@param array|string $from
@param array        $joins
@param Condition    $where
@param BindValues   $values
@param array        $order
@param array        $limit

@return string
180269
public function getDeleteSQL($from, $joins, $where, $values, $order, $limit) {
        $len = count($joins);
        if ($len == 0) {
            $sql [] = 'DELETE FROM ' . $from [0][0];
        } else {
            $sql [] = 'DELETE ' . $from[0][1] . ' FROM ' . implode(' AS ', $from [0]);
            foreach ($joins as $join) {
                $sql [] = $join [2] . ' ' . $join [0] . ' AS ' . $join [3] . ' ON (' . $join [1] . ')';
            }
        }

        if ($where && count($where) > 0) {
            $sql [] = 'WHERE';
            $sql [] = $where->getWhereCondition($this, $values);
        }
        if ($len == 0) {
            if ($order) {
                $_orders = [];
                foreach ($order as $o) {
                    $_orders [] = Condition::cleanField($o [0]) . ' ' . ($o [1] == 'a' ? 'ASC' : 'DESC');
                }
                $sql [] = 'ORDER BY ' . implode(' , ', $_orders);
            }
            if ($limit) {
                $limit2 = $values->addValue('limit', $limit [1]);
                $sql [] = 'LIMIT ' . $limit2;
            }
        }

        return implode(' ', $sql);
    }
1066740
protected function handleJoins(array $joins)
    {
        if (empty($joins)) {
            return '';
        }
        $sql = [];
        foreach ($joins as $join) {
            /** @var Join $joinObject */
            $joinObject = $join['join'];

            $on = '';
            if ($joinObject) {
                $on = $this->handleJoinConditions($joinObject->getJoinConditions());
            }
            if ($on !== '') {
                $on = ' ON ' . $on;
            }

            $sql[] = $join['type'] . ' JOIN ' . $this->handleTables($join['table']) . $on;
        }
        return ' ' . implode(' ', $sql);
    }
778319
public function delete(string $from, $wheres, array $options = [])
    {
        if (!$wheres) {
            throw new \RuntimeException('Safety considerations, where conditions can not be empty');
        }

        list($where, $bindings) = $this->handleWheres($wheres);

        $options['from'] = $this->qn($from);
        $options['where'] = $where;

        $statement = $this->compileDelete($options);

        if (isset($options['dumpSql'])) {
            return [$statement, $bindings];
        }

        return $this->fetchAffected($statement, $bindings);
    }
1110389
private function prepareJoin(array $join)
    {
        if ($join['table'] instanceof SelectQuery) {
            [$sql, $params] = $join['table']->toSql();

            $join['table'] = '(' . $sql . ')';

            $join['params'] = $params;
        }

        if ($join['on'] instanceof Conditions) {
            [$sql, $params] = $join['on']->toSql();

            $join['on'] = $sql;

            $join['params'] = array_merge($join['params'], $params);
        }

        return $join;
    }
168584
public function cuSelectAsArray($tableName, $where = '', $order = '', $limit = '')
    {

        $data_array = [];
        $where      = trim($where);
        $order      = trim($order);
        $limit      = trim($limit);
        if ($where === false) {
            $where = '';
        }
        if ($where !== '') {
            $where = ' WHERE ' . $where;
        }
        if ($order !== '') {
            $order = ' ORDER BY ' . $order;
        }
        if ($limit !== '') {
            $limit = ' LIMIT ' . $limit;
        }

        /** @noinspection SqlNoDataSourceInspection */
        $q      = 'SELECT * FROM `%s` %s %s %s;';
        $q      = sprintf($q, $tableName, $where, $order, $limit);
        $result = $this->query($q);

        if ($result !== false) {
            while ($data = $result->fetch_assoc()) {
                $data_array[] = $data;
            }
        }

        return $data_array;
    }
103002
private function buildJoins(array $joins)
    {
        foreach ($joins as &$join) {
            // table(s)
            foreach ($join[1] as &$table) {
                $table = $this->escapeIdentifier($table);
            }
            $join[1] = implode(', ', array_filter($join[1]));

            // on clause
            if ($join[2]) {
                $join[2] = 'ON '.$join[2];
            } else {
                unset($join[2]);
            }

            // using clause
            foreach ($join[3] as &$column) {
                $column = $this->escapeIdentifier($column);
            }
            $join[3] = implode(', ', array_filter($join[3]));

            if ($join[3]) {
                $join[3] = 'USING ('.$join[3].')';
            } else {
                unset($join[3]);
            }
            $join = implode(' ', $join);
        }

        return implode(' ', array_filter($joins));
    }
418930
public function findBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $queryCriteria = Criteria::create();

        foreach ($criteria as $prop => $value) {
            $queryCriteria->andWhere(Criteria::expr()->eq($prop, $value));
        }

        $queryCriteria->orderBy($orders);

        if ($limit !== null) {
            $queryCriteria->setMaxResults($limit);
        }

        if ($offset !== null) {
            $queryCriteria->setFirstResult($offset);
        }

        return $this->matching($queryCriteria);
    }
139830
public function update(string $from, $wheres, array $values, array $options = [])
    {
        list($where, $bindings) = DBHelper::handleConditions($wheres, $this);

        $options['update'] = $this->qn($from);
        $options['where'] = $where;

        $statement = $this->compileUpdate($values, $bindings, $options);

        if (isset($options['returnSql'])) {
            return [$statement, $bindings];
        }

        return $this->fetchAffected($statement, $bindings);
    }
