Compile the SQL partial for a JOIN statement and return it.

@param   mixed  $db  Database_Connection instance or instance name

@return  string
504911
public function compile($db = null)
	{
		if ( ! $db instanceof \Database_Connection)
		{
			// Get the database instance
			$db = \Database_Connection::instance($db);
		}

		if ($this->_type)
		{
			$sql = strtoupper($this->_type).' JOIN';
		}
		else
		{
			$sql = 'JOIN';
		}

		// Quote the table name that is being joined
		$sql .= ' '.$db->quote_table($this->_table);

		$conditions = array();

		foreach ($this->_on as $condition)
		{
			// Split the condition
			list($c1, $op, $c2, $chaining) = $condition;

			// Add chain type
			$conditions[] = ' '.$chaining.' ';

			if ($op)
			{
				// Make the operator uppercase and spaced
				$op = ' '.strtoupper($op);
			}

			// Quote each of the identifiers used for the condition
			$conditions[] = $db->quote_identifier($c1).$op.' '.(is_null($c2)?'NULL':$db->quote_identifier($c2));
		}

		// remove the first chain type
		array_shift($conditions);

		// if there are conditions, concat the conditions "... AND ..." and glue them on...
		empty($conditions) or $sql .= ' ON ('.implode('', $conditions).')';

		return $sql;
	}
726379
private function compileJoinPrefix($joinType)
    {
        if (array_key_exists($joinType, $this->joinPrefixes)) {
            return $this->joinPrefixes[$joinType];
        }

        return null;
    }
870709
protected function compileJoins(Builder $query, $joins)
    {
        $sql = array();

        $query->setBindings(array(), 'join');

        foreach ($joins as $join) {
            $table = $this->wrapTable($join->table);

            $clauses = array();

            foreach ($join->clauses as $clause) {
                $clauses[] = $this->compileJoinConstraint($clause);
            }

            foreach ($join->bindings as $binding) {
                $query->addBinding($binding, 'join');
            }

            $clauses[0] = $this->removeLeadingBoolean($clauses[0]);

            $clauses = implode(' ', $clauses);

            $type = $join->type;

            //
            $sql[] = "$type join $table on $clauses";
        }

        return implode(' ', $sql);
    }
604116
private function convertDbToApi($db)
    {
        $result = new AResponse();
        if ($db) {
            /* extract DB data */
            $custId = $db[QBGetCustomer::A_ID];
            $email = $db[QBGetCustomer::A_EMAIL];
            $nameFirst = $db[QBGetCustomer::A_NAME_FIRST];
            $nameLast = $db[QBGetCustomer::A_NAME_LAST];
            $mlmId = $db[QBGetCustomer::A_MLM_ID];
            $path = $db[QBGetCustomer::A_PATH];
            $country = $db[QBGetCustomer::A_COUNTRY];

            /* prepare response data */
            $pathFull = $path . $custId . Cfg::DTPS;

            /* compose response data */
            $result->setId($custId);
            $result->setEmail($email);
            $result->setNameFirst($nameFirst);
            $result->setNameLast($nameLast);
            $result->setMlmId($mlmId);
            $result->setCountry($country);
            $result->setPathFull($pathFull);
        }
        return $result;
    }
1077876
public static function getSqlFormat(AbstractDatabaseDriver $db = null)
    {
        $db = $db ?: Ioc::getDatabase();

        return $db->getQuery(true)->getDateFormat();
    }
680057
public static function getDbo()
	{
		if (!self::$database)
		{
			//get config values

			$host = Config::get()->get('database.host');
			$user = Config::get()->get('database.user');
			$password = Config::get()->get('database.password');
			$database = Config::get()->get('database.name');
			$prefix = Config::get()->get('database.prefix');
			$driver = Config::get()->get('database.driver');
			$debug = Config::get()->get('database.debug');

			//added extra code to prevent error when $driver is incorrect

			$options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);

			self::$database = DatabaseFactory::getInstance()->getDriver($driver, $options);

			//get the debug configuration setting
			self::$database->setDebug(Config::get()->get('debug'));
		}
		return self::$database;
	}
526694
protected function _compile_join()
    {
        $sSql = '';
        // Write the "JOIN" portion of the query
        if (count($this->qb_join) > 0) {
            $sSql .= "\n" . implode("\n", $this->qb_join);
        }
        return $sSql;
    }
1263100
public function _getSql()
    {
        $sql = '';
        $params = [];
        try {
            list($sql, $params) = $this->getSqlCompiler(BaseOrm::getDbConnection())->asSql();
        } catch (OrmException $e) {
        }

        $sql = str_replace('?', '%s', $sql);

        return vsprintf($sql, $params);
    }
