Class yii\sphinx\Command

Inheritanceyii\sphinx\Command » yii\db\Command » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-sphinx/blob/master/Command.php

Command represents a SQL statement to be executed against a Sphinx.

A command object is usually created by calling yii\sphinx\Connection::createCommand(). The SQL statement it represents can be set via the \yii\sphinx\sql property.

To execute a non-query SQL (such as INSERT, REPLACE, DELETE, UPDATE), call execute(). To execute a SQL statement that returns result data set (such as SELECT, CALL SNIPPETS, CALL KEYWORDS), use queryAll(), queryOne(), queryColumn(), queryScalar(), or query(). For example,

$articles = $connection->createCommand("SELECT * FROM `idx_article` WHERE MATCH('programming')")->queryAll();

Command supports SQL statement preparation and parameter binding just as yii\db\Command does.

Command also supports building SQL statements by providing methods such as insert(), update(), etc. For example,

$connection->createCommand()->update('idx_article', [
    'genre_id' => 15,
    'author_id' => 157,
])->execute();

To build SELECT SQL statements, please use yii\sphinx\Query and yii\sphinx\QueryBuilder instead.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$db yii\sphinx\Connection The Sphinx connection that this command is associated with. yii\sphinx\Command
$fetchMode integer The default fetch mode for this command. yii\db\Command
$params array The parameters (name => value) that are bound to the current PDO statement. yii\db\Command
$pdoStatement PDOStatement The PDOStatement object that this command is associated with yii\db\Command
$queryCacheDependency yii\caching\Dependency The dependency to be associated with the cached query result for this command yii\db\Command
$queryCacheDuration integer The default number of seconds that query results can remain valid in cache. yii\db\Command

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addCheck() Creates a SQL command for adding a check constraint to an existing table. yii\db\Command
addColumn() {@inheritdoc} yii\sphinx\Command
addCommentOnColumn() Builds a SQL command for adding comment to column. yii\db\Command
addCommentOnTable() Builds a SQL command for adding comment to table. yii\db\Command
addDefaultValue() Creates a SQL command for adding a default value constraint to an existing table. yii\db\Command
addForeignKey() {@inheritdoc} yii\sphinx\Command
addPrimaryKey() {@inheritdoc} yii\sphinx\Command
addUnique() Creates a SQL command for adding an unique constraint to an existing table. yii\db\Command
alterColumn() {@inheritdoc} yii\sphinx\Command
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
batchInsert() Creates a batch INSERT command. yii\sphinx\Command
batchReplace() Creates a batch REPLACE command. yii\sphinx\Command
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
bindParam() Binds a parameter to the SQL statement to be executed. yii\db\Command
bindValue() {@inheritdoc} yii\sphinx\Command
bindValues() {@inheritdoc} yii\sphinx\Command
cache() Enables query cache for this command. yii\db\Command
callKeywords() Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics. yii\sphinx\Command
callSnippets() Builds a snippet from provided data and query, using specified index settings. yii\sphinx\Command
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
cancel() Cancels the execution of the SQL statement. yii\db\Command
checkIntegrity() {@inheritdoc} yii\sphinx\Command
className() Returns the fully qualified name of this class. yii\base\BaseObject
createIndex() {@inheritdoc} yii\sphinx\Command
createTable() {@inheritdoc} yii\sphinx\Command
delete() Creates a DELETE command. yii\db\Command
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
dropCheck() Creates a SQL command for dropping a check constraint. yii\db\Command
dropColumn() {@inheritdoc} yii\sphinx\Command
dropCommentFromColumn() Builds a SQL command for dropping comment from column. yii\db\Command
dropCommentFromTable() Builds a SQL command for dropping comment from table. yii\db\Command
dropDefaultValue() Creates a SQL command for dropping a default value constraint. yii\db\Command
dropForeignKey() {@inheritdoc} yii\sphinx\Command
dropIndex() {@inheritdoc} yii\sphinx\Command
dropPrimaryKey() {@inheritdoc} yii\sphinx\Command
dropTable() {@inheritdoc} yii\sphinx\Command
dropUnique() Creates a SQL command for dropping an unique constraint. yii\db\Command
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
execute() Executes the SQL statement. yii\db\Command
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getRawSql() {@inheritdoc} yii\sphinx\Command
getSql() Returns the SQL statement for this command. yii\db\Command
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\BaseObject
insert() Creates an INSERT command. yii\db\Command
noCache() Disables query cache for this command. yii\db\Command
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
prepare() {@inheritdoc} yii\sphinx\Command
query() Executes the SQL statement and returns query result. yii\db\Command
queryAll() Executes the SQL statement and returns ALL rows at once. yii\db\Command
queryColumn() Executes the SQL statement and returns the first column of the result. yii\db\Command
queryOne() Executes the SQL statement and returns the first row of the result. yii\db\Command
queryScalar() Executes the SQL statement and returns the value of the first column in the first row of data. yii\db\Command
renameColumn() {@inheritdoc} yii\sphinx\Command
renameTable() {@inheritdoc} yii\sphinx\Command
replace() Creates an REPLACE command. yii\sphinx\Command
resetSequence() {@inheritdoc} yii\sphinx\Command
setRawSql() Specifies the SQL statement to be executed. The SQL statement will not be modified in any way. yii\db\Command
setSql() Specifies the SQL statement to be executed. The SQL statement will be quoted using yii\db\Connection::quoteSql(). yii\db\Command
trigger() Triggers an event. yii\base\Component
truncateIndex() Creates a SQL command for truncating a runtime index. yii\sphinx\Command
truncateTable() {@inheritdoc} yii\sphinx\Command
update() Creates an UPDATE command. yii\sphinx\Command

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
bindPendingParams() Binds pending parameters that were registered via bindValue() and bindValues(). yii\db\Command
queryInternal() Performs the actual DB query of a SQL statement. yii\db\Command
refreshTableSchema() Refreshes table schema, which was marked by requireTableSchemaRefresh(). yii\db\Command
requireTableSchemaRefresh() Marks a specified table schema to be refreshed after command execution. yii\db\Command
reset() Resets \yii\db\sql and $params properties. yii\db\Command

