Browse Source

reorganized DB classes.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
8517ee9e50
  1. 6
      docs/model.md
  2. 4
      framework/base/Application.php
  3. 2
      framework/base/Module.php
  4. 4
      framework/caching/DbCache.php
  5. 4
      framework/caching/DbDependency.php
  6. 2
      framework/console/create/default/protected/config/main.php
  7. 12
      framework/db/ActiveQuery.php
  8. 10
      framework/db/ActiveRecord.php
  9. 2
      framework/db/ActiveRecordBehavior.php
  10. 8
      framework/db/ActiveRelation.php
  11. 2
      framework/db/BaseQuery.php
  12. 2
      framework/db/ColumnSchema.php
  13. 2
      framework/db/Command.php
  14. 24
      framework/db/Connection.php
  15. 2
      framework/db/DataReader.php
  16. 2
      framework/db/Driver.php
  17. 2
      framework/db/Expression.php
  18. 8
      framework/db/Query.php
  19. 2
      framework/db/QueryBuilder.php
  20. 2
      framework/db/TableSchema.php
  21. 2
      framework/db/Transaction.php
  22. 20
      framework/db/mysql/Driver.php
  23. 4
      framework/db/mysql/QueryBuilder.php
  24. 18
      framework/db/sqlite/Driver.php
  25. 4
      framework/db/sqlite/QueryBuilder.php
  26. 8
      framework/logging/DbTarget.php
  27. 2
      framework/logging/Logger.php
  28. 4
      framework/logging/Target.php
  29. 12
      framework/validators/ExistValidator.php
  30. 6
      framework/validators/UniqueValidator.php
  31. 4
      tests/unit/MysqlTestCase.php
  32. 4
      tests/unit/data/ar/ActiveRecord.php
  33. 2
      tests/unit/data/ar/Customer.php
  34. 4
      tests/unit/framework/db/ar/ActiveRecordTest.php
  35. 8
      tests/unit/framework/db/dao/CommandTest.php
  36. 2
      tests/unit/framework/db/dao/ConnectionTest.php
  37. 8
      tests/unit/framework/db/dao/QueryTest.php
  38. 4
      upgrade.md

6
docs/model.md

