Get a Zend\Db\Sql\Sql object

@return \Zend\Db\Sql\Sql
320580
protected function sql()
    {
        if ( null === $this->sql )
        {
            $this->sql = new Sql(
                $this->getDbAdapter(),
                $this->getTableInSchema( 'settings' )
            );
        }

        return $this->sql;
    }
33567
public function get()
    {
        $eventResult = $this->fireEvents('before-select');
        if (!is_null($eventResult)) {
            return $eventResult;
        };

        $executionTime = 0;
        if (is_null($this->pdoStatement)) {
            $queryObject = $this->getQuery('select');
            list($this->pdoStatement, $executionTime) = $this->statement(
                $queryObject->getSql(),
                $queryObject->getBindings()
            );
        }

        $start = microtime(true);
        $result = call_user_func_array(array($this->pdoStatement, 'fetchAll'), $this->fetchParameters);
        $executionTime += microtime(true) - $start;
        $this->pdoStatement = null;
        $this->fireEvents('after-select', $result, $executionTime);
        return $result;
    }
1097567
public function getQuery() {
        $query = 'SELECT '.implode(', ', $this->fields)
                .' FROM '.implode(', ', $this->from);
        if (count($this->conditions) > 0) {
            $query = $query.' WHERE '.implode(' AND ', $this->conditions);
        }
        $query = rtrim($query).';';

        return $query;
    }
768795
public function getDatabase()
    {
        if(!isset($this->_database))
        {
            $query = $this->getObject('lib:database.query.select')
                ->columns('DATABASE()');

            $this->_database = $this->select($query, KDatabase::FETCH_FIELD);
        }
        return $this->_database;
    }
1180283
protected function build()
    {
        $sql = $this->start . "\n"
            . ($this->from    ? $this->from . "\n"    : null)
            . ($this->join    ? $this->join           : null)
            . ($this->set     ? $this->set . "\n"     : null)
            . ($this->where   ? $this->where . "\n"   : null)
            . ($this->groupby ? $this->groupby . "\n" : null)
            . ($this->orderby ? $this->orderby . "\n" : null)
            . ($this->limit   ? $this->limit . "\n"   : null)
            . ($this->offset  ? $this->offset . "\n"  : null)
            . ";";

        return $sql;
    }
697313
public function getQuery()
    {
        $sql = $this->setQuery;
        $sql .= $this->getWhere();
        $sql .= $this->getGroupBy();
        $sql .= $this->getOrderBy();
        $sql .= $this->getHaving();
        $sql .= $this->getLimit();

        $this->setQuery = null;
        $this->setWhere = null;
        $this->setHaving = null;
        $this->setOrderBy = null;
        $this->setGroupBy = null;
        $this->setLimit = null;

        return str_replace('  ', ' ', $sql);
    }
676435
public function toSql()
    {
        if ($this->isEmpty()) {
            return '';
        }

        $params = $this->getParams();

        $sql = array('SET');
        $set = array();

        foreach ($params as $column => $value) {
            $set[] = implode(' = ', array(
                $column, $this->getBuilder()->getHelper()->toDbValue($value)
            ));
        }

        $sql[] = implode(', ', $set);

        return implode(' ', $sql);
    }
1262840
public function getQuery()
    {
        $query = null;

        switch ($this->type) {
            case self::SELECT:
                $query = $this->getSelectQuery();
                break;
            case self::INSERT:
                $query = $this->getInsertQuery();
                break;
            case self::UPDATE:
                $query = $this->getUpdateQuery();
                break;
            case self::DELETE:
                $query = $this->getDeleteQuery();
                break;
        }

        return $query;
    }
1271206
private function getSQL() {
        try {
            $this->checkDialect();
        } catch (DialectException $e) {
            return null;
        }
        if (!$this->values) {
            $this->values = new BindValues ();
        } else if (!$this->valueFixed) {
            $this->values->reset();
        }
        $fields = $this->prepareFields($this->fields, $this->values);
        $from   = $this->prepareFrom($this->sanitize($this->from));
        $joins  = $this->prepareJoins($this->sanitize($this->joins));
        $having = $this->sanitize($this->having);
        $group  = $this->sanitize($this->group);
        $order  = $this->sanitize($this->order);

        return $this->dialect->getSelectSQL($fields, $from, $joins, $this->where, $having, $group, $order, $this->limit, $this->values, $this->forupdate);
    }
85985
function query() {
        if(empty($this->sql)) {
            $this->_constructSql();
        }
        list($sql, $param) = $this->_constructSql();
        $this->_reset();
        return $this->execute($sql, $param);
    }
1176928
public function query($sql, $bind = array())
    {
        // connect to the database if needed
        $this->_connect();

        // is the $sql a Zend_Db_Select object?
        if ($sql instanceof Zend_Db_Select) {
            if (empty($bind)) {
                $bind = $sql->getBind();
            }

            $sql = $sql->assemble();
        }

        // make sure $bind to an array;
        // don't use (array) typecasting because
        // because $bind may be a Zend_Db_Expr object
        if (!is_array($bind)) {
            $bind = array($bind);
        }

        // prepare and execute the statement with profiling
        $stmt = $this->prepare($sql);
        $stmt->execute($bind);

        // return the results embedded in the prepared statement object
        $stmt->setFetchMode($this->_fetchMode);
        return $stmt;
    }
