PHP 클래스 yii\sphinx\QueryBuilder

QueryBuilder can also be used to build SQL statements such as INSERT, REPLACE, UPDATE, DELETE, from a Query object.
부터: 2.0
저자: Paul Klimov ([email protected])
상속: extends yii\base\Object
파일 보기 프로젝트 열기: yiisoft/yii2-sphinx

공개 프로퍼티들

프로퍼티 타입 설명
$db the Sphinx connection.
$querySeparator separator between different SQL queries. This is mainly used by QueryBuilder::build when generating a SQL statement.
$separator the separator between different fragments of a SQL statement. Defaults to an empty space. This is mainly used by QueryBuilder::build when generating a SQL statement.

보호된 프로퍼티들

프로퍼티 타입 설명
$conditionBuilders map of query condition to builder methods. These methods are used by [[buildCondition]] to build SQL conditions from array syntax.

공개 메소드들

메소드 설명
__construct ( Connection $connection, array $config = [] ) Constructor.
batchInsert ( string $index, array $columns, array $rows, array &$params ) : string Generates a batch INSERT SQL statement.
batchReplace ( string $index, array $columns, array $rows, array &$params ) : string Generates a batch REPLACE SQL statement.
build ( Query $query, array $params = [] ) : array Generates a SELECT SQL statement from a Query object.
buildAndCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Connects two or more SQL expressions with the AND or OR operator.
buildBetweenCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the BETWEEN operator.
buildColumns ( string | array $columns ) : string Processes columns and properly quote them if necessary.
buildCondition ( IndexSchema[] $indexes, string | array $condition, array &$params ) : string Parses the condition specification and generates the corresponding SQL expression.
buildFrom ( array $indexes, array &$params ) : string
buildGroupBy ( array $columns, integer $limit ) : string
buildHashCondition ( IndexSchema[] $indexes, array $condition, array &$params ) : string Creates a condition based on column-value pairs.
buildHaving ( string[] $indexes, string | array $condition, array &$params ) : string
buildInCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the IN operator.
buildLikeCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the LIKE operator.
buildLimit ( integer $limit, integer $offset ) : string
buildMatch ( string | yii\db\Expression | MatchExpression $match, array &$params ) : string
buildNotCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Inverts an SQL expressions with NOT operator.
buildOption ( array $options, array &$params ) : string
buildOrderBy ( array $columns ) : string
buildOrderByAndLimit ( string $sql, array $orderBy, integer $limit, integer $offset ) : string Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
buildSelect ( array $columns, array &$params, boolean $distinct = false, string $selectOption = null ) : string
buildSimpleCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string Creates an SQL expressions like "column" operator value.
buildWhere ( string[] $indexes, string | array $condition, array &$params, string | yii\db\Expression | null $match = null ) : string
buildWithin ( array $columns ) : string
callKeywords ( string $index, string $text, boolean $fetchStatistic, array &$params ) : string Builds a SQL statement for returning tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
callSnippets ( string $index, string | array $source, string $match, array $options, array &$params ) : string Builds a SQL statement for call snippet from provided data and query, using specified index settings.
delete ( string $index, array | string $condition, array &$params ) : string Creates a DELETE SQL statement.
getMatchBuilder ( ) : MatchBuilder
insert ( string $index, array $columns, array &$params ) : string Creates an INSERT SQL statement.
replace ( string $index, array $columns, array &$params ) : string Creates an REPLACE SQL statement.
truncateIndex ( string $index ) : string Builds a SQL statement for truncating an index.
update ( string $index, array $columns, array | string $condition, array &$params, array $options ) : string Creates an UPDATE SQL statement.

보호된 메소드들

메소드 설명
buildCompositeInCondition ( IndexSchema[] $indexes, string $operator, array $columns, array $values, array &$params ) : string
buildFacets ( array $facets, array &$params ) : string
buildShowMeta ( boolean | string | yii\db\Expression $showMeta, array &$params ) : string Builds SHOW META query.
composeColumnValue ( IndexSchema[] $indexes, string $columnName, mixed $value, array &$params ) : string Composes column value for SQL, taking in account the column type.
generateBatchInsertReplace ( string $statement, string $index, array $columns, array $rows, array &$params ) : string Generates a batch INSERT/REPLACE SQL statement.
generateInsertReplace ( string $statement, string $index, array $columns, array &$params ) : string Generates INSERT/REPLACE SQL statement.

비공개 메소드들

