Command
API reference › yii › db › sqlite › Command
Command represents an SQLite’s SQL statement to be executed against a database.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$db | yii\ | The DB connection that this command is associated with Default: null. | yii\ |
$fetchMode | int | The default fetch mode for this command. Default: \. | yii\ |
$params | array | The parameters (name => value) that are bound to the current PDO statement. Default: []. | yii\ |
$pdoStatement | PDOStatement| | The PDOStatement object that this command is associated with Default: null. | yii\ |
$queryCacheDependency | yii\ | The dependency to be associated with the cached query result for this command Default: null. | yii\ |
$queryCacheDuration | int | The default number of seconds that query results can remain valid in cache. Default: null. | yii\ |
$rawSql | string | The raw SQL with parameter values inserted into the corresponding placeholders in $sql. | yii\ |
$sql | string | The SQL statement to be executed. | yii\ |
$pendingParams protected | array | Pending parameters to be bound to the current PDO statement. Default: []. Available since 2.0.33. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
addCheck() | Creates a SQL command for adding a check constraint to an existing table. | yii\ |
addColumn() | Creates a SQL command for adding a new DB column. | yii\ |
addCommentOnColumn() | Builds a SQL command for adding comment to column. | yii\ |
addCommentOnTable() | Builds a SQL command for adding comment to table. | yii\ |
addDefaultValue() | Creates a SQL command for adding a default value constraint to an existing table. | yii\ |
addForeignKey() | Creates a SQL command for adding a foreign key constraint to an existing table. | yii\ |
addPrimaryKey() | Creates a SQL command for adding a primary key constraint to an existing table. | yii\ |
addUnique() | Creates a SQL command for adding an unique constraint to an existing table. | yii\ |
alterColumn() | Creates a SQL command for changing the definition of a column. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
batchInsert() | Creates a batch INSERT command. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
bindParam() | Binds a parameter to the SQL statement to be executed. | yii\ |
bindValue() | Binds a value to a parameter. | yii\ |
bindValues() | Binds a list of values to the corresponding parameters. | yii\ |
cache() | Enables query cache for this command. | yii\ |
cancel() | Cancels the execution of the SQL statement. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
checkIntegrity() | Builds a SQL command for enabling or disabling integrity check. | Command |
className() static | Returns the fully qualified name of this class. | yii\ |
createIndex() | Creates a SQL command for creating a new index. | yii\ |
createTable() | Creates a SQL command for creating a new DB table. | yii\ |
createView() | Creates a SQL View. | yii\ |
delete() | Creates a DELETE command. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
dropCheck() | Creates a SQL command for dropping a check constraint. | yii\ |
dropColumn() | Creates a SQL command for dropping a DB column. | yii\ |
dropCommentFromColumn() | Builds a SQL command for dropping comment from column. | yii\ |
dropCommentFromTable() | Builds a SQL command for dropping comment from table. | yii\ |
dropDefaultValue() | Creates a SQL command for dropping a default value constraint. | yii\ |
dropForeignKey() | Creates a SQL command for dropping a foreign key constraint. | yii\ |
dropIndex() | Creates a SQL command for dropping an index. | yii\ |
dropPrimaryKey() | Creates a SQL command for removing a primary key constraint to an existing table. | yii\ |
dropTable() | Creates a SQL command for dropping a DB table. | yii\ |
dropUnique() | Creates a SQL command for dropping an unique constraint. | yii\ |
dropView() | Drops a SQL View. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
execute() | Executes the SQL statement. | Command |
executeResetSequence() | Executes a db command resetting the sequence value of a table’s primary key. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getRawSql() | Returns the raw SQL by inserting parameter values into the corresponding placeholders in $sql. | yii\ |
getSql() | Returns the SQL statement for this command. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the object. | yii\ |
insert() | Creates an INSERT command. | yii\ |
noCache() | Disables query cache for this command. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
prepare() | Prepares the SQL statement to be executed. | Command |
query() | Executes the SQL statement and returns query result. | yii\ |
queryAll() | Executes the SQL statement and returns ALL rows at once. | yii\ |
queryColumn() | Executes the SQL statement and returns the first column of the result. | yii\ |
queryOne() | Executes the SQL statement and returns the first row of the result. | yii\ |
queryScalar() | Executes the SQL statement and returns the value of the first column in the first row of data. | yii\ |
renameColumn() | Creates a SQL command for renaming a column. | yii\ |
renameTable() | Creates a SQL command for renaming a DB table. | yii\ |
resetSequence() | Creates a SQL command for resetting the sequence value of a table’s primary key. | yii\ |
setRawSql() | Specifies the SQL statement to be executed. The SQL statement will not be modified in any way. | yii\ |
setSql() | Specifies the SQL statement to be executed. The SQL statement will be quoted using Connection::quoteSql(). | yii\ |
trigger() | Triggers an event. | yii\ |
truncateTable() | Creates a SQL command for truncating a DB table. | yii\ |
update() | Creates an UPDATE command. | yii\ |
upsert() | Creates a command to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do. | yii\ |
bindPendingParams() protected | Binds pending parameters that were registered via bindValue() and bindValues(). | yii\ |
getCacheKey() protected | Returns the cache key for the query. | yii\ |
internalExecute() protected | Executes a prepared statement. | yii\ |
logQuery() protected | Logs the current database query if query logging is enabled and returns the profiling token if profiling is enabled. | yii\ |
queryInternal() protected | Performs the actual DB query of a SQL statement. | Command |
refreshTableSchema() protected | Refreshes table schema, which was marked by requireTableSchemaRefresh(). | yii\ |
requireTableSchemaRefresh() protected | Marks a specified table schema to be refreshed after command execution. | yii\ |
requireTransaction() protected | Marks the command to be executed in transaction. | yii\ |
reset() protected | Resets command properties to their initial state. | Command |
setRetryHandler() protected | Sets a callable (e.g. anonymous function) that is called when Exception is thrown when executing the command. The signature of the callable should be: | yii\ |
Method details
Section titled “Method details”checkIntegrity()
Section titled “checkIntegrity() ”public function checkIntegrity(mixed $check = true, mixed $schema = '', mixed $table = ''): $thisBuilds a SQL command for enabling or disabling integrity check.
Parameters
| Parameter | Type | Description |
|---|---|---|
$check | mixed | Whether to turn on or off the integrity check. |
$schema | mixed | The schema name of the tables. Defaults to empty string, meaning the current or default schema. |
$table | mixed | The table name. |
Returns
$this: The command object itself
Throws
yii\base\NotSupportedException: if this is not supported by the underlying DBMS
execute()
Section titled “execute() ”public function execute(): intExecutes the SQL statement.
This method should only be used for executing non-query SQL statement, such as INSERT, DELETE, UPDATE SQLs.
No result set will be returned.
prepare()
Section titled “prepare() ”public function prepare(mixed $forRead = null): mixedPrepares the SQL statement to be executed.
For complex SQL statement that is to be executed multiple times, this may improve performance. For SQL statement with binding parameters, this method is invoked automatically.
Parameters
| Parameter | Type | Description |
|---|---|---|
$forRead | mixed | Whether this method is called for a read query. If null, it means the SQL statement should be used to determine whether it is for read or write. |
Returns
mixed
Throws
yii\db\Exception: if there is any DB error
queryInternal()
Section titled “queryInternal() ”protected function queryInternal(mixed $method, mixed $fetchMode = null): mixedPerforms the actual DB query of a SQL statement.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | mixed | Method of PDOStatement to be called |
$fetchMode | mixed | The result fetch mode. Please refer to PHP manual for valid fetch modes. If this parameter is null, the value set in $fetchMode will be used. |
Returns
mixed: The method execution result
Throws
yii\db\Exception: if the query causes any problem
reset()
Section titled “reset() ”protected function reset(): mixedResets command properties to their initial state.
Returns
mixed
Since
2.0.13