1109675
public function getPdo()
    {
        if ($this->pdo === null) {
            $this->pdo = $this->doConnect();
        }
        return $this->pdo;
    }
166368
public function getSql() {
        $sql = "CREATE TABLE IF NOT EXISTS {$this->getTable()} (";
        $column = $this->_data;
        if (!empty($this->primaryKey)) {
            $column[] = "PRIMARY KEY (`{$this->primaryKey}`)";
        }
        foreach ($this->checks as $key => $item) {
            $column[] = (!is_integer($key) ? "CONSTRAINT `{$key}` " : null)." CHECK ({$item})";
        }
        foreach ($this->index as $key => $item) {
            $column[] = (count($item) > 2 ? 'UNIQUE ': null). "INDEX `{$key}` (`{$item[0]}` {$item['1']})";
        }
        foreach ($this->foreignKey as $key => $item) {
            $column[] = "CONSTRAINT `{$key}` FOREIGN KEY (`{$item[0]}`) REFERENCES `{$item[1]}` (`{$item[2]}`) ON DELETE {$item[2]} ON UPDATE {$item[3]}";
        }
        $sql .= implode(',', $column).") ENGINE={$this->engine}";
        if ($this->aiBegin > 1) {
            $sql .= ' AUTO_INCREMENT='.$this->aiBegin;
        }
        return $sql." DEFAULT CHARSET={$this->charset} COMMENT='{$this->comment}';";
    }
1122376
public function get_query()
	{
		// Get the columns
		$columns = $this->select(false);

		// Start building the query
		$select = $columns;
		if ($this->use_subquery())
		{
			$select = array();
			foreach ($columns as $c)
			{
				$select[] = $c[0];
			}
		}
		$query = call_fuel_func_array('DB::select', $select);

		// Set the defined connection on the query
		$query->set_connection($this->connection);

		// Set from table
		$query->from(array($this->_table(), $this->alias));

		// Build the query further
		$tmp = $this->build_query($query, $columns);

		return $tmp['query'];
	}
265357
public function getSQLForInsert()
    {
        $columns = array_map(function ($column) {
            return $this->getQuotedName($column);
        }, array_keys(current($this->sqlParts['values'])));

        $values = [];
        foreach ($this->sqlParts['values'] as $part) {
            $record = array_map(function ($value) {
                if ($value instanceof ToSqlInterface) {
                    return $value->toSQL();
                }

                return $this->getAdapter()->getSqlType($value);
            }, $part);

            $values[] = '('.implode(', ', $record).')';
        }

        $table = $this->getQuotedName($this->sqlParts['from']['table']);

        return sprintf(
            'INSERT INTO %s (%s) VALUES %s',
            $table,
            implode(', ', $columns),
            implode(', ', $values)
        );
    }
109623
public function get()
    {
        $sql = "SELECT * FROM `$this->_table` ";

        $this->_param_list = array();

        if (!empty($this->_where_list)) {
            $sql .= "WHERE ";
            $first = true;
            foreach ($this->_where_list as $field_name => $field_settings) {
                $type          = isset($field_settings['type']) ? $field_settings['type'] : false;
                $field_value   = $field_settings['value'];
                $field_connect = isset($field_settings['op']) ? $field_settings['op'] : ' AND ';

                switch ($type) {
                    case 'like':
                        $sql .= ($first !== true ? "$field_connect" : "") . "$field_name like '%:$field_name%'";
                        $this->_param_list[] = array(":$field_name", $field_value);
                        break;
                    case 'in':
                        $sql .= ($first !== true ? "$field_connect" : "") . "$field_name IN (:$field_name)";
                        $this->_param_list[] = array(":$field_name", $field_value);
                        break;
                    default:
                        $sql .= ($first !== true ? "$field_connect" : "") . "$field_name = :$field_name";
                        $this->_param_list[] = array(":$field_name", $field_value);
                        break;
                }

                // we can assume that after the first iteration it's false
                $first = false;
            }
        }
        unset($field_connect, $field_name, $field_value, $type, $field_settings);

        if (!empty($this->_group)) {
            if (is_array($this->_group)) {
                $this->_limit = implode(',', $this->_group_by);
            }

            $sql .= ' GROUP BY ' . $this->_group_by;
        }

        if (!empty($this->_limit)) {
            if (is_array($this->_limit)) {
                $this->_limit = implode(',', $this->_limit);
            }

            $sql .= ' LIMIT ' . $this->_limit;
        }

        $this->last_sql = $sql;

        $this->__init_database();

        $stmt = $this->db->prepare($sql);
        // set the prepared statement
        for ($i = 0, $c = count($this->_param_list); $i < $c; $i++) {
            $stmt->bindParam($this->_param_list[$i][0], $this->_param_list[$i][1]);
        }


        if (!$stmt->execute()) return;

        $this->result = $stmt->fetchAll(MySQL::FETCH_OBJ);
    }
358918
public function getSql()
    {
        if ($this->builtSql === null) {
            $this->builtSql = $this->buildSql();
        }

        return $this->builtSql;
    }