메소드 설명
buildSelectFields ( array $columns, array &$params ) : string
getIndexSchemas ( array $indexes ) : IndexSchema[]

메소드 상세

__construct() 공개 메소드

Constructor.
public __construct ( Connection $connection, array $config = [] )
$connection Connection the Sphinx connection.
$config array name-value pairs that will be used to initialize the object properties

batchInsert() 공개 메소드

For example, php $sql = $queryBuilder->batchInsert('idx_user', ['id', 'name', 'age'], [ [1, 'Tom', 30], [2, 'Jane', 20], [3, 'Linda', 25], ], $params); Note that the values in each row must match the corresponding column names.
public batchInsert ( string $index, array $columns, array $rows, array &$params ) : string
$index string the index that new rows will be inserted into.
$columns array the column names
$rows array the rows to be batch inserted into the index
$params array the binding parameters that will be generated by this method. They should be bound to the Sphinx command later.
리턴 string the batch INSERT SQL statement

batchReplace() 공개 메소드

For example, php $sql = $queryBuilder->batchReplace('idx_user', ['id', 'name', 'age'], [ [1, 'Tom', 30], [2, 'Jane', 20], [3, 'Linda', 25], ], $params); Note that the values in each row must match the corresponding column names.
public batchReplace ( string $index, array $columns, array $rows, array &$params ) : string
$index string the index that new rows will be replaced.
$columns array the column names
$rows array the rows to be batch replaced in the index
$params array the binding parameters that will be generated by this method. They should be bound to the Sphinx command later.
리턴 string the batch INSERT SQL statement

build() 공개 메소드

Generates a SELECT SQL statement from a Query object.
public build ( Query $query, array $params = [] ) : array
$query Query the [[Query]] object from which the SQL statement will be generated
$params array the parameters to be bound to the generated SQL statement. These parameters will be included in the result with the additional parameters generated during the query building process.
리턴 array the generated SQL statement (the first array element) and the corresponding parameters to be bound to the SQL statement (the second array element). The parameters returned include those provided in `$params`.

buildAndCondition() 공개 메소드

Connects two or more SQL expressions with the AND or OR operator.
public buildAndCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use for connecting the given operands
$operands array the SQL expressions to connect.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildBetweenCondition() 공개 메소드

Creates an SQL expressions with the BETWEEN operator.
public buildBetweenCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use (e.g. `BETWEEN` or `NOT BETWEEN`)
$operands array the first operand is the column name. The second and third operands describe the interval that column value should be in.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildColumns() 공개 메소드

It will join all columns into a string with comma as separators.
public buildColumns ( string | array $columns ) : string
$columns string | array the columns to be processed
리턴 string the processing result

buildCompositeInCondition() 보호된 메소드

