@param \Concrete\Core\Database\Connection\Connection $db

@return string|null
964097
protected function getDatabaseVersion(Connection $db)
    {
        $driver = $db->getDriver();
        if (!$driver instanceof VersionAwarePlatformDriver) {
            return null;
        }
        $params = $db->getParams();
        if (isset($params['serverVersion'])) {
            $rawVersion = (string) $params['serverVersion'];
        } else {
            $connection = $db->getWrappedConnection();
            if (!$connection instanceof ServerInfoAwareConnection) {
                return null;
            }
            $rawVersion = (string) $connection->getServerVersion();
        }
        if (!preg_match('/^\d+\.\d+(?:\.\d+)?/', $rawVersion, $matches)) {
            return null;
        }

        return $matches[0];
    }
28896
static function getParameters($connection_name) {
		if (!array_key_exists($connection_name, self::$parameters)) {
			throw new RuntimeException("Configuration for database '$connection_name' not loaded");
		}

		return self::$parameters[$connection_name];
	}
1287645
public function listCollections($db = null)
    {
        $collections = [];
        $result = $this->command(['listCollections' => 1], $db);
        foreach ($result as $collection) {
            $collections[] = $collection['name'];
        }

        return $collections;
    }
155352
public function query($sql, $values = null, $connection = null)
  {
    if ($this->isDebug()) {
      $i = $this->getQueriesCount();
      $t = microtime(true);

      $this->queries[$i] = array('query' => $sql, 'values' => $values);
    }

    $pdo = $this->getConnection($connection);

    if ($sql instanceof Query) {
      $values = $values ?: $sql->getBindedValues();
      $sql    = $sql->asStatement();
    }

    $stmt = $pdo->prepare($sql);
    $res = $stmt->execute($values);

    if ($this->isDebug()) {
      $this->queries[$i]['time'] = microtime(true) - $t;
    }

    if (!$res) {
      Exception::ThrowError(Exception::QUERY, $stmt->errorInfo());
    }

    return $stmt;
  }
437673
public function getBucket($db = null)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;

        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->select === null) {
            $bucketName = $db->quoteBucketName($modelClass::bucketName());

            $primaryModel = $this->primaryModel ?: ActiveRecord::className();

            $primaryKey = $primaryModel::primaryKey()[0];
            $primaryKey = $db->quoteColumnName($primaryKey);

            $this->select = "meta($bucketName).id AS $primaryKey, $bucketName.*";
        }

        if ($this->from === null) {
            $this->from = $modelClass::bucketName();
        }

        return $db->getBucket($this->from);
    }
669308
public static function getQueryBuilder(Connection $connection)
    {
        switch ($connection->getDriver()->getName()) {
            case 'pdo_mysql':
                $adapter = new Database\Mysql\Adapter($connection);
                break;

            case 'pdo_sqlite':
                $adapter = new Database\Sqlite\Adapter($connection);
                break;

            case 'pdo_pgsql':
                $adapter = new Database\Pgsql\Adapter($connection);
                break;

            default:
                throw new NotSupportedException('Unknown driver');
        }

        $lookupBuilder = new LookupBuilder();
        $lookupBuilder->addLookupCollection($adapter->getLookupCollection());

        return new QueryBuilder($connection, $adapter, $lookupBuilder);
    }
1275165
public function getDatabaseDetail(MySQL $db = null)
    {

        if (empty($db) || empty($db->db)) {
            $db = $this;
        }

        return new MysqlDetail($db);
    }
380933
public function connectionType($which_connection='')
    {
        if ($which_connection == '') {
            $which_connection=$this->default_db;
        }
        if ($this->isConnected($which_connection)) {
            $reflect = new \ReflectionClass($this->connections[$which_connection]);
            if (substr($reflect->name, 0, 6) == 'ADODB_') {
                return substr($reflect->name, 6);
            }
        }

        return 'unknown';
    }
1018740
public static function getNullDate(AbstractDatabaseDriver $db = null)
    {
        $db = $db ?: Ioc::getDatabase();

        return $db->getQuery(true)->getNullDate();
    }
100962
public function createCommand($db = null)
    {
        if ($this->primaryModel !== null) {
            // lazy loading a relational query
            if ($this->via instanceof self) {
                // via pivot index
                $viaModels = $this->via->findJunctionRows([$this->primaryModel]);
                $this->filterByModels($viaModels);
            } elseif (is_array($this->via)) {
                // via relation
                /* @var $viaQuery ActiveQuery */
                list($viaName, $viaQuery) = $this->via;
                if ($viaQuery->multiple) {
                    $viaModels = $viaQuery->all();
                    $this->primaryModel->populateRelation($viaName, $viaModels);
                } else {
                    $model = $viaQuery->one();
                    $this->primaryModel->populateRelation($viaName, $model);
                    $viaModels = $model === null ? [] : [$model];
                }
                $this->filterByModels($viaModels);
            } else {
                $this->filterByModels([$this->primaryModel]);
            }
        }

        $this->setConnection($db);
        $db = $this->getConnection();

        if ($this->sql === null) {
            list ($sql, $params) = $db->getQueryBuilder()->build($this);
        } else {
            $sql = $this->sql;
            $params = $this->params;
        }

        return $db->createCommand($sql, $params);
    }
81716
protected function getPrefix(Connection $connection)
    {
        $params = $connection->getParams();

        return isset($params['prefix']) ? $params['prefix'] : null;
    }
324834
protected function getDriverName($connection)
    {
        try {
            return DB::connection($connection)->getDriverName();
        } catch (Exception $e) {
            $this->eye->logger()->debug('Unable to find DB driver', $connection);
        }

        return 'unknown';
    }
1047025
protected function getSQLResultFromConnection($connection, $sql, array $params = array())
    {
        $result = $connection->fetchAll($sql, $params);
        return $result;
    }
176641
public function getDatabaseMetadata(
        Connection $connection,
        string $databaseName
    ): DatabaseMetadata {
        // Get a list of table names
        $tableNameStatement = $connection
            ->createQueryBuilder()
            ->select([
                'tables.TABLE_NAME AS name'
            ])
            ->from('information_schema.TABLES', 'tables')
            ->where('TABLE_SCHEMA = :schema')
            ->andWhere('TABLE_TYPE = "BASE TABLE"')
            ->setParameter('schema', $databaseName)
            ->execute();

        // Build table metadata
        $tableMetadataList = [];
        while ($tableName = $tableNameStatement->fetchColumn(0)) {
            $tableMetadataList[] = $this->getTableMetadata($connection, $databaseName, $tableName);
        }

        return new DatabaseMetadata($databaseName, $tableMetadataList);
    }
694395
protected function getConnection($context)
    {
        $connectionName = null;

        if (!empty($context['options']['db_connection_name'])) {
            $connectionName = $context['options']['db_connection_name'];
        }

        return $this->doctrine->getConnection($connectionName);
    }
970764
public function listCollections($db = '')
    {
        $cursor = $this->cmd('listCollections', null, $db);
        $result = [];
        foreach ($cursor as $collection) {
            $result[] = $collection['name'];
        }
        return $result;
    }
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;
    }