Returns the sql generator used for db manipulation.
Used mostly in upgrade.php scripts.
@return database_manager The instance used to perform ddl operations.
@see lib/ddl/database_manager.php
322101
public function get_manager() {
        global $CFG;

        if (!$this->database_manager) {
            require_once($CFG->libdir.'/ddllib.php');

            $classname = $this->get_dbfamily().'_sql_generator';
            require_once("$CFG->libdir/ddl/$classname.php");
            $generator = new $classname($this, $this->temptables);

            $this->database_manager = new database_manager($this, $generator);
        }
        return $this->database_manager;
    }
1018921
public function getSql()
    {
        $table = $this->table;

        if ($this->hasTable($table)) {
            $this->isChange = true;
        }

        $columnSql = $this->getCreateDefinition();

        if ($this->isChange) {
            $sql = "ALTER TABLE $table" . $columnSql;
        } else {
            $sql = "CREATE TABLE $table ($columnSql)";
            $sql .= $this->getTableOptionSql();
        }

        return $sql;
    }
769879
public static function getEntityManager() {
		if (self::$_entityManager == null) {
			self::$_entityManager = self::_getInstance ();
		}
		return self::$_entityManager;
	}
1105630
protected function db()
    {
        if (!isset($this->database)) {
            throw new RuntimeException(sprintf(
                'Database Connection is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->database;
    }
643833
public function SQL() {
      if(is_null($this->_SQL)) {
         $Name = $this->Engine . 'Driver';
         $this->_SQL = Gdn::Factory($Name);
         $this->_SQL->Database = $this;
      }
      
      return $this->_SQL;
   }
355093
public function getSql()
    {
        $sqlTemplate = "SELECT %s FROM %s %s";
        $fieldsCompiled = implode(',', $this->getFields());
        return trim(sprintf(
            $sqlTemplate,
            $fieldsCompiled,
            $this->getTable(),
            $this->getWhereStatement()
        ));
    }
826190
protected function get_iterator() {
        global $DB;

        // Build the SQL dynamically here
        $fieldslist = 't.' . implode(', t.', $this->fields);
        $sql = "SELECT t.id, $fieldslist
                  FROM {" . $this->tablename . "} t
                  JOIN {backup_ids_temp} b ON b.newitemid = t.id
                 WHERE b.backupid = ?
                   AND b.itemname = ?
                   AND t.blockname = 'html'";
        $params = array($this->restoreid, $this->mapping);
        return ($DB->get_recordset_sql($sql, $params));
    }
239675
private function getSqlInterfaceFunction()
    {

        if( count($this->keyProperties) !== 1 ) {

            $content = "    throw new \LogicException('Normality can\\'t (yet) handle tables without a primary key or multi-column primary keys.\\n".
                "Please extend the generator or overload {$this->pgClass->getEntityName()}->parse().');";

        } else {

            $primaryKey = $this->keyProperties[0];
            $dataType = $this->dataTypes[$primaryKey];

            // if datatype inheritied we don't need to do anything
            if( $dataType->isInherited() ) {
                return array();
            }

            // we're doing something
            $content = '';

            $this->class->addImplements( "SqlInterface");
            $this->class->addUses( 'Bond\Sql\QuoteInterface' );
            $this->class->addUses( 'Bond\Sql\SqlInterface' );

            if( $dataType->getType() === 'int' ) {

                // can this property be a entity?
                if( $dataType->isEntity() ) {
                    $content .= <<<PHP
    if( is_object( \$this->data['{$primaryKey}'] ) and \$this->data['{$primaryKey}'] instanceof SqlInterface ) {
        return \$this->data['{$primaryKey}']->parse( \$quoting );
    }\n
PHP
;
                }

                // cast integer datatype to int if not null
                $content .= <<<PHP
    return \$this->data['{$primaryKey}'] !== null ? (string) (int) \$this->data['{$primaryKey}'] : 'NULL';
PHP
;

            } else {

                $content .= <<<PHP
    return \$quoting->quote( \$this->data['{$primaryKey}'] );
PHP
;

            }

        }

        $fn = new Sformatf( <<<'PHP'
/**
 * Impementation of interface \Bond\Pg\Query->Validate()
 * @return scalar
 */
public function parse( QuoteInterface $quoting )
{
%s
}

PHP
            , $content
        );

        $this->class->classComponents[] = new FunctionDeclaration( "parse", $fn );

    }
1289916
public function getSchemaManager()
    {
        if ($this->_schemaManager === null) {
            $this->_schemaManager = $this->_driver->getSchemaManager($this);
        }

        return $this->_schemaManager;
    }
949691
protected function generateSelectSQL()
        {
            $sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';

            if ($this->query->isCustomSelection()) {
                if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
                    foreach ($this->query->getSortOrders() as $sort_order) {
                        $this->query->addSelectionColumn($sort_order->getColumn());
                    }
                }

                $sql_parts = [];
                foreach ($this->query->getSelectionColumns() as $column => $selection) {
                    $alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
                    $sub_sql = $selection->getVariableString();
                    if ($selection->isSpecial()) {
                        $sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
                        if ($selection->hasAdditional())
                            $sub_sql .= ' ' . $selection->getAdditional() . ' ';
                        if (mb_strpos($selection->getSpecial(), '(') !== false)
                            $sub_sql .= ')';
                    } else {
                        $sub_sql .= Query::quoteIdentifier($selection->getColumn());
                    }
                    $sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
                    $sql_parts[] = $sub_sql;
                }
                $sql .= implode(', ', $sql_parts);
            } else {
                $this->addAllSelectColumns();
                $sql .= $this->generateSelectAllSQL();
            }

            return $sql;
        }
1046434
protected function generateSQL()
    {
        if ( !in_array( $this->type, array( 'name', 'alias', 'all' ) ) )
        {
            eZDebug::writeError( "Parameter \$type must be one of name, alias or all. The value which was used was '{$this->type}'." );
            return null;
        }

        $db = eZDB::instance();
        if ( $this->languages === true )
        {
            $langMask = trim( eZContentLanguage::languagesSQLFilter( 'ezurlalias_ml', 'lang_mask' ) );
            $conds[] = "($langMask)";
        }

        if ( $this->paren !== null )
        {
            $conds[] = "parent = {$this->paren}";
        }

        if ( $this->text !== null )
        {
            $conds[] = "text_md5 = " . $db->md5( "'" . $db->escapeString( $this->text ) . "'" );
        }

        if ( $this->actions !== null )
        {
            // Check for conditions which will return no rows.
            if ( count( $this->actions ) == 0 )
                return false;

            if ( count( $this->actions ) == 1 )
            {
                $action = $this->actions[0];
                $actionStr = $db->escapeString( $action );
                $conds[] = "action = '$actionStr'";
            }
            else
            {
                $actions = array();
                foreach ( $this->actions as $action )
                {
                    $actions[] = "'" . $db->escapeString( $action ) . "'";
                }
                $conds[] = "action IN (" . join( ", ", $actions ) . ")";
            }
        }
        $actionTypes = null;
        if ( $this->actionTypes !== null )
        {
            $actionTypes = $this->actionTypes;
        }
        if ( $this->actionTypesEx !== null )
        {
            if ( $actionTypes == null )
            {
                $rows = $db->arrayQuery( "SELECT DISTINCT action_type FROM ezurlalias_ml" );
                $actionTypes = array();
                foreach ( $rows as $row )
                {
                    $actionTypes[] = $row['action_type'];
                }
            }
            $actionTypes = array_values( array_diff( $actionTypes, $this->actionTypesEx ) );
        }
        if ( $actionTypes !== null )
        {
            // Check for conditions which will return no rows.
            if ( count( $actionTypes ) == 0 )
                return false;

            if ( count( $actionTypes ) == 1 )
            {
                $action = $actionTypes[0];
                $actionStr = $db->escapeString( $action );
                $conds[] = "action_type = '$actionStr'";
            }
            else
            {
                $actions = array();
                foreach ( $actionTypes as $action )
                {
                    $actions[] = "'" . $db->escapeString( $action ) . "'";
                }
                $conds[] = "action_type IN (" . join( ", ", $actions ) . ")";
            }
        }

        $conds[] = 'is_original = 1';
        if ( $this->type == 'name' )
        {
            $conds[] = 'is_alias = 0';
        }
        else if ( $this->type == 'alias' )
        {
            $conds[] = 'is_alias = 1';
        }
        else // 'all'
        {
        }

        return "FROM ezurlalias_ml WHERE " . join( " AND ", $conds );
    }
716640
public function generateSelectSQL($all = false)
        {
            if ($this->sql === null) {
                $this->detectDistinct();
                $this->action = QueryInterface::ACTION_SELECT;
                $sql_generator = new SqlGenerator($this);

                $this->sql = $sql_generator->getSelectSQL($all);
            }

            return $this->sql;
        }
83107
protected function createDatabaseDriver()
    {
        $connection = $this->getDatabaseConnection();
        $connection->getReadPdo();
        $table = $this->app['config']['session.table'];
        return $this->buildSession(new DatabaseSessionHandler($connection, $table, $this->app));

    }
556292
public static function getHandle()
    {
        if (!isset(self::$_dbhnd)) {
            self::$_dbhnd = new \PDO(
                BLConfig::get('db', 'dsn'),
                BLConfig::get('db', 'user'),
                BLConfig::get('db', 'pass')
            );
            self::$_dbhnd->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        }
        return self::$_dbhnd;
    }
411927
protected function createDatabaseDriver()
	{
		$connection = $this->getDatabaseConnection();

		$table = $connection->getTablePrefix().$this->app['config']['session.table'];

		return $this->buildSession(new PdoSessionHandler($connection->getPdo(), $this->getDatabaseOptions($table)));
	}
1206024
public function getCurrentDatabase()
    {
        if ($this->currentDatabase === null) {
            $compiler = $this->connection->schemaCompiler();
            $result = $compiler->currentDatabase($this->connection->getDSN());

            if (is_array($result)) {
                $this->currentDatabase = $this->connection->column($result['sql'], $result['params']);
            } else {
                $this->currentDatabase = $result;
            }
        }

        return $this->currentDatabase;
    }
74870
public static function db()
    {
        self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return self::$conn;
    }