Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
|
Public Member Functions | |
__construct (\Magento\Framework\DB\Adapter\Pdo\Mysql $adapter, \Magento\Framework\DB\Select\SelectRenderer $selectRenderer, $parts=[]) | |
where ($cond, $value=null, $type=null) | |
resetJoinLeft () | |
limit ($count=null, $offset=null) | |
crossUpdateFromSelect ($table) | |
insertFromSelect ($tableName, $fields=[], $onDuplicate=true) | |
insertIgnoreFromSelect ($tableName, $fields=[]) | |
deleteFromSelect ($table) | |
setPart ($part, $value) | |
useStraightJoin ($flag=true) | |
orderRand ($field=null) | |
exists ($select, $joinCondition, $isExists=true) | |
getConnection () | |
assemble () | |
__sleep () | |
__wakeup () | |
![]() | |
__construct (Zend_Db_Adapter_Abstract $adapter) | |
getBind () | |
bind ($bind) | |
distinct ($flag=true) | |
from ($name, $cols=' *', $schema=null) | |
columns ($cols=' *', $correlationName=null) | |
union ($select=array(), $type=self::SQL_UNION) | |
join ($name, $cond, $cols=self::SQL_WILDCARD, $schema=null) | |
joinInner ($name, $cond, $cols=self::SQL_WILDCARD, $schema=null) | |
joinLeft ($name, $cond, $cols=self::SQL_WILDCARD, $schema=null) | |
joinRight ($name, $cond, $cols=self::SQL_WILDCARD, $schema=null) | |
joinFull ($name, $cond, $cols=self::SQL_WILDCARD, $schema=null) | |
joinCross ($name, $cols=self::SQL_WILDCARD, $schema=null) | |
joinNatural ($name, $cols=self::SQL_WILDCARD, $schema=null) | |
where ($cond, $value=null, $type=null) | |
orWhere ($cond, $value=null, $type=null) | |
group ($spec) | |
having ($cond, $value=null, $type=null) | |
orHaving ($cond, $value=null, $type=null) | |
order ($spec) | |
limit ($count=null, $offset=null) | |
limitPage ($page, $rowCount) | |
forUpdate ($flag=true) | |
getPart ($part) | |
query ($fetchMode=null, $bind=array()) | |
assemble () | |
reset ($part=null) | |
getAdapter () | |
_joinUsing ($type, $name, $cond, $cols=' *', $schema=null) | |
__call ($method, array $args) | |
__toString () | |
Data Fields | |
const | TYPE_CONDITION = 'TYPE_CONDITION' |
const | STRAIGHT_JOIN = 'straightjoin' |
const | SQL_STRAIGHT_JOIN = 'STRAIGHT_JOIN' |
![]() | |
const | DISTINCT = 'distinct' |
const | COLUMNS = 'columns' |
const | FROM = 'from' |
const | UNION = 'union' |
const | WHERE = 'where' |
const | GROUP = 'group' |
const | HAVING = 'having' |
const | ORDER = 'order' |
const | LIMIT_COUNT = 'limitcount' |
const | LIMIT_OFFSET = 'limitoffset' |
const | FOR_UPDATE = 'forupdate' |
const | INNER_JOIN = 'inner join' |
const | LEFT_JOIN = 'left join' |
const | RIGHT_JOIN = 'right join' |
const | FULL_JOIN = 'full join' |
const | CROSS_JOIN = 'cross join' |
const | NATURAL_JOIN = 'natural join' |
const | SQL_WILDCARD = '*' |
const | SQL_SELECT = 'SELECT' |
const | SQL_UNION = 'UNION' |
const | SQL_UNION_ALL = 'UNION ALL' |
const | SQL_FROM = 'FROM' |
const | SQL_WHERE = 'WHERE' |
const | SQL_DISTINCT = 'DISTINCT' |
const | SQL_GROUP_BY = 'GROUP BY' |
const | SQL_ORDER_BY = 'ORDER BY' |
const | SQL_HAVING = 'HAVING' |
const | SQL_FOR_UPDATE = 'FOR UPDATE' |
const | SQL_AND = 'AND' |
const | SQL_AS = 'AS' |
const | SQL_OR = 'OR' |
const | SQL_ON = 'ON' |
const | SQL_ASC = 'ASC' |
const | SQL_DESC = 'DESC' |
const | REGEX_COLUMN_EXPR = '/^([\w]*\s*\(([^\(\)]|(?1))*\))$/' |
const | REGEX_COLUMN_EXPR_ORDER = '/^([\w]+\s*\(([^\(\)]|(?1))*\))$/' |
const | REGEX_COLUMN_EXPR_GROUP = '/^([\w]+\s*\(([^\(\)]|(?1))*\))$/' |
const | REGEX_SQL_COMMENTS |
Protected Member Functions | |
_resetJoinLeft () | |
_findTableInCond ($table, $cond) | |
_join ($type, $name, $cond, $cols, $schema=null) | |
_renderStraightjoin ($sql) | |
_tableCols ($correlationName, $cols, $afterCorrelationName=null) | |
_renderForupdate ($sql) | |
![]() | |
_join ($type, $name, $cond, $cols, $schema=null) | |
_tableCols ($correlationName, $cols, $afterCorrelationName=null) | |
_where ($condition, $value=null, $type=null, $bool=true) | |
_getDummyTable () | |
_getQuotedSchema ($schema=null) | |
_getQuotedTable ($tableName, $correlationName=null) | |
_renderDistinct ($sql) | |
_renderColumns ($sql) | |
_renderFrom ($sql) | |
_renderUnion ($sql) | |
_renderWhere ($sql) | |
_renderGroup ($sql) | |
_renderHaving ($sql) | |
_renderOrder ($sql) | |
_renderLimitoffset ($sql) | |
_renderForupdate ($sql) | |
Additional Inherited Members | |
![]() | |
$_bind = array() | |
$_adapter | |
$_parts = array() | |
$_tableCols = array() | |
![]() | |
static | $_partsInit |
static | $_joinTypes |
static | $_unionTypes |
Class for SQL SELECT generation and results.
@api @method \Magento\Framework\DB\Select from($name, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select join($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinInner($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinLeft($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinNatural($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinFull($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinRight($name, $cond, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select joinCross($name, $cols = '*', $schema = null) @method \Magento\Framework\DB\Select orWhere($cond, $value = null, $type = null) @method \Magento\Framework\DB\Select group($spec) @method \Magento\Framework\DB\Select order($spec) @method \Magento\Framework\DB\Select limitPage($page, $rowCount) @method \Magento\Framework\DB\Select forUpdate($flag = true) @method \Magento\Framework\DB\Select distinct($flag = true) @method \Magento\Framework\DB\Select reset($part = null) @method \Magento\Framework\DB\Select columns($cols = '*', $correlationName = null)
Definition at line 33 of file Select.php.
__construct | ( | \Magento\Framework\DB\Adapter\Pdo\Mysql | $adapter, |
\Magento\Framework\DB\Select\SelectRenderer | $selectRenderer, | ||
$parts = [] |
|||
) |
Class constructor Add straight join support
Adapter\Pdo\Mysql | $adapter | |
Select\SelectRenderer | $selectRenderer | |
array | $parts |
Definition at line 63 of file Select.php.
__sleep | ( | ) |
__wakeup | ( | ) |
Init not serializable fields
Definition at line 535 of file Select.php.
|
protected |
Find table name in condition (where, column)
string | $table | |
string | $cond |
Definition at line 241 of file Select.php.
|
protected |
Populate the $_parts 'join' key
Does the dirty work of populating the join key.
The $name and $cols parameters follow the same logic as described in the from() method.
null | string | $type | Type of join; inner, left, and null are currently supported |
array | string | \Zend_Db_Expr | $name | Table name |
string | $cond | Join on this condition |
array | string | $cols | The columns to select from the joined table |
string | $schema | The database name to specify, if any. |
Definition at line 293 of file Select.php.
|
protected |
Render FOR UPDATE clause
string | $sql | SQL query |
Definition at line 459 of file Select.php.
|
protected |
Render STRAIGHT_JOIN clause
string | $sql | SQL query |
Definition at line 407 of file Select.php.
|
protected |
Validate LEFT joins, and remove it if not exists
Definition at line 208 of file Select.php.
|
protected |
Adds to the internal table-to-column mapping array.
string | $correlationName | The table/join the columns come from. |
array | string | $cols | The list of columns; preferably as an array, but possibly as a string containing one column. |
bool | string | $afterCorrelationName | True if it should be prepended, a correlation name if it should be inserted |
Definition at line 426 of file Select.php.
assemble | ( | ) |
Converts this object to an SQL SELECT string.
Definition at line 507 of file Select.php.
crossUpdateFromSelect | ( | $table | ) |
Cross Table Update From Current select
string | array | $table |
Definition at line 329 of file Select.php.
deleteFromSelect | ( | $table | ) |
Retrieve DELETE query from select
string | $table | The table name or alias |
Definition at line 366 of file Select.php.
exists | ( | $select, | |
$joinCondition, | |||
$isExists = true |
|||
) |
Add EXISTS clause
Select | $select | |
string | $joinCondition | |
bool | $isExists |
Definition at line 476 of file Select.php.
getConnection | ( | ) |
Get adapter
Definition at line 496 of file Select.php.
insertFromSelect | ( | $tableName, | |
$fields = [] , |
|||
$onDuplicate = true |
|||
) |
Insert to table from current select
string | $tableName | |
array | $fields | |
bool | $onDuplicate |
Definition at line 342 of file Select.php.
insertIgnoreFromSelect | ( | $tableName, | |
$fields = [] |
|||
) |
Generate INSERT IGNORE query to the table from current select
string | $tableName | |
array | $fields |
Definition at line 355 of file Select.php.
limit | ( | $count = null , |
|
$offset = null |
|||
) |
Sets a limit count and offset to the query.
int | $count | OPTIONAL The number of rows to return. |
int | $offset | OPTIONAL Start returning after this many rows. |
Definition at line 308 of file Select.php.
orderRand | ( | $field = null | ) |
Adds the random order to query
string | $field | integer field name |
Definition at line 447 of file Select.php.
resetJoinLeft | ( | ) |
Reset unused LEFT JOIN(s)
Definition at line 130 of file Select.php.
setPart | ( | $part, | |
$value | |||
) |
Modify (hack) part of the structured information for the current query
string | $part | |
mixed | $value |
Definition at line 379 of file Select.php.
useStraightJoin | ( | $flag = true | ) |
Use a STRAIGHT_JOIN for the SQL Select
bool | $flag | Whether or not the SELECT use STRAIGHT_JOIN (default true). |
Definition at line 395 of file Select.php.
where | ( | $cond, | |
$value = null , |
|||
$type = null |
|||
) |
Adds a WHERE condition to the query by AND.
If a value is passed as the second param, it will be quoted and replaced into the condition wherever a question-mark appears. Array values are quoted and comma-separated.
// simplest but non-secure $select->where("id = $id");
// secure (ID is quoted but matched anyway) $select->where('id = ?', $id);
// alternatively, with named binding $select->where('id = :id');
Note that it is more correct to use named bindings in your queries for values other than strings. When you use named bindings, don't forget to pass the values when actually making a query:
$db->fetchAll($select, array('id' => 5));
string | $cond | The WHERE condition. |
string | $value | OPTIONAL A single value to quote into the condition. |
string | int | null | $type | OPTIONAL The type of the given value |
Definition at line 109 of file Select.php.
const SQL_STRAIGHT_JOIN = 'STRAIGHT_JOIN' |
Sql straight join
Definition at line 48 of file Select.php.
const STRAIGHT_JOIN = 'straightjoin' |
Straight join key
Definition at line 43 of file Select.php.
const TYPE_CONDITION = 'TYPE_CONDITION' |
Condition type
Definition at line 38 of file Select.php.