598603
public function getSql()
    {
        if ($this->isEmpty()) {
            throw new Exception("Invalid segment, please specify a valid segment.");
        }
        $sql = '';
        $subExpression = false;
        foreach ($this->tree as $expression) {
            $operator = $expression[self::INDEX_BOOL_OPERATOR];
            $operand = $expression[self::INDEX_OPERAND];

            if ($operator == self::BOOL_OPERATOR_OR
                && !$subExpression
            ) {
                $sql .= ' (';
                $subExpression = true;
            } else {
                $sql .= ' ';
            }

            $sql .= $operand;

            if ($operator == self::BOOL_OPERATOR_AND
                && $subExpression
            ) {
                $sql .= ')';
                $subExpression = false;
            }

            $sql .= " $operator";
        }
        if ($subExpression) {
            $sql .= ')';
        }
        return array(
            'where' => $sql,
            'bind'  => $this->valuesBind,
            'join'  => implode(' ', $this->joins)
        );
    }
1258104
public function getDbInfo($db)
    {
        $info = ArrayHelper::getValue($this->dbInfo, $db, null);
        if (!$info) {
            throw new UserException('Database with name ' . $db . ' not configured for dump.');
        }

        return $info;
    }
258151
public function getDbFieldType() : string
    {
        $dbFieldType = $this->config->getProvider('dbFieldType');
        $dbFieldType = new $dbFieldType($this->config);
        $dbFieldType = $dbFieldType->provide();

        return $dbFieldType;
    }
1213468
static function cleanup( $db )
    {
        if ( $db === null )
            $db = eZDB::instance();
        $relationTypes = $db->supportedRelationTypes();
        $result = true;
        $defaultRegexp = "#^ez|tmp_notification_rule_s#";
        foreach ( $relationTypes as $relationType )
        {
            $relationItems = $db->relationList( $relationType );
            // This is the default regexp, unless the db driver provides one
            $matchRegexp = null;
            if ( method_exists( $db, 'relationMatchRegexp' ) )
            {
                $matchRegexp = $db->relationMatchRegexp( $relationType );
            }
            if ( $matchRegexp === null )
                $matchRegexp = $defaultRegexp;
            foreach ( $relationItems as $relationItem )
            {
                // skip relations that shouldn't be touched
                if ( $matchRegexp !== false and
                     !preg_match( $matchRegexp, $relationItem ) )
                    continue;

                if ( !$db->removeRelation( $relationItem, $relationType ) )
                {
                    $result = false;
                    break;
                }
            }
            if ( !$result )
                break;
        }
        return $result;
    }
584428
protected function db($db = '')
    {
        $db = $db ? $db : $this->use_db;

        return Connection::getInstance($db);
    }
487226
private function getDbName() {
        if (!isset($this->dbname)) {
            $this->dbname = $this->getPDO()->query('select database()')->fetchColumn();
        }
        return $this->dbname;
    }
111542
public static function db()
    {
        if (self::$db === null) {
            $rc = rcube::get_instance();
            $db = rcube_db::factory($rc->config->get('db_dsnw'));

            $db->set_debug((bool)$rc->config->get('sql_debug'));

            // Connect to database
            $db->db_connect('w');

            if (!$db->is_connected()) {
                rcube::raise_error("Error connecting to database: " . $db->is_error(), false, true);
            }

            self::$db = $db;
        }

        return self::$db;
    }
1065533
protected function generateJoinSQL()
        {
            $sql = ' FROM ' . $this->getTable()->getSelectFromSql();
            foreach ($this->query->getJoins() as $join) {
                $sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
                $sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());

                if ($join->hasAdditionalCriteria()) {
                    $sql_parts = [];

                    foreach ($join->getAdditionalCriteria() as $criteria) {
                        $criteria->setQuery($this->query);
                        $sql_parts[] = $criteria->getSql();
                        foreach ($criteria->getValues() as $value) {
                            $this->query->addValue($value);
                        }
                    }

                    $sql .= ' AND ' . join(' AND ', $sql_parts);
                }

                $sql .= ')';
            }

            return $sql;
        }
1303193
public function getTables ($db)
	{
		
		// Get tables
		
		if (!isset ($this->tables[$db]))
		{
			
			$query	= $this->db->query ('SHOW TABLES FROM ' . $db);
			$query->setFetchMode (\PDO::FETCH_COLUMN, 0);
			
			$this->tables[$db]	= $query->fetchAll ();
			
		}
		
		// Return tables
		
		return $this->tables[$db];
		
	}