Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
|
Public Member Functions | |
__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 | 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 | |
_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) | |
Protected Attributes | |
$_bind = array() | |
$_adapter | |
$_parts = array() | |
$_tableCols = array() | |
Static Protected Attributes | |
static | $_partsInit |
static | $_joinTypes |
static | $_unionTypes |
Definition at line 44 of file Select.php.
__construct | ( | Zend_Db_Adapter_Abstract | $adapter | ) |
Class constructor
Zend_Db_Adapter_Abstract | $adapter |
Definition at line 184 of file Select.php.
__call | ( | $method, | |
array | $args | ||
) |
Turn magic function calls into non-magic function calls for joinUsing syntax
string | $method | |
array | $args | OPTIONAL Zend_Db_Table_Select query modifier |
Zend_Db_Select_Exception | If an invalid method is called. |
Recognize methods for Has-Many cases: findParent<Class>() findParent<Class>By<Rule>() Use the non-greedy pattern repeat modifier e.g. \w+?
Definition at line 1333 of file Select.php.
__toString | ( | ) |
Implements magic method.
Definition at line 1371 of file Select.php.
|
protected |
|
protected |
Return a quoted schema name
string | $schema | The schema name OPTIONAL |
Definition at line 1060 of file Select.php.
|
protected |
Return a quoted table name
string | $tableName | The table name |
string | $correlationName | The correlation name OPTIONAL |
Definition at line 1075 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. |
Zend_Db_Select_Exception |
Definition at line 779 of file Select.php.
_joinUsing | ( | $type, | |
$name, | |||
$cond, | |||
$cols = '*' , |
|||
$schema = null |
|||
) |
Handle JOIN... USING... syntax
This is functionality identical to the existing JOIN methods, however the join condition can be passed as a single column name. This method then completes the ON condition by using the same field for the FROM table and the JOIN table.
$select = $db->select()->from('table1') ->joinUsing('table2', 'column1');
// SELECT * FROM table1 JOIN table2 ON table1.column1 = table2.column2
These joins are called by the developer simply by adding 'Using' to the method name. E.g.
Definition at line 898 of file Select.php.
|
protected |
Render DISTINCT clause
string | $sql | SQL query |
Definition at line 1101 of file Select.php.
|
protected |
Render DISTINCT clause
string | $sql | SQL query |
Definition at line 1086 of file Select.php.
|
protected |
Render FOR UPDATE clause
string | $sql | SQL query |
Definition at line 1315 of file Select.php.
|
protected |
Render FROM clause
string | $sql | SQL query |
Definition at line 1134 of file Select.php.
|
protected |
Render GROUP clause
string | $sql | SQL query |
Definition at line 1222 of file Select.php.
|
protected |
Render HAVING clause
string | $sql | SQL query |
Definition at line 1241 of file Select.php.
|
protected |
Render LIMIT OFFSET clause
string | $sql | SQL query |
Definition at line 1285 of file Select.php.
|
protected |
Render ORDER clause
string | $sql | SQL query |
Definition at line 1256 of file Select.php.
|
protected |
Render UNION query
string | $sql | SQL query |
Definition at line 1182 of file Select.php.
|
protected |
Render WHERE clause
string | $sql | SQL query |
Definition at line 1207 of file Select.php.
|
protected |
Adds to the internal table-to-column mapping array.
string | $tbl | 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 | True if it should be prepended, a correlation name if it should be inserted |
Definition at line 950 of file Select.php.
|
protected |
Internal function for creating the where clause
string | $condition | |
mixed | $value | optional |
string | $type | optional |
boolean | $bool | true = AND, false = OR |
Definition at line 1023 of file Select.php.
assemble | ( | ) |
Converts this object to an SQL SELECT string.
Definition at line 724 of file Select.php.
bind | ( | $bind | ) |
Set bind variables
mixed | $bind |
Definition at line 206 of file Select.php.
columns | ( | $cols = '*' , |
|
$correlationName = null |
|||
) |
Specifies the columns used in the FROM clause.
The parameter can be a single string or Zend_Db_Expr object, or else an array of strings or Zend_Db_Expr objects.
array | string | Zend_Db_Expr | $cols | The columns to select from this table. |
string | $correlationName | Correlation name of target table. OPTIONAL |
Definition at line 264 of file Select.php.
distinct | ( | $flag = true | ) |
Makes the query SELECT DISTINCT.
bool | $flag | Whether or not the SELECT is DISTINCT (default true). |
Definition at line 219 of file Select.php.
forUpdate | ( | $flag = true | ) |
Makes the query SELECT FOR UPDATE.
bool | $flag | Whether or not the SELECT is FOR UPDATE (default true). |
Definition at line 675 of file Select.php.
from | ( | $name, | |
$cols = '*' , |
|||
$schema = null |
|||
) |
Adds a FROM table and optional columns to the query.
The first parameter $name can be a simple string, in which case the correlation name is generated automatically. If you want to specify the correlation name, the first parameter must be an associative array in which the key is the correlation name, and the value is the physical table name. For example, array('alias' => 'table'). The correlation name is prepended to all columns fetched for this table.
The second parameter can be a single string or Zend_Db_Expr object, or else an array of strings or Zend_Db_Expr objects.
The first parameter can be null or an empty string, in which case no correlation name is generated or prepended to the columns named in the second parameter.
array | string | Zend_Db_Expr | $name | The table name or an associative array relating correlation name to table name. |
array | string | Zend_Db_Expr | $cols | The columns to select from this table. |
string | $schema | The schema name to specify, if any. |
Definition at line 249 of file Select.php.
getAdapter | ( | ) |
Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Select object.
Definition at line 758 of file Select.php.
getBind | ( | ) |
getPart | ( | $part | ) |
Get part of the structured information for the current query.
string | $part |
Zend_Db_Select_Exception |
Definition at line 688 of file Select.php.
group | ( | $spec | ) |
Adds grouping to the query.
array | string | $spec | The column(s) to group by. |
Definition at line 526 of file Select.php.
having | ( | $cond, | |
$value = null , |
|||
$type = null |
|||
) |
Adds a HAVING 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. See where() for an example
string | $cond | The HAVING condition. |
mixed | $value | OPTIONAL The value to quote into the condition. |
int | $type | OPTIONAL The type of the given value |
Definition at line 556 of file Select.php.
join | ( | $name, | |
$cond, | |||
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Adds a JOIN table and columns to the query.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The 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 334 of file Select.php.
joinCross | ( | $name, | |
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add a CROSS JOIN table and colums to the query. A cross join is a cartesian product; there is no join condition.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The table name. |
array | string | $cols | The columns to select from the joined table. |
string | $schema | The database name to specify, if any. |
Definition at line 437 of file Select.php.
joinFull | ( | $name, | |
$cond, | |||
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add a FULL OUTER JOIN table and colums to the query. A full outer join is like combining a left outer join and a right outer join. All rows from both tables are included, paired with each other on the same row of the result set if they satisfy the join condition, and otherwise paired with NULLs in place of columns from the other table.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The 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 420 of file Select.php.
joinInner | ( | $name, | |
$cond, | |||
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add an INNER JOIN table and colums to the query Rows in both tables are matched according to the expression in the $cond argument. The result set is comprised of all cases where rows from the left table match rows from the right table.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The 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 355 of file Select.php.
joinLeft | ( | $name, | |
$cond, | |||
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add a LEFT OUTER JOIN table and colums to the query All rows from the left operand table are included, matching rows from the right operand table included, and the columns from the right operand table are filled with NULLs if no row exists matching the left table.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The 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 376 of file Select.php.
joinNatural | ( | $name, | |
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add a NATURAL JOIN table and colums to the query. A natural join assumes an equi-join across any column(s) that appear with the same name in both tables. Only natural inner joins are supported by this API, even though SQL permits natural outer joins as well.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The table name. |
array | string | $cols | The columns to select from the joined table. |
string | $schema | The database name to specify, if any. |
Definition at line 457 of file Select.php.
joinRight | ( | $name, | |
$cond, | |||
$cols = self::SQL_WILDCARD , |
|||
$schema = null |
|||
) |
Add a RIGHT OUTER JOIN table and colums to the query. Right outer join is the complement of left outer join. All rows from the right operand table are included, matching rows from the left operand table included, and the columns from the left operand table are filled with NULLs if no row exists matching the right table.
The $name and $cols parameters follow the same logic as described in the from() method.
array | string | Zend_Db_Expr | $name | The 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 398 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 646 of file Select.php.
limitPage | ( | $page, | |
$rowCount | |||
) |
Sets the limit and count by page number.
int | $page | Limit results to this page number. |
int | $rowCount | Use this many rows per page. |
Definition at line 660 of file Select.php.
order | ( | $spec | ) |
Adds a row order to the query.
mixed | $spec | The column(s) and direction to order by. |
Definition at line 604 of file Select.php.
orHaving | ( | $cond, | |
$value = null , |
|||
$type = null |
|||
) |
Adds a HAVING condition to the query by OR.
Otherwise identical to orHaving().
string | $cond | The HAVING condition. |
mixed | $value | OPTIONAL The value to quote into the condition. |
int | $type | OPTIONAL The type of the given value |
Definition at line 583 of file Select.php.
orWhere | ( | $cond, | |
$value = null , |
|||
$type = null |
|||
) |
Adds a WHERE condition to the query by OR.
Otherwise identical to where().
string | $cond | The WHERE condition. |
mixed | $value | OPTIONAL The value to quote into the condition. |
int | $type | OPTIONAL The type of the given value |
Definition at line 513 of file Select.php.
query | ( | $fetchMode = null , |
|
$bind = array() |
|||
) |
Executes the current select object and returns the result
integer | $fetchMode | OPTIONAL |
mixed | $bind | An array of data to bind to the placeholders. |
Definition at line 705 of file Select.php.
reset | ( | $part = null | ) |
Clear parts of the Select object, or an individual part.
string | $part | OPTIONAL |
Definition at line 742 of file Select.php.
union | ( | $select = array() , |
|
$type = self::SQL_UNION |
|||
) |
Adds a UNION clause to the query.
The first parameter has to be an array of Zend_Db_Select or sql query strings.
$sql1 = $db->select(); $sql2 = "SELECT ..."; $select = $db->select() ->union(array($sql1, $sql2)) ->order("id");
array | $select | Array of select clauses for the union. |
Definition at line 301 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. |
mixed | $value | OPTIONAL The value to quote into the condition. |
int | $type | OPTIONAL The type of the given value |
Definition at line 494 of file Select.php.
|
protected |
Definition at line 117 of file Select.php.
|
protected |
Definition at line 110 of file Select.php.
|
staticprotected |
Definition at line 145 of file Select.php.
|
protected |
Definition at line 170 of file Select.php.
|
staticprotected |
Definition at line 126 of file Select.php.
|
protected |
Definition at line 177 of file Select.php.
|
staticprotected |
Definition at line 159 of file Select.php.
const COLUMNS = 'columns' |
Definition at line 48 of file Select.php.
const CROSS_JOIN = 'cross join' |
Definition at line 63 of file Select.php.
const DISTINCT = 'distinct' |
Definition at line 47 of file Select.php.
const FOR_UPDATE = 'forupdate' |
Definition at line 57 of file Select.php.
const FROM = 'from' |
Definition at line 49 of file Select.php.
const FULL_JOIN = 'full join' |
Definition at line 62 of file Select.php.
const GROUP = 'group' |
Definition at line 52 of file Select.php.
const HAVING = 'having' |
Definition at line 53 of file Select.php.
const INNER_JOIN = 'inner join' |
Definition at line 59 of file Select.php.
const LEFT_JOIN = 'left join' |
Definition at line 60 of file Select.php.
const LIMIT_COUNT = 'limitcount' |
Definition at line 55 of file Select.php.
const LIMIT_OFFSET = 'limitoffset' |
Definition at line 56 of file Select.php.
const NATURAL_JOIN = 'natural join' |
Definition at line 64 of file Select.php.
const ORDER = 'order' |
Definition at line 54 of file Select.php.
const REGEX_COLUMN_EXPR = '/^([\w]*\s*\(([^\(\)]|(?1))*\))$/' |
Definition at line 84 of file Select.php.
const REGEX_COLUMN_EXPR_GROUP = '/^([\w]+\s*\(([^\(\)]|(?1))*\))$/' |
Definition at line 86 of file Select.php.
const REGEX_COLUMN_EXPR_ORDER = '/^([\w]+\s*\(([^\(\)]|(?1))*\))$/' |
Definition at line 85 of file Select.php.
const REGEX_SQL_COMMENTS |
Definition at line 89 of file Select.php.
const RIGHT_JOIN = 'right join' |
Definition at line 61 of file Select.php.
const SQL_AND = 'AND' |
Definition at line 77 of file Select.php.
const SQL_AS = 'AS' |
Definition at line 78 of file Select.php.
const SQL_ASC = 'ASC' |
Definition at line 81 of file Select.php.
const SQL_DESC = 'DESC' |
Definition at line 82 of file Select.php.
const SQL_DISTINCT = 'DISTINCT' |
Definition at line 72 of file Select.php.
const SQL_FOR_UPDATE = 'FOR UPDATE' |
Definition at line 76 of file Select.php.
const SQL_FROM = 'FROM' |
Definition at line 70 of file Select.php.
const SQL_GROUP_BY = 'GROUP BY' |
Definition at line 73 of file Select.php.
const SQL_HAVING = 'HAVING' |
Definition at line 75 of file Select.php.
const SQL_ON = 'ON' |
Definition at line 80 of file Select.php.
const SQL_OR = 'OR' |
Definition at line 79 of file Select.php.
const SQL_ORDER_BY = 'ORDER BY' |
Definition at line 74 of file Select.php.
const SQL_SELECT = 'SELECT' |
Definition at line 67 of file Select.php.
const SQL_UNION = 'UNION' |
Definition at line 68 of file Select.php.
const SQL_UNION_ALL = 'UNION ALL' |
Definition at line 69 of file Select.php.
const SQL_WHERE = 'WHERE' |
Definition at line 71 of file Select.php.
const SQL_WILDCARD = '*' |
Definition at line 66 of file Select.php.
const UNION = 'union' |
Definition at line 50 of file Select.php.
const WHERE = 'where' |
Definition at line 51 of file Select.php.