protected buildCompositeInCondition ( IndexSchema[] $indexes, string $operator, array $columns, array $values, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use (e.g. `IN` or `NOT IN`)
$columns array
$values array
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildCondition() 공개 메소드

Parses the condition specification and generates the corresponding SQL expression.
public buildCondition ( IndexSchema[] $indexes, string | array $condition, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$condition string | array the condition specification. Please refer to [[Query::where()]] on how to specify a condition.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildFacets() 보호된 메소드

protected buildFacets ( array $facets, array &$params ) : string
$facets array facet specifications
$params array the binding parameters to be populated
리턴 string the FACET clause build from [[query]]

buildFrom() 공개 메소드

public buildFrom ( array $indexes, array &$params ) : string
$indexes array
$params array the binding parameters to be populated
리턴 string the FROM clause built from [[query]].

buildGroupBy() 공개 메소드

public buildGroupBy ( array $columns, integer $limit ) : string
$columns array group columns
$limit integer group limit
리턴 string the GROUP BY clause

buildHashCondition() 공개 메소드

Creates a condition based on column-value pairs.
public buildHashCondition ( IndexSchema[] $indexes, array $condition, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$condition array the condition specification.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildHaving() 공개 메소드

public buildHaving ( string[] $indexes, string | array $condition, array &$params ) : string
$indexes string[] list of index names, which affected by query
$condition string | array
$params array the binding parameters to be populated
리턴 string the HAVING clause built from [[Query::$having]].

buildInCondition() 공개 메소드

Creates an SQL expressions with the IN operator.
public buildInCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use (e.g. `IN` or `NOT IN`)
$operands array the first operand is the column name. If it is an array a composite IN condition will be generated. The second operand is an array of values that column value should be among. If it is an empty array the generated expression will be a `false` value if operator is `IN` and empty if operator is `NOT IN`.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildLikeCondition() 공개 메소드

Creates an SQL expressions with the LIKE operator.
public buildLikeCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use (e.g. `LIKE`, `NOT LIKE`, `OR LIKE` or `OR NOT LIKE`)
$operands array an array of two or three operands - The first operand is the column name. - The second operand is a single value or an array of values that column value should be compared with. If it is an empty array the generated expression will be a `false` value if operator is `LIKE` or `OR LIKE`, and empty if operator is `NOT LIKE` or `OR NOT LIKE`. - An optional third operand can also be provided to specify how to escape special characters in the value(s). The operand should be an array of mappings from the special characters to their escaped counterparts. If this operand is not provided, a default escape mapping will be used. You may use `false` or an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildLimit() 공개 메소드

public buildLimit ( integer $limit, integer $offset ) : string
$limit integer
$offset integer
리턴 string the LIMIT and OFFSET clauses built from [[query]].

buildMatch() 공개 메소드

public buildMatch ( string | yii\db\Expression | MatchExpression $match, array &$params ) : string
$match string | yii\db\Expression | MatchExpression match condition
$params array the binding parameters to be populated
리턴 string generated MATCH expression

buildNotCondition() 공개 메소드

Inverts an SQL expressions with NOT operator.
public buildNotCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use for connecting the given operands
$operands array the SQL expressions to connect.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildOption() 공개 메소드

public buildOption ( array $options, array &$params ) : string
$options array query options in format: optionName => optionValue
$params array the binding parameters to be populated
리턴 string the OPTION clause build from [[query]]

buildOrderBy() 공개 메소드

public buildOrderBy ( array $columns ) : string
$columns array
리턴 string the ORDER BY clause built from [[query]].

buildOrderByAndLimit() 공개 메소드

Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
public buildOrderByAndLimit ( string $sql, array $orderBy, integer $limit, integer $offset ) : string
$sql string the existing SQL (without ORDER BY/LIMIT/OFFSET)
$orderBy array the order by columns. See [[Query::orderBy]] for more details on how to specify this parameter.
$limit integer the limit number. See [[Query::limit]] for more details.
$offset integer the offset number. See [[Query::offset]] for more details.
리턴 string the SQL completed with ORDER BY/LIMIT/OFFSET (if any)

buildSelect() 공개 메소드

public buildSelect ( array $columns, array &$params, boolean $distinct = false, string $selectOption = null ) : string
$columns array
$params array the binding parameters to be populated
$distinct boolean
$selectOption string
리턴 string the SELECT clause built from [[query]].

buildShowMeta() 보호된 메소드

Builds SHOW META query.
protected buildShowMeta ( boolean | string | yii\db\Expression $showMeta, array &$params ) : string
$showMeta boolean | string | yii\db\Expression show meta specification.
$params array the binding parameters to be populated
리턴 string SHOW META query, if it does not required - empty string.

buildSimpleCondition() 공개 메소드

Creates an SQL expressions like "column" operator value.
public buildSimpleCondition ( IndexSchema[] $indexes, string $operator, array $operands, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$operator string the operator to use. Anything could be used e.g. `>`, `<=`, etc.
$operands array contains two column names.
$params array the binding parameters to be populated
리턴 string the generated SQL expression

buildWhere() 공개 메소드

public buildWhere ( string[] $indexes, string | array $condition, array &$params, string | yii\db\Expression | null $match = null ) : string
$indexes string[] list of index names, which affected by query
$condition string | array
$params array the binding parameters to be populated
$match string | yii\db\Expression | null
리턴 string the WHERE clause built from [[query]].

buildWithin() 공개 메소드

public buildWithin ( array $columns ) : string
$columns array
리턴 string the ORDER BY clause built from [[query]].

callKeywords() 공개 메소드

Builds a SQL statement for returning tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
public callKeywords ( string $index, string $text, boolean $fetchStatistic, array &$params ) : string
$index string the name of the index from which to take the text processing settings
$text string the text to break down to keywords.
$fetchStatistic boolean whether to return document and hit occurrence statistics
$params array the binding parameters that will be modified by this method so that they can be bound to the Sphinx command later.
리턴 string the SQL statement for call keywords.

callSnippets() 공개 메소드

Builds a SQL statement for call snippet from provided data and query, using specified index settings.
public callSnippets ( string $index, string | array $source, string $match, array $options, array &$params ) : string
$index string name of the index, from which to take the text processing settings.
$source string | array is the source data to extract a snippet from. It could be either a single string or array of strings.
$match string the full-text query to build snippets for.
$options array list of options in format: optionName => optionValue
$params array the binding parameters that will be modified by this method so that they can be bound to the Sphinx command later.
리턴 string the SQL statement for call snippets.

composeColumnValue() 보호된 메소드

Composes column value for SQL, taking in account the column type.
protected composeColumnValue ( IndexSchema[] $indexes, string $columnName, mixed $value, array &$params ) : string
$indexes IndexSchema[] list of indexes, which affected by query
$columnName string name of the column
$value mixed raw column value
$params array the binding parameters to be populated
리턴 string SQL expression, which represents column value

delete() 공개 메소드

For example, php $sql = $queryBuilder->delete('idx_user', 'status = 0'); The method will properly escape the index and column names.
public delete ( string $index, array | string $condition, array &$params ) : string
$index string the index where the data will be deleted from.
$condition array | string the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition.
$params array the binding parameters that will be modified by this method so that they can be bound to the Sphinx command later.
리턴 string the DELETE SQL

generateBatchInsertReplace() 보호된 메소드

Generates a batch INSERT/REPLACE SQL statement.
protected generateBatchInsertReplace ( string $statement, string $index, array $columns, array $rows, array &$params ) : string
$statement string statement ot be generated.
$index string the affected index name.
$columns array the column data (name => value).
$rows array the rows to be batch inserted into the index
$params array the binding parameters that will be generated by this method.
리턴 string generated SQL

generateInsertReplace() 보호된 메소드

Generates INSERT/REPLACE SQL statement.
protected generateInsertReplace ( string $statement, string $index, array $columns, array &$params ) : string
$statement string statement ot be generated.
$index string the affected index name.
$columns array the column data (name => value).
$params array the binding parameters that will be generated by this method.
리턴 string generated SQL

getMatchBuilder() 공개 메소드

부터: 2.0.6
public getMatchBuilder ( ) : MatchBuilder
리턴 MatchBuilder match builder.

insert() 공개 메소드

For example, php $sql = $queryBuilder->insert('idx_user', [ 'name' => 'Sam', 'age' => 30, 'id' => 10, ], $params); The method will properly escape the index and column names.
public insert ( string $index, array $columns, array &$params ) : string
$index string the index that new rows will be inserted into.
$columns array the column data (name => value) to be inserted into the index.
$params array the binding parameters that will be generated by this method. They should be bound to the Sphinx command later.
리턴 string the INSERT SQL

replace() 공개 메소드

For example, php $sql = $queryBuilder->replace('idx_user', [ 'name' => 'Sam', 'age' => 30, 'id' => 10, ], $params); The method will properly escape the index and column names.
public replace ( string $index, array $columns, array &$params ) : string
$index string the index that new rows will be replaced.
$columns array the column data (name => value) to be replaced in the index.
$params array the binding parameters that will be generated by this method. They should be bound to the Sphinx command later.
리턴 string the INSERT SQL

truncateIndex() 공개 메소드

Builds a SQL statement for truncating an index.
public truncateIndex ( string $index ) : string
$index string the index to be truncated. The name will be properly quoted by the method.
리턴 string the SQL statement for truncating an index.

update() 공개 메소드

For example, php $params = []; $sql = $queryBuilder->update('idx_user', ['status' => 1], 'age > 30', $params); The method will properly escape the index and column names.
public update ( string $index, array $columns, array | string $condition, array &$params, array $options ) : string
$index string the index to be updated.
$columns array the column data (name => value) to be updated.
$condition array | string the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition.
$params array the binding parameters that will be modified by this method so that they can be bound to the Sphinx command later.
$options array list of options in format: optionName => optionValue
리턴 string the UPDATE SQL

프로퍼티 상세

$conditionBuilders 보호되어 있는 프로퍼티

map of query condition to builder methods. These methods are used by [[buildCondition]] to build SQL conditions from array syntax.
protected $conditionBuilders

$db 공개적으로 프로퍼티

the Sphinx connection.
public $db

$querySeparator 공개적으로 프로퍼티

separator between different SQL queries. This is mainly used by QueryBuilder::build when generating a SQL statement.
public $querySeparator

$separator 공개적으로 프로퍼티

the separator between different fragments of a SQL statement. Defaults to an empty space. This is mainly used by QueryBuilder::build when generating a SQL statement.
public $separator