Command
API reference › yii › db › mssql › Command
Command represents an MSSQL 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. | Command |
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. | yii\ |
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. | yii\ |
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. | yii\ |
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. | yii\ |
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. | yii\ |
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”alterColumn()
Section titled “alterColumn() ”public function alterColumn(mixed $table, mixed $column, mixed $type): $thisCreates a SQL command for changing the definition of a column.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table whose column is to be changed. The table name will be properly quoted by the method. |
$column | mixed | The name of the column to be changed. The name will be properly quoted by the method. |
$type | mixed | The column type. QueryBuilder::getColumnType() will be called to convert the give column type to the physical one. For example, string will be converted as varchar(255), and string not null becomes varchar(255) not null. |
Returns
$this: The command object itself