Property Details

$db public property

The Sphinx connection that this command is associated with.

public yii\sphinx\Connection $db null

Method Details

addColumn() public method

{@inheritdoc}

public void addColumn ( $table, $column, $type )
$table
$column
$type
addForeignKey() public method

{@inheritdoc}

public void addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete null, $update null )
$name
$table
$columns
$refTable
$refColumns
$delete
$update
addPrimaryKey() public method

{@inheritdoc}

public void addPrimaryKey ( $name, $table, $columns )
$name
$table
$columns
alterColumn() public method

{@inheritdoc}

public void alterColumn ( $table, $column, $type )
$table
$column
$type
batchInsert() public method

Creates a batch INSERT command.

For example,

$connection->createCommand()->batchInsert('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();

Note that the values in each row must match the corresponding column names.

public $this batchInsert ( $index, $columns, $rows )
$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

return $this

The command object itself

batchReplace() public method

Creates a batch REPLACE command.

For example,

$connection->createCommand()->batchReplace('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();

Note that the values in each row must match the corresponding column names.

public $this batchReplace ( $index, $columns, $rows )
$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

return $this

The command object itself

bindValue() public method

{@inheritdoc}

public void bindValue ( $name, $value, $dataType null )
$name
$value
$dataType
bindValues() public method

{@inheritdoc}

public void bindValues ( $values )
$values
callKeywords() public method

Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.

public $this callKeywords ( $index, $text, $fetchStatistic false )
$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

return $this

The command object itself

callSnippets() public method

Builds a snippet from provided data and query, using specified index settings.

public $this callSnippets ( $index, $source, $match, $options = [] )
$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

return $this

The command object itself

checkIntegrity() public method

{@inheritdoc}

public void checkIntegrity ( $check true, $schema '', $table '' )
$check
$schema
$table
createIndex() public method

{@inheritdoc}

public void createIndex ( $name, $table, $columns, $unique false )
$name
$table
$columns
$unique
createTable() public method

{@inheritdoc}

public void createTable ( $table, $columns, $options null )
$table
$columns
$options
dropColumn() public method

{@inheritdoc}

public void dropColumn ( $table, $column )
$table
$column
dropForeignKey() public method

{@inheritdoc}

public void dropForeignKey ( $name, $table )
$name
$table
dropIndex() public method

{@inheritdoc}

public void dropIndex ( $name, $table )
$name
$table
dropPrimaryKey() public method

{@inheritdoc}

public void dropPrimaryKey ( $name, $table )
$name
$table
dropTable() public method

{@inheritdoc}

public void dropTable ( $table )
$table
getRawSql() public method

{@inheritdoc}

public void getRawSql ( )
prepare() public method

{@inheritdoc}

public void prepare ( $forRead null )
$forRead
renameColumn() public method

{@inheritdoc}

public void renameColumn ( $table, $oldName, $newName )
$table
$oldName
$newName
renameTable() public method

{@inheritdoc}

public void renameTable ( $table, $newName )
$table
$newName
replace() public method

Creates an REPLACE command.

For example,

$connection->createCommand()->replace('idx_user', [
    'name' => 'Sam',
    'age' => 30,
])->execute();

The method will properly escape the column names, and bind the values to be replaced.

Note that the created command is not executed until execute() is called.

public $this replace ( $index, $columns )
$index string

The index that new rows will be replaced into.

$columns array

The column data (name => value) to be replaced into the index.

return $this

The command object itself

resetSequence() public method

{@inheritdoc}

public void resetSequence ( $table, $value null )
$table
$value
truncateIndex() public method

Creates a SQL command for truncating a runtime index.

public $this truncateIndex ( $index )
$index string

The index to be truncated. The name will be properly quoted by the method.

return $this

The command object itself

truncateTable() public method

{@inheritdoc}

public void truncateTable ( $table )
$table
update() public method

Creates an UPDATE command.

For example,

$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();

The method will properly escape the column names and bind the values to be updated.

Note that the created command is not executed until execute() is called.

public $this update ( $index, $columns, $condition '', $params = [], $options = [] )
$index string

The index to be updated.

$columns array

The column data (name => value) to be updated.

$condition string|array

The condition that will be put in the WHERE part. Please refer to yii\sphinx\Query::where() on how to specify condition.

$params array

The parameters to be bound to the command

$options array

List of options in format: optionName => optionValue

return $this

The command object itself