3030use function strncmp ;
3131
3232/**
33- * Represents an SQL statement to be executed against a database.
33+ * Represents an SQL statement to execute in a database.
3434 *
35- * A command object is usually created by calling {@see \Yiisoft\Db\Connection\ConnectionInterface::createCommand()}.
35+ * It's usually created by calling {@see \Yiisoft\Db\Connection\ConnectionInterface::createCommand()}.
3636 *
37- * The SQL statement it represents can be set via the {@see sql} property .
37+ * You can get the SQL statement it represents via the {@see getSql()} method .
3838 *
39- * To execute a non-query SQL (such as INSERT, DELETE, UPDATE), call {@see execute()}.
39+ * To execute a non-query SQL (such as ` INSERT`, ` DELETE`, ` UPDATE` ), call {@see execute()}.
4040 *
41- * To execute a SQL statement that returns a result data set (such as SELECT), use {@see queryAll()}, {@see queryOne()},
41+ * To execute a SQL statement that returns a result (such as ` SELECT` ), use {@see queryAll()}, {@see queryOne()},
4242 * {@see queryColumn()}, {@see queryScalar()}, or {@see query()}.
4343 *
4444 * For example,
4747 * $users = $connectionInterface->createCommand('SELECT * FROM user')->queryAll();
4848 * ```
4949 *
50- * Abstract command supports SQL statement preparation and parameter binding.
50+ * Abstract command supports SQL prepared statements and parameter binding.
5151 *
5252 * Call {@see bindValue()} to bind a value to a SQL parameter.
5353 * Call {@see bindParam()} to bind a PHP variable to a SQL parameter.
5454 *
5555 * When binding a parameter, the SQL statement is automatically prepared. You may also call {@see prepare()} explicitly
56- * to prepare a SQL statement .
56+ * to do it .
5757 *
58- * Abstract command also supports building SQL statements by providing methods such as {@see insert()}, {@see update()},
58+ * Abstract command supports building SQL statements using methods such as {@see insert()}, {@see update()},
5959 * etc.
6060 *
61- * For example, the following code will create and execute an INSERT SQL statement:
61+ * For example, the following code will create and execute an ` INSERT` SQL statement:
6262 *
6363 * ```php
6464 * $connectionInterface->createCommand()->insert(
6767 * )->execute();
6868 * ```
6969 *
70- * To build SELECT SQL statements, please use {@see QueryInterface} instead.
70+ * To build ` SELECT` SQL statements, please use {@see QueryInterface} instead.
7171 */
7272abstract class AbstractCommand implements CommandInterface
7373{
74- // Query mode: return count of affected rows. {@see execute()}.
74+ /**
75+ * Command in this query mode returns count of affected rows.
76+ *
77+ * @see execute()
78+ */
7579 protected const QUERY_MODE_EXECUTE = 1 ;
76- // Query mode: first row of selected data. {@see queryOne()}
80+ /**
81+ * Command in this query mode returns the first row of selected data.
82+ *
83+ * @see queryOne()
84+ */
7785 protected const QUERY_MODE_ROW = 2 ;
78- // Query mode: all rows of selected data. {@see queryAll()}
86+ /**
87+ * Command in this query mode returns all rows of selected data.
88+ *
89+ * @see queryAll()
90+ */
7991 protected const QUERY_MODE_ALL = 4 ;
80- // Query mode: all rows with first column of selected data. {@see queryColumns()}
92+ /**
93+ * Command in this query mode returns all rows with the first column of selected data.
94+ *
95+ * @see queryColumn()
96+ */
8197 protected const QUERY_MODE_COLUMN = 8 ;
82- // Query mode: returned DataReaderInterface (abstraction of db cursor to selected data) {@see query()}
98+ /**
99+ * Command in this query mode returns {@see DataReaderInterface}, an abstraction for database cursor for
100+ * selected data.
101+ *
102+ * @see query()
103+ */
83104 protected const QUERY_MODE_CURSOR = 16 ;
84105
85106 use LoggerAwareTrait;
86107 use ProfilerAwareTrait;
87108
109+ /**
110+ * @var string|null Transaction isolation level.
111+ */
88112 protected string |null $ isolationLevel = null ;
89- /** @psalm-var ParamInterface[] */
113+ /**
114+ * @var array Parameters to use.
115+ *
116+ * @psalm-var ParamInterface[]
117+ */
90118 protected array $ params = [];
119+ /**
120+ * @var string|null Name of the table to refresh schema for. Null means not to refresh the schema.
121+ */
91122 protected string |null $ refreshTableName = null ;
92123 protected Closure |null $ retryHandler = null ;
93- /** @var string The SQL statement to be executed */
124+ /**
125+ * @var string The SQL statement to execute.
126+ */
94127 private string $ sql = '' ;
95128
96129 public function addCheck (string $ table , string $ name , string $ expression ): static
@@ -339,15 +372,15 @@ public function getRawSql(): string
339372 if (!isset ($ params [0 ])) {
340373 return preg_replace_callback ('#(:\w+)# ' , static function (array $ matches ) use ($ params ): string {
341374 $ m = $ matches [1 ];
342- return (string ) ($ params [$ m ] ?? $ m );
375+ return (string )($ params [$ m ] ?? $ m );
343376 }, $ this ->sql );
344377 }
345378
346379 // Support unnamed placeholders should be dropped
347380 $ sql = '' ;
348381
349382 foreach (explode ('? ' , $ this ->sql ) as $ i => $ part ) {
350- $ sql .= $ part . (string ) ($ params [$ i ] ?? '' );
383+ $ sql .= $ part . (string )($ params [$ i ] ?? '' );
351384 }
352385
353386 return $ sql ;
@@ -507,7 +540,7 @@ public function upsert(
507540 /**
508541 * Returns the query result.
509542 *
510- * @param int $queryMode One from modes QUERY_MODE_*.
543+ * @param int $queryMode Query mode, ` QUERY_MODE_*` .
511544 *
512545 * @throws Exception
513546 * @throws Throwable
@@ -524,14 +557,21 @@ abstract protected function internalGetQueryResult(int $queryMode): mixed;
524557 */
525558 abstract protected function internalExecute (string |null $ rawSql ): void ;
526559
560+ /**
561+ * Check if the value has a given flag.
562+ *
563+ * @param int $value Flags value to check.
564+ * @param int $flag Flag to look for in the value.
565+ *
566+ * @return bool Whether the value has a given flag.
567+ */
527568 protected function is (int $ value , int $ flag ): bool
528569 {
529570 return ($ value & $ flag ) === $ flag ;
530571 }
531572
532573 /**
533- * Logs the current database query if query logging is enabled and returns the profiling token if profiling is
534- * enabled.
574+ * Logs the current database query if query logging is on and returns the profiling token if profiling is on.
535575 */
536576 protected function logQuery (string $ rawSql , string $ category ): void
537577 {
@@ -541,7 +581,7 @@ protected function logQuery(string $rawSql, string $category): void
541581 /**
542582 * The method is called after the query is executed.
543583 *
544- * @param int $queryMode One from modes QUERY_MODE_*.
584+ * @param int $queryMode Query mode, ` QUERY_MODE_*` .
545585 *
546586 * @throws Exception
547587 * @throws Throwable
@@ -595,7 +635,7 @@ protected function requireTableSchemaRefresh(string $name): static
595635 }
596636
597637 /**
598- * Marks the command to be executed in transaction.
638+ * Marks the command to execute in transaction.
599639 *
600640 * @param string|null $isolationLevel The isolation level to use for this transaction.
601641 *
0 commit comments