@ -20,7 +20,7 @@ A model should list all its available attributes in the `attributes()` method.
Attributes may be implemented in various ways. The [[\yii\base\Model]] class Attributes may be implemented in various ways. The [[\yii\base\Model]] class
implements attributes as public member variables of the class, while the implements attributes as public member variables of the class, while the
[[\yii\db\ar\ActiveRecord]] class implements them as DB table columns. For example, [[\yii\db\ActiveRecord]] class implements them as DB table columns. For example,
~~~php ~~~php
// LoginForm has two attributes: username and password // LoginForm has two attributes: username and password
@ -32,7 +32,7 @@ class LoginForm extends \yii\base\Model
// Post is associated with the tbl_post DB table. // Post is associated with the tbl_post DB table.
// Its attributes correspond to the columns in tbl_post // Its attributes correspond to the columns in tbl_post
class Post extends \yii\db\ar\ActiveRecord class Post extends \yii\db\ActiveRecord
{ {
public function table() public function table()
{ {
@ -65,7 +65,7 @@ whose keys are the scenario names and whose values are the corresponding
active attribute lists. Below is an example: active attribute lists. Below is an example:
~~~php ~~~php
class User extends \yii\db\ar\ActiveRecord class User extends \yii\db\ActiveRecord
{ {
public function table() public function table()
{ {

4
framework/base/Application.php

@ -52,7 +52,7 @@ use yii\base\Exception;
* @property CCache $cache Returns the cache component. * @property CCache $cache Returns the cache component.
* @property CPhpMessageSource $coreMessages Returns the core message translations. * @property CPhpMessageSource $coreMessages Returns the core message translations.
* @property CDateFormatter $dateFormatter Returns the locale-dependent date formatter. * @property CDateFormatter $dateFormatter Returns the locale-dependent date formatter.
* @property \yii\db\dao\Connection $db Returns the database connection component. * @property \yii\db\Connection $db Returns the database connection component.
* @property CErrorHandler $errorHandler Returns the error handler component. * @property CErrorHandler $errorHandler Returns the error handler component.
* @property string $extensionPath Returns the root directory that holds all third-party extensions. * @property string $extensionPath Returns the root directory that holds all third-party extensions.
* @property string $id Returns the unique identifier for the application. * @property string $id Returns the unique identifier for the application.
@ -324,7 +324,7 @@ class Application extends Module
/** /**
* Returns the database connection component. * Returns the database connection component.
* @return \yii\db\dao\Connection the database connection * @return \yii\db\Connection the database connection
*/ */
public function getDb() public function getDb()
{ {

2
framework/base/Module.php

@ -501,7 +501,7 @@ abstract class Module extends Component
* ~~~ * ~~~
* array( * array(
* 'db' => array( * 'db' => array(
* 'class' => 'yii\db\dao\Connection', * 'class' => 'yii\db\Connection',
* 'dsn' => 'sqlite:path/to/file.db', * 'dsn' => 'sqlite:path/to/file.db',
* ), * ),
* 'cache' => array( * 'cache' => array(

4
framework/caching/DbCache.php

@ -10,8 +10,8 @@
namespace yii\caching; namespace yii\caching;
use yii\base\Exception; use yii\base\Exception;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Query; use yii\db\Query;
/** /**
* DbCache implements a cache application component by storing cached data in a database. * DbCache implements a cache application component by storing cached data in a database.

4
framework/caching/DbDependency.php

@ -10,8 +10,8 @@
namespace yii\caching; namespace yii\caching;
use yii\base\Exception; use yii\base\Exception;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Query; use yii\db\Query;
/** /**
* DbDependency represents a dependency based on the query result of a SQL statement. * DbDependency represents a dependency based on the query result of a SQL statement.

2
framework/console/create/default/protected/config/main.php

@ -6,7 +6,7 @@ return array(
// uncomment the following to use a MySQL database // uncomment the following to use a MySQL database
/* /*
'db' => array( 'db' => array(
'class' => 'yii\db\dao\Connection', 'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=testdrive', 'dsn' => 'mysql:host=localhost;dbname=testdrive',
'username' => 'root', 'username' => 'root',
'password' => '', 'password' => '',

12
framework/db/ar/ActiveQuery.php → framework/db/ActiveQuery.php

@ -8,14 +8,14 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\ar; namespace yii\db;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Command; use yii\db\Command;
use yii\db\dao\QueryBuilder; use yii\db\QueryBuilder;
use yii\db\dao\BaseQuery; use yii\db\BaseQuery;
use yii\base\VectorIterator; use yii\base\VectorIterator;
use yii\db\dao\Expression; use yii\db\Expression;
use yii\db\Exception; use yii\db\Exception;
class ActiveQuery extends BaseQuery class ActiveQuery extends BaseQuery

10
framework/db/ar/ActiveRecord.php → framework/db/ActiveRecord.php

@ -8,16 +8,16 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\ar; namespace yii\db;
use yii\base\Model; use yii\base\Model;
use yii\base\Event; use yii\base\Event;
use yii\base\ModelEvent; use yii\base\ModelEvent;
use yii\db\Exception; use yii\db\Exception;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\TableSchema; use yii\db\TableSchema;
use yii\db\dao\Query; use yii\db\Query;
use yii\db\dao\Expression; use yii\db\Expression;
use yii\util\StringHelper; use yii\util\StringHelper;
/** /**

2
framework/db/ar/ActiveRecordBehavior.php → framework/db/ActiveRecordBehavior.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\ar; namespace yii\db;
use yii\base\ModelBehavior; use yii\base\ModelBehavior;

8
framework/db/ar/ActiveRelation.php → framework/db/ActiveRelation.php

@ -8,11 +8,11 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\ar; namespace yii\db;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Command; use yii\db\Command;
use yii\db\dao\QueryBuilder; use yii\db\QueryBuilder;
/** /**
* It is used in three scenarios: * It is used in three scenarios:

2
framework/db/dao/BaseQuery.php → framework/db/BaseQuery.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
/** /**
* BaseQuery is the base class that represents a SQL SELECT statement in a DBMS-independent way. * BaseQuery is the base class that represents a SQL SELECT statement in a DBMS-independent way.

2
framework/db/dao/ColumnSchema.php → framework/db/ColumnSchema.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
/** /**
* ColumnSchema class describes the metadata of a column in a database table. * ColumnSchema class describes the metadata of a column in a database table.

2
framework/db/dao/Command.php → framework/db/Command.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

24
framework/db/dao/Connection.php → framework/db/Connection.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;
@ -25,7 +25,7 @@ use yii\db\Exception;
* the DB connection: * the DB connection:
* *
* ~~~ * ~~~
* $connection = new \yii\db\dao\Connection(array( * $connection = new \yii\db\Connection(array(
* 'dsn' => $dsn, * 'dsn' => $dsn,
* 'username' => $username, * 'username' => $username,
* 'password' => $password, * 'password' => $password,
@ -76,7 +76,7 @@ use yii\db\Exception;
* array( * array(
* 'components' => array( * 'components' => array(
* 'db' => array( * 'db' => array(
* 'class' => '\yii\db\dao\Connection', * 'class' => '\yii\db\Connection',
* 'dsn' => 'mysql:host=127.0.0.1;dbname=demo', * 'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
* 'username' => 'root', * 'username' => 'root',
* 'password' => '', * 'password' => '',
@ -238,15 +238,15 @@ class Connection extends \yii\base\ApplicationComponent
* [[Driver]] class to support DBMS that is not supported by Yii. * [[Driver]] class to support DBMS that is not supported by Yii.
*/ */
public $driverMap = array( public $driverMap = array(
'pgsql' => 'yii\db\dao\pgsql\Driver', // PostgreSQL 'pgsql' => 'yii\db\pgsql\Driver', // PostgreSQL
'mysqli' => 'yii\db\dao\mysql\Driver', // MySQL 'mysqli' => 'yii\db\mysql\Driver', // MySQL
'mysql' => 'yii\db\dao\mysql\Driver', // MySQL 'mysql' => 'yii\db\mysql\Driver', // MySQL
'sqlite' => 'yii\db\dao\sqlite\Driver', // sqlite 3 'sqlite' => 'yii\db\sqlite\Driver', // sqlite 3
'sqlite2' => 'yii\db\dao\sqlite\Driver', // sqlite 2 'sqlite2' => 'yii\db\sqlite\Driver', // sqlite 2
'mssql' => 'yi\db\dao\mssql\Driver', // Mssql driver on windows hosts 'mssql' => 'yi\db\dao\mssql\Driver', // Mssql driver on windows hosts
'dblib' => 'yii\db\dao\mssql\Driver', // dblib drivers on linux (and maybe others os) hosts 'dblib' => 'yii\db\mssql\Driver', // dblib drivers on linux (and maybe others os) hosts
'sqlsrv' => 'yii\db\dao\mssql\Driver', // Mssql 'sqlsrv' => 'yii\db\mssql\Driver', // Mssql
'oci' => 'yii\db\dao\oci\Driver', // Oracle driver 'oci' => 'yii\db\oci\Driver', // Oracle driver
); );
/** /**
* @var Transaction the currently active transaction * @var Transaction the currently active transaction
@ -612,7 +612,7 @@ class Connection extends \yii\base\ApplicationComponent
public function getStats() public function getStats()
{ {
$logger = \Yii::getLogger(); $logger = \Yii::getLogger();
$timings = $logger->getProfiling(array('yii\db\dao\Command::query', 'yii\db\dao\Command::execute')); $timings = $logger->getProfiling(array('yii\db\Command::query', 'yii\db\Command::execute'));
$count = count($timings); $count = count($timings);
$time = 0; $time = 0;
foreach ($timings as $timing) { foreach ($timings as $timing) {

2
framework/db/dao/DataReader.php → framework/db/DataReader.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

2
framework/db/dao/Driver.php → framework/db/Driver.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

2
framework/db/dao/Expression.php → framework/db/Expression.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
/** /**
* Expression represents a DB expression that does not need escaping or quoting. * Expression represents a DB expression that does not need escaping or quoting.

8
framework/db/dao/Query.php → framework/db/Query.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
/** /**
* Query represents a SQL statement in a way that is independent of DBMS. * Query represents a SQL statement in a way that is independent of DBMS.
@ -144,7 +144,7 @@ class Query extends BaseQuery
* The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'), * The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'),
* where name stands for a column name which will be properly quoted by the method, and definition * where name stands for a column name which will be properly quoted by the method, and definition
* stands for the column type which can contain an abstract DB type. * stands for the column type which can contain an abstract DB type.
* The method [[\yii\db\dao\QueryBuilder::getColumnType()]] will be called * The method [[\yii\db\QueryBuilder::getColumnType()]] will be called
* to convert the abstract column types to physical ones. For example, `string` will be converted * to convert the abstract column types to physical ones. For example, `string` will be converted
* as `varchar(255)`, and `string not null` becomes `varchar(255) not null`. * as `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
* *
@ -200,7 +200,7 @@ class Query extends BaseQuery
* Builds and executes a SQL statement for adding a new DB column. * Builds and executes a SQL statement for adding a new DB column.
* @param string $table the table that the new column will be added to. The table name will be properly quoted by the method. * @param string $table the table that the new column will be added to. The table name will be properly quoted by the method.
* @param string $column the name of the new column. The name will be properly quoted by the method. * @param string $column the name of the new column. The name will be properly quoted by the method.
* @param string $type the column type. [[\yii\db\dao\QueryBuilder::getColumnType()]] will be called * @param string $type the column type. [[\yii\db\QueryBuilder::getColumnType()]] will be called
* to convert the give column type to the physical one. For example, `string` will be converted * 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`. * as `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
* @return Query the query object itself * @return Query the query object itself
@ -240,7 +240,7 @@ class Query extends BaseQuery
* Builds and executes a SQL statement for changing the definition of a column. * Builds and executes a SQL statement for changing the definition of a column.
* @param string $table the table whose column is to be changed. The table name will be properly quoted by the method. * @param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
* @param string $column the name of the column to be changed. The name will be properly quoted by the method. * @param string $column the name of the column to be changed. The name will be properly quoted by the method.
* @param string $type the column type. [[\yii\db\dao\QueryBuilder::getColumnType()]] will be called * @param string $type the column type. [[\yii\db\QueryBuilder::getColumnType()]] will be called
* to convert the give column type to the physical one. For example, `string` will be converted * 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`. * as `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
* @return Query the query object itself * @return Query the query object itself

2
framework/db/dao/QueryBuilder.php → framework/db/QueryBuilder.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

2
framework/db/dao/TableSchema.php → framework/db/TableSchema.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

2
framework/db/dao/Transaction.php → framework/db/Transaction.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao; namespace yii\db;
use yii\db\Exception; use yii\db\Exception;

20
framework/db/dao/mysql/Driver.php → framework/db/mysql/Driver.php

@ -7,10 +7,10 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao\mysql; namespace yii\db\mysql;
use yii\db\dao\TableSchema; use yii\db\TableSchema;
use yii\db\dao\ColumnSchema; use yii\db\ColumnSchema;
/** /**
* Driver is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x). * Driver is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).
@ -18,7 +18,7 @@ use yii\db\dao\ColumnSchema;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Driver extends \yii\db\dao\Driver class Driver extends \yii\db\Driver
{ {
/** /**
* @var array mapping from physical column types (keys) to abstract column types (values) * @var array mapping from physical column types (keys) to abstract column types (values)
@ -85,7 +85,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Loads the metadata for the specified table. * Loads the metadata for the specified table.
* @param string $name table name * @param string $name table name
* @return \yii\db\dao\TableSchema driver dependent table metadata. Null if the table does not exist. * @return \yii\db\TableSchema driver dependent table metadata. Null if the table does not exist.
*/ */
protected function loadTableSchema($name) protected function loadTableSchema($name)
{ {
@ -100,7 +100,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Resolves the table name and schema name (if any). * Resolves the table name and schema name (if any).
* @param \yii\db\dao\TableSchema $table the table metadata object * @param \yii\db\TableSchema $table the table metadata object
* @param string $name the table name * @param string $name the table name
*/ */
protected function resolveTableNames($table, $name) protected function resolveTableNames($table, $name)
@ -142,7 +142,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Resolves the default value for the column. * Resolves the default value for the column.
* @param \yii\db\dao\ColumnSchema $column the column metadata object * @param \yii\db\ColumnSchema $column the column metadata object
* @param string $value the default value fetched from database * @param string $value the default value fetched from database
*/ */
protected function resolveColumnDefault($column, $value) protected function resolveColumnDefault($column, $value)
@ -154,7 +154,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Resolves the abstract data type for the column. * Resolves the abstract data type for the column.
* @param \yii\db\dao\ColumnSchema $column the column metadata object * @param \yii\db\ColumnSchema $column the column metadata object
*/ */
public function resolveColumnType($column) public function resolveColumnType($column)
{ {
@ -196,7 +196,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Collects the metadata of table columns. * Collects the metadata of table columns.
* @param \yii\db\dao\TableSchema $table the table metadata * @param \yii\db\TableSchema $table the table metadata
* @return boolean whether the table exists in the database * @return boolean whether the table exists in the database
*/ */
protected function findColumns($table) protected function findColumns($table)
@ -222,7 +222,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Collects the foreign key column details for the given table. * Collects the foreign key column details for the given table.
* @param \yii\db\dao\TableSchema $table the table metadata * @param \yii\db\TableSchema $table the table metadata
*/ */
protected function findConstraints($table) protected function findConstraints($table)
{ {

4
framework/db/dao/mysql/QueryBuilder.php → framework/db/mysql/QueryBuilder.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao\mysql; namespace yii\db\mysql;
use yii\db\Exception; use yii\db\Exception;
@ -17,7 +17,7 @@ use yii\db\Exception;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class QueryBuilder extends \yii\db\dao\QueryBuilder class QueryBuilder extends \yii\db\QueryBuilder
{ {
/** /**
* @var array mapping from abstract column types (keys) to physical column types (values). * @var array mapping from abstract column types (keys) to physical column types (values).

18
framework/db/dao/sqlite/Driver.php → framework/db/sqlite/Driver.php

@ -7,10 +7,10 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao\sqlite; namespace yii\db\sqlite;
use yii\db\dao\TableSchema; use yii\db\TableSchema;
use yii\db\dao\ColumnSchema; use yii\db\ColumnSchema;
/** /**
* Driver is the class for retrieving metadata from a SQLite (2/3) database. * Driver is the class for retrieving metadata from a SQLite (2/3) database.
@ -18,7 +18,7 @@ use yii\db\dao\ColumnSchema;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Driver extends \yii\db\dao\Driver class Driver extends \yii\db\Driver
{ {
/** /**
* @var array mapping from physical column types (keys) to abstract column types (values) * @var array mapping from physical column types (keys) to abstract column types (values)
@ -76,7 +76,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Loads the metadata for the specified table. * Loads the metadata for the specified table.
* @param string $name table name * @param string $name table name
* @return \yii\db\dao\TableSchema driver dependent table metadata. Null if the table does not exist. * @return \yii\db\TableSchema driver dependent table metadata. Null if the table does not exist.
*/ */
protected function loadTableSchema($name) protected function loadTableSchema($name)
{ {
@ -92,7 +92,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Collects the table column metadata. * Collects the table column metadata.
* @param \yii\db\dao\TableSchema $table the table metadata * @param \yii\db\TableSchema $table the table metadata
* @return boolean whether the table exists in the database * @return boolean whether the table exists in the database
*/ */
protected function findColumns($table) protected function findColumns($table)
@ -120,7 +120,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Collects the foreign key column details for the given table. * Collects the foreign key column details for the given table.
* @param \yii\db\dao\TableSchema $table the table metadata * @param \yii\db\TableSchema $table the table metadata
*/ */
protected function findConstraints($table) protected function findConstraints($table)
{ {
@ -155,7 +155,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Resolves the abstract data type for the column. * Resolves the abstract data type for the column.
* @param \yii\db\dao\ColumnSchema $column the column metadata object * @param \yii\db\ColumnSchema $column the column metadata object
*/ */
public function resolveColumnType($column) public function resolveColumnType($column)
{ {
@ -189,7 +189,7 @@ class Driver extends \yii\db\dao\Driver
/** /**
* Resolves the default value for the column. * Resolves the default value for the column.
* @param \yii\db\dao\ColumnSchema $column the column metadata object * @param \yii\db\ColumnSchema $column the column metadata object
* @param string $value the default value fetched from database * @param string $value the default value fetched from database
*/ */
protected function resolveColumnDefault($column, $value) protected function resolveColumnDefault($column, $value)

4
framework/db/dao/sqlite/QueryBuilder.php → framework/db/sqlite/QueryBuilder.php

@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\db\dao\sqlite; namespace yii\db\sqlite;
use yii\db\Exception; use yii\db\Exception;
@ -17,7 +17,7 @@ use yii\db\Exception;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class QueryBuilder extends \yii\db\dao\QueryBuilder class QueryBuilder extends \yii\db\QueryBuilder
{ {
/** /**
* @var array mapping from abstract column types (keys) to physical column types (values). * @var array mapping from abstract column types (keys) to physical column types (values).

8
framework/logging/DbTarget.php

@ -23,7 +23,7 @@ namespace yii\logging;
class DbTarget extends Target class DbTarget extends Target
{ {
/** /**
* @var string the ID of [[\yii\db\dao\Connection]] application component. * @var string the ID of [[\yii\db\Connection]] application component.
* Defaults to 'db'. Please make sure that your database contains a table * Defaults to 'db'. Please make sure that your database contains a table
* whose name is as specified in [[tableName]] and has the required table structure. * whose name is as specified in [[tableName]] and has the required table structure.
* @see tableName * @see tableName
@ -31,7 +31,7 @@ class DbTarget extends Target
public $connectionID = 'db'; public $connectionID = 'db';
/** /**
* @var string the name of the DB table that stores log messages. Defaults to '{{log}}'. * @var string the name of the DB table that stores log messages. Defaults to '{{log}}'.
* If you are using table prefix 'tbl_' (configured via [[\yii\db\dao\Connection::tablePrefix]]), * If you are using table prefix 'tbl_' (configured via [[\yii\db\Connection::tablePrefix]]),
* it means the DB table would be named as 'tbl_log'. * it means the DB table would be named as 'tbl_log'.
* *
* The DB table must have the following structure: * The DB table must have the following structure:
@ -62,14 +62,14 @@ class DbTarget extends Target
/** /**
* Returns the DB connection used for saving log messages. * Returns the DB connection used for saving log messages.
* @return \yii\db\dao\Connection the DB connection instance * @return \yii\db\Connection the DB connection instance
* @throws \yii\base\Exception if [[connectionID]] does not refer to a valid application component ID. * @throws \yii\base\Exception if [[connectionID]] does not refer to a valid application component ID.
*/ */
public function getDbConnection() public function getDbConnection()
{ {
if ($this->_db === null) { if ($this->_db === null) {
$this->_db = \Yii::$application->getComponent($this->connectionID); $this->_db = \Yii::$application->getComponent($this->connectionID);
if (!$this->_db instanceof \yii\db\dao\Connection) { if (!$this->_db instanceof \yii\db\Connection) {
throw new \yii\base\Exception('DbTarget.connectionID must refer to a valid application component ID'); throw new \yii\base\Exception('DbTarget.connectionID must refer to a valid application component ID');
} }
} }

2
framework/logging/Logger.php

@ -190,7 +190,7 @@ class Logger extends \yii\base\Component
* @param array $categories list of categories that you are interested in. * @param array $categories list of categories that you are interested in.
* You can use an asterisk at the end of a category to do a prefix match. * You can use an asterisk at the end of a category to do a prefix match.
* For example, 'yii\db\*' will match categories starting with 'yii\db\', * For example, 'yii\db\*' will match categories starting with 'yii\db\',
* such as 'yii\db\dao\Connection'. * such as 'yii\db\Connection'.
* @param array $excludeCategories list of categories that you are interested in. * @param array $excludeCategories list of categories that you are interested in.
* @return array the profiling results. Each array element has the following structure: * @return array the profiling results. Each array element has the following structure:
* `array($token, $category, $time)`. * `array($token, $category, $time)`.

4
framework/logging/Target.php

@ -37,7 +37,7 @@ abstract class Target extends \yii\base\Component
* @var array list of message categories that this target is interested in. Defaults to empty, meaning all categories. * @var array list of message categories that this target is interested in. Defaults to empty, meaning all categories.
* You can use an asterisk at the end of a category so that the category may be used to * You can use an asterisk at the end of a category so that the category may be used to
* match those categories sharing the same common prefix. For example, 'yii\db\*' will match * match those categories sharing the same common prefix. For example, 'yii\db\*' will match
* categories starting with 'yii\db\', such as 'yii\db\dao\Connection'. * categories starting with 'yii\db\', such as 'yii\db\Connection'.
*/ */
public $categories = array(); public $categories = array();
/** /**
@ -45,7 +45,7 @@ abstract class Target extends \yii\base\Component
* If this property is not empty, then any category listed here will be excluded from [[categories]]. * If this property is not empty, then any category listed here will be excluded from [[categories]].
* You can use an asterisk at the end of a category so that the category can be used to * You can use an asterisk at the end of a category so that the category can be used to
* match those categories sharing the same common prefix. For example, 'yii\db\*' will match * match those categories sharing the same common prefix. For example, 'yii\db\*' will match
* categories starting with 'yii\db\', such as 'yii\db\dao\Connection'. * categories starting with 'yii\db\', such as 'yii\db\Connection'.
* @see categories * @see categories
*/ */
public $except = array(); public $except = array();

12
framework/validators/ExistValidator.php

@ -21,22 +21,22 @@ namespace yii\validators;
class ExistValidator extends Validator class ExistValidator extends Validator
{ {
/** /**
* @var string the yii\db\ar\ActiveRecord class name or alias of the class * @var string the yii\db\ActiveRecord class name or alias of the class
* that should be used to look for the attribute value being validated. * that should be used to look for the attribute value being validated.
* Defaults to null, meaning using the yii\db\ar\ActiveRecord class of * Defaults to null, meaning using the yii\db\ActiveRecord class of
* the attribute being validated. * the attribute being validated.
* @see attributeName * @see attributeName
*/ */
public $className; public $className;
/** /**
* @var string the yii\db\ar\ActiveRecord class attribute name that should be * @var string the yii\db\ActiveRecord class attribute name that should be
* used to look for the attribute value being validated. Defaults to null, * used to look for the attribute value being validated. Defaults to null,
* meaning using the name of the attribute being validated. * meaning using the name of the attribute being validated.
* @see className * @see className
*/ */
public $attributeName; public $attributeName;
/** /**
* @var \yii\db\dao\BaseQuery additional query criteria. This will be combined * @var \yii\db\BaseQuery additional query criteria. This will be combined
* with the condition that checks if the attribute value exists in the * with the condition that checks if the attribute value exists in the
* corresponding table column. * corresponding table column.
*/ */
@ -51,7 +51,7 @@ class ExistValidator extends Validator
* Validates the attribute of the object. * Validates the attribute of the object.
* If there is any error, the error message is added to the object. * If there is any error, the error message is added to the object.
* *
* @param \yii\db\ar\ActiveRecord $object the object being validated * @param \yii\db\ActiveRecord $object the object being validated
* @param string $attribute the attribute being validated * @param string $attribute the attribute being validated
* *
* @throws \yii\base\Exception if table doesn't have column specified * @throws \yii\base\Exception if table doesn't have column specified
@ -72,7 +72,7 @@ class ExistValidator extends Validator
$finder = $object->find()->where(array($column->name => $value)); $finder = $object->find()->where(array($column->name => $value));
if ($this->query instanceof \yii\db\dao\BaseQuery) { if ($this->query instanceof \yii\db\BaseQuery) {
$finder->mergeWith($this->query); $finder->mergeWith($this->query);
} }

6
framework/validators/UniqueValidator.php

@ -28,7 +28,7 @@ class UniqueValidator extends Validator
*/ */
public $allowEmpty = true; public $allowEmpty = true;
/** /**
* @var string the yii\db\ar\ActiveRecord class name or alias of the class * @var string the yii\db\ActiveRecord class name or alias of the class
* that should be used to look for the attribute value being validated. * that should be used to look for the attribute value being validated.
* Defaults to null, meaning using the class of the object currently * Defaults to null, meaning using the class of the object currently
* being validated. * being validated.
@ -43,7 +43,7 @@ class UniqueValidator extends Validator
*/ */
public $attributeName; public $attributeName;
/** /**
* @var \yii\db\ar\ActiveQuery additional query criteria. This will be * @var \yii\db\ActiveQuery additional query criteria. This will be
* combined with the condition that checks if the attribute value exists * combined with the condition that checks if the attribute value exists
* in the corresponding table column. * in the corresponding table column.
*/ */
@ -87,7 +87,7 @@ class UniqueValidator extends Validator
$finder->where($this->caseSensitive ? "{$column->quotedName}=:value" : "LOWER({$column->quotedName})=LOWER(:value)"); $finder->where($this->caseSensitive ? "{$column->quotedName}=:value" : "LOWER({$column->quotedName})=LOWER(:value)");
$finder->params(array(':value' => $value)); $finder->params(array(':value' => $value));
if ($this->query instanceof \yii\db\dao\BaseQuery) { if ($this->query instanceof \yii\db\BaseQuery) {
$finder->mergeWith($this->query); $finder->mergeWith($this->query);
} }

4
tests/unit/MysqlTestCase.php

@ -13,12 +13,12 @@ class MysqlTestCase extends TestCase
/** /**
* @param bool $reset whether to clean up the test database * @param bool $reset whether to clean up the test database
* @return \yii\db\dao\Connection * @return \yii\db\Connection
*/ */
function getConnection($reset = true) function getConnection($reset = true)
{ {
$params = $this->getParam('mysql'); $params = $this->getParam('mysql');
$db = new \yii\db\dao\Connection; $db = new \yii\db\Connection;
$db->dsn = $params['dsn']; $db->dsn = $params['dsn'];
$db->username = $params['username']; $db->username = $params['username'];
$db->password = $params['password']; $db->password = $params['password'];

4
tests/unit/data/ar/ActiveRecord.php

@ -9,7 +9,7 @@
namespace yiiunit\data\ar; namespace yiiunit\data\ar;
use yii\db\dao\Connection; use yii\db\Connection;
/** /**
* ActiveRecord is ... * ActiveRecord is ...
@ -17,7 +17,7 @@ use yii\db\dao\Connection;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class ActiveRecord extends \yii\db\ar\ActiveRecord class ActiveRecord extends \yii\db\ActiveRecord
{ {
public static $db; public static $db;

2
tests/unit/data/ar/Customer.php

@ -1,7 +1,7 @@
<?php <?php
namespace yiiunit\data\ar; namespace yiiunit\data\ar;
use yii\db\ar\ActiveQuery; use yii\db\ActiveQuery;
class Customer extends ActiveRecord class Customer extends ActiveRecord
{ {

4
tests/unit/framework/db/ar/ActiveRecordTest.php

@ -2,8 +2,8 @@
namespace yiiunit\framework\db\ar; namespace yiiunit\framework\db\ar;
use yii\db\dao\Query; use yii\db\Query;
use yii\db\ar\ActiveQuery; use yii\db\ActiveQuery;
use yiiunit\data\ar\ActiveRecord; use yiiunit\data\ar\ActiveRecord;
use yiiunit\data\ar\Customer; use yiiunit\data\ar\Customer;
use yiiunit\data\ar\OrderItem; use yiiunit\data\ar\OrderItem;

8
tests/unit/framework/db/dao/CommandTest.php

@ -2,10 +2,10 @@
namespace yiiunit\framework\db\dao; namespace yiiunit\framework\db\dao;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Command; use yii\db\Command;
use yii\db\dao\Query; use yii\db\Query;
use yii\db\dao\DataReader; use yii\db\DataReader;
class CommandTest extends \yiiunit\MysqlTestCase class CommandTest extends \yiiunit\MysqlTestCase
{ {

2
tests/unit/framework/db/dao/ConnectionTest.php

@ -2,7 +2,7 @@
namespace yiiunit\framework\db\dao; namespace yiiunit\framework\db\dao;
use yii\db\dao\Connection; use yii\db\Connection;
class ConnectionTest extends \yiiunit\MysqlTestCase class ConnectionTest extends \yiiunit\MysqlTestCase
{ {

8
tests/unit/framework/db/dao/QueryTest.php

@ -2,10 +2,10 @@
namespace yiiunit\framework\db\dao; namespace yiiunit\framework\db\dao;
use yii\db\dao\Connection; use yii\db\Connection;
use yii\db\dao\Command; use yii\db\Command;
use yii\db\dao\Query; use yii\db\Query;
use yii\db\dao\DataReader; use yii\db\DataReader;
class QueryTest extends \yiiunit\MysqlTestCase class QueryTest extends \yiiunit\MysqlTestCase
{ {

4
upgrade.md

@ -40,7 +40,7 @@ Upgrading from v1.1.x
- `CFormModel` is removed. Please use `yii\base\Model` instead. - `CFormModel` is removed. Please use `yii\base\Model` instead.
- `CDbCriteria` is replaced by `yii\db\dao\Query` which includes methods for - `CDbCriteria` is replaced by `yii\db\Query` which includes methods for
building a query. `CDbCommandBuilder` is replaced by `yii\db\dao\QueryBuilder` building a query. `CDbCommandBuilder` is replaced by `yii\db\QueryBuilder`
which has cleaner and more complete support of query building capabilities. which has cleaner and more complete support of query building capabilities.

Loading…
Cancel
Save