This commit is contained in:
Qiang Xue
2011-11-12 21:49:52 -05:00
parent 03ea25b1c8
commit b947d68884
7 changed files with 79 additions and 45 deletions

View File

@@ -20,15 +20,20 @@ use yii\db\Exception;
*
* To execute a non-query SQL (such as INSERT, DELETE, UPDATE), call [[execute]].
* To execute a SQL statement that returns result data set (such as SELECT),
* use [[query]], [[queryRow]], [[queryColumn]], or [[queryScalar]].
* use [[queryAll]], [[queryRow]], [[queryColumn]], [[queryScalar]], or [[query]].
* For example,
*
* ~~~
* $users = \Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll();
* ~~~
*
* Command supports SQL statement preparation and parameter binding.
* Call [[bindValue]] to bind a value to a SQL parameter;
* Call [[bindParam]] to bind a PHP variable to a SQL parameter.
* When binding a parameter, the SQL statement is automatically prepared.
* You may also call [[prepare]] to explicitly prepare a SQL statement.
* You may also call [[prepare]] explicitly to prepare a SQL statement.
*
* Command can also be used as a query builder that builds and executes a SQL statement
* Command can be used as a query builder that builds and executes a SQL statement
* from code fragments. For example,
*
* ~~~

View File

@@ -37,6 +37,9 @@ use yii\db\Exception;
*/
class DataReader extends \yii\base\Object implements \Iterator, \Countable
{
/**
* @var \PDOStatement the PDOStatement associated with the command
*/
private $_statement;
private $_closed = false;
private $_row;
@@ -48,7 +51,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable
*/
public function __construct(Command $command)
{
$this->_statement = $command->getPdoStatement();
$this->_statement = $command->pdoStatement;
$this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
}

View File

@@ -45,7 +45,6 @@ class Transaction extends \yii\base\Object
public $active;
/**
* @var Connection the database connection that this transaction is associated with.
* This property is set true when the transaction is started.
*/
public $connection;
@@ -70,9 +69,8 @@ class Transaction extends \yii\base\Object
\Yii::trace('Committing transaction', __CLASS__);
$this->connection->pdo->commit();
$this->active = false;
}
else {
throw new Exception('Transaction is inactive and cannot perform commit operation.');
} else {
throw new Exception('Failed to commit transaction: transaction was inactive.');
}
}
@@ -86,9 +84,8 @@ class Transaction extends \yii\base\Object
\Yii::trace('Rolling back transaction', __CLASS__);
$this->connection->pdo->rollBack();
$this->active = false;
}
else {
throw new Exception('Transaction is inactive and cannot perform roll back operation.');
} else {
throw new Exception('Failed to roll back transaction: transaction was inactive.');
}
}
}