408590
public function sql(string $fields = null, string $where = null, string $orderBy = null, string $limit = null): string
    {
        $this->statement->select($fields, $where, $orderBy, $limit);

        // 语句真正被创建
        $this->statement->create();

        // 返回相应的SQL语句
        return $this->statement->getSql();
    }
811603
public static function coming_events_limited($from=false, $limit=30)
    {
        $events = self::coming_events($from)->limit($limit);
        return $events;
    }
1006863
public function get_select_sql( $tables, $where = null, $fields = null, $limit = null, $offset = null, $order_by = null, $group_by = null, $for_update = false ) {
		$as = null;
		if ( is_array( $tables ) ) {
			if ( empty( $tables ) ) {
				return false;
			}
			$table = array_shift( $tables );
			$join  = $tables;
			if ( count( $table ) > 1 ) {
				$as = $table[1];
			}
			$table = $table[0];
		} else {
			$table = $tables;
			$join  = null;
		}
		if ( ! isset( $this->table_defines[ $table ] ) ) {
			return false;
		}

		$columns = $this->table_defines[ $table ]['columns'];

		! is_array( $where ) and $where = [];
		if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
			$where['deleted_at'] = null;
		}

		list( $conditions, $values ) = $this->build_conditions( $where, $columns );
		$table  = $this->get_table( $table );
		$fields = $this->build_fields( $fields, $columns );
		$sql    = "SELECT {$fields} FROM $table";
		if ( isset( $as ) ) {
			$sql .= " AS $as";
		}
		$sql .= $this->build_join( $join );
		if ( ! empty( $conditions ) ) {
			$sql .= " WHERE $conditions";
		}
		$sql .= $this->build_group_by( $group_by, $columns );
		$sql .= $this->build_order_by( $order_by, $columns );
		$sql .= $this->build_limit( $limit, $offset );
		if ( $for_update ) {
			$sql .= ' FOR UPDATE';
		}

		return $this->prepare( $sql, $values );
	}
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);
    }
107649
public function findMany($conditions = '', $params = array(), $orderBy = null, $limit = null, $offset = null){
        $cmd = $this->db->builder()->select()->from($this->table)->where($conditions, $params);
        if($orderBy){
            $cmd->orderBy($orderBy);
        }
        $rows = $cmd->limit($limit, $offset)->queryAll();
        if(false === $rows){
            return false;
        }
        else{
            return $this->mapModels($rows);
        }
    }
685996
public function select(
        $table,
        $conditions = null,
        $fields = null,
        $order = null,
        $limit = null,
        $offset = null
    )
    {
        if (is_null($fields)) {
            $fields = "*";
        }

        $queryString = "SELECT {$fields} FROM {$table} ";

        if (!is_null($conditions)) {
            $queryString .= "WHERE {$conditions} ";
        }

        if (!is_null($order)) {
            $queryString .= "ORDER BY {$order} ";
        }

        if (!is_null($limit)) {
            $queryString .= "LIMIT {$limit} ";
        }

        if (!is_null($offset) && !is_null($limit)) {
            $queryString .= "OFFSET {$offset} ";
        }


        $queryString .= ";";

        $this->query($queryString);

        return $this->countRows();
    }
1099322
public function sqlExists(
		$from,
		$where = null,
		array $params = []
	) {
		$sql = $this->queryBuilder->buildExists($from, $where);
		$query = $this->database->prepare($sql);
		$query->execute($params);
		$this->addQuery($query->queryString, $params);
		return (boolean)$query->fetchColumn();
	}
69542
public function getFromWhere($from, $where=NULL, $where_values=array(), $order=NULL, $limit=NULL, $offset=NULL){
        $res= FALSE;
        try{
            //Armo partes de la consulta
            if($order != NULL){$order= " ORDER BY " . $order;}
            if($limit != NULL){
                $limit= " LIMIT " . $limit;
                if($offset != NULL){$limit.= ' OFFSET ' . $offset;}
            }
            //Armo y preparo la consulta
            $query= $this->prepareSelect($this->select, $from, $where, '', '', $order, $limit);
            //Ejecuto la consulta
            $query->execute($where_values);
            //Controlo que este todo bien
            if($this->isOk($query)){
                $res= $query;
            }
            //Limpio las variables del AR
            $this->cleanVars();
        } catch (\PDOException $e) {
            $this->cleanVars();
            throw $e;
        }
        return $res;
    }
167645
private static function fetchByConditions( $conditions, $limit, $offset )
    {
        $db = eZDB::instance();

        $defaultConditions = array(
            'ezcobj_state.group_id=ezcobj_state_group.id',
            'ezcobj_state_language.contentobject_state_id=ezcobj_state.id',
            eZContentLanguage::languagesSQLFilter( 'ezcobj_state' ),
            eZContentLanguage::sqlFilter( 'ezcobj_state_language', 'ezcobj_state' )
        );

        $conditions = array_merge( $conditions, $defaultConditions );

        $conditionsSQL = implode( ' AND ', $conditions );

        $sql = "SELECT ezcobj_state.*, ezcobj_state_language.* " .
               "FROM ezcobj_state, ezcobj_state_group, ezcobj_state_language " .
               "WHERE $conditionsSQL " .
               "ORDER BY ezcobj_state.priority";

        $rows = $db->arrayQuery( $sql, array( 'limit' => $limit, 'offset' => $offset ) );

        $states = array();
        foreach ( $rows as $row )
        {
            $state = new eZContentObjectState( $row );
            $stateLanguage = new eZContentObjectStateLanguage( $row );
            $state->setLanguageObject( $stateLanguage );
            $states[] = $state;
        }

        return $states;
    }