Browse Source

Merge pull request #2922 from yiisoft/remove-tbl-prefix

Fixes #2911: Removed `tbl_` default for table prefix
tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
5e7d76058d
  1. 0
      apps/advanced/common/tests/templates/fixtures/user.php
  2. 4
      apps/advanced/console/migrations/m130524_201442_init.php
  3. 0
      apps/advanced/frontend/tests/unit/fixtures/data/user.php
  4. 2
      apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php
  5. 2
      apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php
  6. 4
      apps/basic/tests/unit/models/UserTest.php
  7. 66
      docs/guide/active-record.md
  8. 18
      docs/guide/console-migrate.md
  9. 8
      docs/guide/data-providers.md
  10. 24
      docs/guide/database-basics.md
  11. 40
      docs/guide/query-builder.md
  12. 2
      docs/guide/test-fixture.md
  13. 2
      docs/guide/upgrade-from-v1.md
  14. 2
      extensions/faker/FixtureController.php
  15. 2
      extensions/faker/README.md
  16. 4
      extensions/gii/generators/model/Generator.php
  17. 2
      extensions/sphinx/Command.php
  18. 1
      framework/CHANGELOG.md
  19. 4
      framework/caching/DbCache.php
  20. 2
      framework/console/controllers/MigrateController.php
  21. 2
      framework/data/ActiveDataProvider.php
  22. 2
      framework/data/ArrayDataProvider.php
  23. 4
      framework/data/SqlDataProvider.php
  24. 4
      framework/db/ActiveQuery.php
  25. 12
      framework/db/ActiveRecord.php
  26. 2
      framework/db/BatchQueryResult.php
  27. 12
      framework/db/Command.php
  28. 8
      framework/db/Connection.php
  29. 2
      framework/db/DataReader.php
  30. 30
      framework/db/Query.php
  31. 10
      framework/db/QueryBuilder.php
  32. 2
      framework/db/sqlite/QueryBuilder.php
  33. 8
      framework/i18n/DbMessageSource.php
  34. 4
      framework/log/DbTarget.php
  35. 6
      framework/rbac/DbManager.php
  36. 18
      framework/rbac/schema-mssql.sql
  37. 18
      framework/rbac/schema-mysql.sql
  38. 18
      framework/rbac/schema-oci.sql
  39. 20
      framework/rbac/schema-pgsql.sql
  40. 18
      framework/rbac/schema-sqlite.sql
  41. 4
      framework/web/DbSession.php
  42. 2
      tests/unit/data/ar/Category.php
  43. 6
      tests/unit/data/ar/Customer.php
  44. 2
      tests/unit/data/ar/Item.php
  45. 2
      tests/unit/data/ar/NullValues.php
  46. 6
      tests/unit/data/ar/Order.php
  47. 2
      tests/unit/data/ar/OrderItem.php
  48. 2
      tests/unit/data/ar/Profile.php
  49. 4
      tests/unit/data/ar/Type.php
  50. 2
      tests/unit/data/ar/elasticsearch/Order.php
  51. 94
      tests/unit/data/cubrid.sql
  52. 74
      tests/unit/data/mssql.sql
  53. 122
      tests/unit/data/mysql.sql
  54. 118
      tests/unit/data/postgres.sql
  55. 118
      tests/unit/data/sqlite.sql
  56. 2
      tests/unit/data/validators/models/ValidatorTestMainModel.php
  57. 2
      tests/unit/data/validators/models/ValidatorTestRefModel.php
  58. 4
      tests/unit/extensions/elasticsearch/ActiveRecordTest.php
  59. 4
      tests/unit/extensions/redis/ActiveRecordTest.php
  60. 4
      tests/unit/extensions/sphinx/QueryTest.php
  61. 2
      tests/unit/framework/caching/DbCacheTest.php
  62. 8
      tests/unit/framework/data/ActiveDataProviderTest.php
  63. 50
      tests/unit/framework/db/ActiveRecordTest.php
  64. 12
      tests/unit/framework/db/BatchQueryResultTest.php
  65. 58
      tests/unit/framework/db/CommandTest.php
  66. 2
      tests/unit/framework/db/QueryBuilderTest.php
  67. 8
      tests/unit/framework/db/QueryTest.php
  68. 20
      tests/unit/framework/db/SchemaTest.php
  69. 16
      tests/unit/framework/db/cubrid/CubridCommandTest.php
  70. 16
      tests/unit/framework/db/mssql/MssqlCommandTest.php
  71. 4
      tests/unit/framework/db/sqlite/SqliteCommandTest.php
  72. 4
      tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php
  73. 0
      tests/unit/framework/test/data/customer.php

0
apps/advanced/common/tests/templates/fixtures/tbl_user.php → apps/advanced/common/tests/templates/fixtures/user.php

4
apps/advanced/console/migrations/m130524_201442_init.php

@ -11,7 +11,7 @@ class m130524_201442_init extends \yii\db\Migration
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable('tbl_user', [
$this->createTable('user', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING . ' NOT NULL',
'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
@ -28,6 +28,6 @@ class m130524_201442_init extends \yii\db\Migration
public function down()
{
$this->dropTable('tbl_user');
$this->dropTable('user');
}
}

0
apps/advanced/frontend/tests/unit/fixtures/data/tbl_user.php → apps/advanced/frontend/tests/unit/fixtures/data/user.php

2
apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php

@ -66,7 +66,7 @@ class PasswordResetRequestFormTest extends DbTestCase
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/tbl_user.php'
'dataFile' => '@frontend/tests/unit/fixtures/data/user.php'
],
];
}

2
apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php

@ -29,7 +29,7 @@ class ResetPasswordFormTest extends DbTestCase
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/tbl_user.php'
'dataFile' => '@frontend/tests/unit/fixtures/data/user.php'
],
];
}

4
apps/basic/tests/unit/models/UserTest.php

@ -9,8 +9,8 @@ class UserTest extends TestCase
protected function setUp()
{
parent::setUp();
// uncomment the following to load fixtures for table tbl_user
//$this->loadFixtures(['tbl_user']);
// uncomment the following to load fixtures for user table
//$this->loadFixtures(['user']);
}
// TODO add test methods here

66
docs/guide/active-record.md

@ -7,9 +7,9 @@ an Active Record instance corresponds to a row of that table, and an attribute o
instance represents the value of a column in that row. Instead of writing raw SQL statements,
you can work with Active Record in an object-oriented fashion to manipulate the data in database tables.
For example, assume `Customer` is an Active Record class is associated with the `tbl_customer` table
and `name` is a column of `tbl_customer`. You can write the following code to insert a new
row into `tbl_customer`:
For example, assume `Customer` is an Active Record class is associated with the `customer` table
and `name` is a column of `customer` table. You can write the following code to insert a new
row into `customer` table:
```php
$customer = new Customer();
@ -21,7 +21,7 @@ The above code is equivalent to using the following raw SQL statement, which is
intuitive, more error prone, and may have compatibility problem for different DBMS:
```php
$db->createCommand('INSERT INTO tbl_customer (name) VALUES (:name)', [
$db->createCommand('INSERT INTO customer (name) VALUES (:name)', [
':name' => 'Qiang',
])->execute();
```
@ -45,7 +45,7 @@ class Customer extends ActiveRecord
*/
public static function tableName()
{
return 'tbl_customer';
return 'customer';
}
}
```
@ -144,7 +144,7 @@ $customers = Customer::find()->indexBy('id')->all();
// $customers array is indexed by customer IDs
// to retrieve customers using a raw SQL statement:
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$customers = Customer::findBySql($sql)->all();
```
@ -332,8 +332,8 @@ $orders = $customer->orders; // $orders is an array of Order objects
Behind the scene, the above code executes the following two SQL queries, one for each line of code:
```sql
SELECT * FROM tbl_customer WHERE id=1;
SELECT * FROM tbl_order WHERE customer_id=1;
SELECT * FROM customer WHERE id=1;
SELECT * FROM order WHERE customer_id=1;
```
> Tip: If you access the expression `$customer->orders` again, it will not perform the second SQL query again.
@ -381,7 +381,7 @@ Sometimes, two tables are related together via an intermediary table called [piv
we can customize the [[yii\db\ActiveQuery]] object by calling its [[yii\db\ActiveQuery::via()|via()]] or
[[yii\db\ActiveQuery::viaTable()|viaTable()]] method.
For example, if table `tbl_order` and table `tbl_item` are related via pivot table `tbl_order_item`,
For example, if table `order` and table `item` are related via pivot table `order_item`,
we can declare the `items` relation in the `Order` class like the following:
```php
@ -390,7 +390,7 @@ class Order extends \yii\db\ActiveRecord
public function getItems()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->viaTable('tbl_order_item', ['order_id' => 'id']);
->viaTable('order_item', ['order_id' => 'id']);
}
}
```
@ -426,9 +426,9 @@ to retrieve the corresponding data and populate it into the related objects. No
if you access the same related objects again. We call this *lazy loading*. For example,
```php
// SQL executed: SELECT * FROM tbl_customer WHERE id=1
// SQL executed: SELECT * FROM customer WHERE id=1
$customer = Customer::find(1);
// SQL executed: SELECT * FROM tbl_order WHERE customer_id=1
// SQL executed: SELECT * FROM order WHERE customer_id=1
$orders = $customer->orders;
// no SQL executed
$orders2 = $customer->orders;
@ -437,11 +437,11 @@ $orders2 = $customer->orders;
Lazy loading is very convenient to use. However, it may suffer from a performance issue in the following scenario:
```php
// SQL executed: SELECT * FROM tbl_customer LIMIT 100
// SQL executed: SELECT * FROM customer LIMIT 100
$customers = Customer::find()->limit(100)->all();
foreach ($customers as $customer) {
// SQL executed: SELECT * FROM tbl_order WHERE customer_id=...
// SQL executed: SELECT * FROM order WHERE customer_id=...
$orders = $customer->orders;
// ...handle $orders...
}
@ -454,8 +454,8 @@ is performed to bring back the orders of that customer.
To solve the above performance problem, you can use the so-called *eager loading* approach by calling [[yii\db\ActiveQuery::with()]]:
```php
// SQL executed: SELECT * FROM tbl_customer LIMIT 100;
// SELECT * FROM tbl_orders WHERE customer_id IN (1,2,...)
// SQL executed: SELECT * FROM customer LIMIT 100;
// SELECT * FROM orders WHERE customer_id IN (1,2,...)
$customers = Customer::find()->limit(100)
->with('orders')->all();
@ -486,11 +486,11 @@ done for both lazy loading and eager loading. For example,
```php
$customer = Customer::find(1);
// lazy loading: SELECT * FROM tbl_order WHERE customer_id=1 AND subtotal>100
// lazy loading: SELECT * FROM order WHERE customer_id=1 AND subtotal>100
$orders = $customer->getOrders()->where('subtotal>100')->all();
// eager loading: SELECT * FROM tbl_customer LIMIT 100
// SELECT * FROM tbl_order WHERE customer_id IN (1,2,...) AND subtotal>100
// eager loading: SELECT * FROM customer LIMIT 100
// SELECT * FROM order WHERE customer_id IN (1,2,...) AND subtotal>100
$customers = Customer::find()->limit(100)->with([
'orders' => function($query) {
$query->andWhere('subtotal>100');
@ -530,11 +530,11 @@ that finds those orders, and accessing `customer->orders` will trigger one SQL e
the `customer` of an order will trigger another SQL execution:
```php
// SELECT * FROM tbl_customer WHERE id=1
// SELECT * FROM customer WHERE id=1
$customer = Customer::find(1);
// echoes "not equal"
// SELECT * FROM tbl_order WHERE customer_id=1
// SELECT * FROM tbl_customer WHERE id=1
// SELECT * FROM order WHERE customer_id=1
// SELECT * FROM customer WHERE id=1
if ($customer->orders[0]->customer === $customer) {
echo 'equal';
} else {
@ -559,10 +559,10 @@ class Customer extends ActiveRecord
Now if we execute the same query as shown above, we would get:
```php
// SELECT * FROM tbl_customer WHERE id=1
// SELECT * FROM customer WHERE id=1
$customer = Customer::find(1);
// echoes "equal"
// SELECT * FROM tbl_order WHERE customer_id=1
// SELECT * FROM order WHERE customer_id=1
if ($customer->orders[0]->customer === $customer) {
echo 'equal';
} else {
@ -574,8 +574,8 @@ In the above, we have shown how to use inverse relations in lazy loading. Invers
eager loading:
```php
// SELECT * FROM tbl_customer
// SELECT * FROM tbl_order WHERE customer_id IN (1, 2, ...)
// SELECT * FROM customer
// SELECT * FROM order WHERE customer_id IN (1, 2, ...)
$customers = Customer::find()->with('orders')->all();
// echoes "equal"
if ($customers[0]->orders[0]->customer === $customers[0]) {
@ -600,7 +600,7 @@ explicitly to build up the JOIN query, you may reuse the existing relation defin
```php
// find all orders and sort the orders by the customer id and the order id. also eager loading "customer"
$orders = Order::find()->joinWith('customer')->orderBy('tbl_customer.id, tbl_order.id')->all();
$orders = Order::find()->joinWith('customer')->orderBy('customer.id, order.id')->all();
// find all orders that contain books, and eager loading "books"
$orders = Order::find()->innerJoinWith('books')->all();
```
@ -617,7 +617,7 @@ and you may also join with sub-relations. For example,
$orders = Order::find()->innerJoinWith([
'books',
'customer' => function ($query) {
$query->where('tbl_customer.created_at > ' . (time() - 24 * 3600));
$query->where('customer.created_at > ' . (time() - 24 * 3600));
}
])->all();
// join with sub-relations: join with books and books' authors
@ -638,7 +638,7 @@ For example, you may filter the primary models by the conditions on the related
above. You may also sort the primary models using columns from the related tables.
When using [[yii\db\ActiveQuery::joinWith()|joinWith()]], you are responsible to disambiguate column names.
In the above examples, we use `tbl_item.id` and `tbl_order.id` to disambiguate the `id` column references
In the above examples, we use `item.id` and `order.id` to disambiguate the `id` column references
because both of the order table and the item table contain a column named `id`.
By default, when you join with a relation, the relation will also be eagerly loaded. You may change this behavior
@ -678,8 +678,8 @@ When you perform query using [[yii\db\ActiveQuery::joinWith()|joinWith()]], the
of the corresponding JOIN query. For example,
```php
// SELECT tbl_user.* FROM tbl_user LEFT JOIN tbl_item ON tbl_item.owner_id=tbl_user.id AND category_id=1
// SELECT * FROM tbl_item WHERE owner_id IN (...) AND category_id=1
// SELECT user.* FROM user LEFT JOIN item ON item.owner_id=user.id AND category_id=1
// SELECT * FROM item WHERE owner_id IN (...) AND category_id=1
$users = User::find()->joinWith('books')->all();
```
@ -687,9 +687,9 @@ Note that if you use eager loading via [[yii\db\ActiveQuery::with()]] or lazy lo
in the WHERE part of the corresponding SQL statement, because there is no JOIN query involved. For example,
```php
// SELECT * FROM tbl_user WHERE id=10
// SELECT * FROM user WHERE id=10
$user = User::find(10);
// SELECT * FROM tbl_item WHERE owner_id=10 AND category_id=1
// SELECT * FROM item WHERE owner_id=10 AND category_id=1
$books = $user->books;
```

18
docs/guide/console-migrate.md

@ -80,7 +80,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{
public function up()
{
$this->createTable('tbl_news', [
$this->createTable('news', [
'id' => 'pk',
'title' => Schema::TYPE_STRING . ' NOT NULL',
'content' => Schema::TYPE_TEXT,
@ -89,7 +89,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public function down()
{
$this->dropTable('tbl_news');
$this->dropTable('news');
}
}
@ -124,13 +124,13 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{
public function safeUp()
{
$this->createTable('tbl_news', [
$this->createTable('news', [
'id' => 'pk',
'title' => Schema::TYPE_STRING . ' NOT NULL',
'content' => Schema::TYPE_TEXT,
]);
$this->createTable('tbl_user', [
$this->createTable('user', [
'id' => 'pk',
'login' => Schema::TYPE_STRING . ' NOT NULL',
'password' => Schema::TYPE_STRING . ' NOT NULL',
@ -139,8 +139,8 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public function safeDown()
{
$this->dropTable('tbl_news');
$this->dropTable('tbl_user');
$this->dropTable('news');
$this->dropTable('user');
}
}
@ -169,8 +169,8 @@ the migrations, it will run the `up()` method in every new migration class, one
after another, in the order of the timestamp value in the class name.
After applying a migration, the migration tool will keep a record in a database
table named `tbl_migration`. This allows the tool to identify which migrations
have been applied and which are not. If the `tbl_migration` table does not exist,
table named `migration`. This allows the tool to identify which migrations
have been applied and which are not. If the `migration` table does not exist,
the tool will automatically create it in the database specified by the `db`
application component.
@ -284,7 +284,7 @@ line:
sub-directory under the application base path.
* `migrationTable`: string, specifies the name of the database table for storing
migration history information. It defaults to `tbl_migration`. The table
migration history information. It defaults to `migration`. The table
structure is `version varchar(255) primary key, apply_time integer`.
* `connectionID`: string, specifies the ID of the database application component.

8
docs/guide/data-providers.md

@ -31,7 +31,7 @@ And the following example shows how to use ActiveDataProvider without ActiveReco
```php
$query = new Query();
$provider = new ActiveDataProvider([
'query' => $query->from('tbl_post'),
'query' => $query->from('post'),
'pagination' => [
'pageSize' => 20,
],
@ -64,7 +64,7 @@ ArrayDataProvider may be used in the following way:
```php
$query = new Query();
$provider = new ArrayDataProvider([
'allModels' => $query->from('tbl_post')->all(),
'allModels' => $query->from('post')->all(),
'sort' => [
'attributes' => ['id', 'username', 'email'],
],
@ -94,11 +94,11 @@ and pagination behaviors.
```php
$count = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM tbl_user WHERE status=:status
SELECT COUNT(*) FROM user WHERE status=:status
', [':status' => 1])->queryScalar();
$dataProvider = new SqlDataProvider([
'sql' => 'SELECT * FROM tbl_user WHERE status=:status',
'sql' => 'SELECT * FROM user WHERE status=:status',
'params' => [':status' => 1],
'totalCount' => $count,
'sort' => [

24
docs/guide/database-basics.md

@ -103,28 +103,28 @@ Once you have a connection instance you can execute SQL queries using [[yii\db\C
When query returns a set of rows:
```php
$command = $connection->createCommand('SELECT * FROM tbl_post');
$command = $connection->createCommand('SELECT * FROM post');
$posts = $command->queryAll();
```
When only a single row is returned:
```php
$command = $connection->createCommand('SELECT * FROM tbl_post WHERE id=1');
$command = $connection->createCommand('SELECT * FROM post WHERE id=1');
$post = $command->queryOne();
```
When there are multiple values from the same column:
```php
$command = $connection->createCommand('SELECT title FROM tbl_post');
$command = $connection->createCommand('SELECT title FROM post');
$titles = $command->queryColumn();
```
When there's a scalar value:
```php
$command = $connection->createCommand('SELECT COUNT(*) FROM tbl_post');
$command = $connection->createCommand('SELECT COUNT(*) FROM post');
$postCount = $command->queryScalar();
```
@ -133,7 +133,7 @@ $postCount = $command->queryScalar();
If SQL executed doesn't return any data you can use command's `execute` method:
```php
$command = $connection->createCommand('UPDATE tbl_post SET status=1 WHERE id=1');
$command = $connection->createCommand('UPDATE post SET status=1 WHERE id=1');
$command->execute();
```
@ -141,23 +141,23 @@ Alternatively the following syntax that takes care of proper table and column na
```php
// INSERT
$connection->createCommand()->insert('tbl_user', [
$connection->createCommand()->insert('user', [
'name' => 'Sam',
'age' => 30,
])->execute();
// INSERT multiple rows at once
$connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [
$connection->createCommand()->batchInsert('user', ['name', 'age'], [
['Tom', 30],
['Jane', 20],
['Linda', 25],
])->execute();
// UPDATE
$connection->createCommand()->update('tbl_user', ['status' => 1], 'age > 30')->execute();
$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
// DELETE
$connection->createCommand()->delete('tbl_user', 'status = 0')->execute();
$connection->createCommand()->delete('user', 'status = 0')->execute();
```
Quoting table and column names
@ -189,7 +189,7 @@ Prepared statements
In order to securely pass query parameters you can use prepared statements:
```php
$command = $connection->createCommand('SELECT * FROM tbl_post WHERE id=:id');
$command = $connection->createCommand('SELECT * FROM post WHERE id=:id');
$command->bindValue(':id', $_GET['id']);
$post = $command->query();
```
@ -197,7 +197,7 @@ $post = $command->query();
Another usage is performing a query multiple times while preparing it only once:
```php
$command = $connection->createCommand('DELETE FROM tbl_post WHERE id=:id');
$command = $connection->createCommand('DELETE FROM post WHERE id=:id');
$command->bindParam(':id', $id);
$id = 1;
@ -281,7 +281,7 @@ These can be used as follows:
```php
// CREATE TABLE
$connection->createCommand()->createTable('tbl_post', [
$connection->createCommand()->createTable('post', [
'id' => 'pk',
'title' => 'string',
'text' => 'text',

40
docs/guide/query-builder.md

@ -11,7 +11,7 @@ A typical usage of the query builder looks like the following:
```php
$rows = (new \yii\db\Query())
->select('id, name')
->from('tbl_user')
->from('user')
->limit(10)
->all();
@ -19,7 +19,7 @@ $rows = (new \yii\db\Query())
$query = (new \yii\db\Query())
->select('id, name')
->from('tbl_user')
->from('user')
->limit(10);
// Create a command. You can get the actual SQL using $command->sql
@ -62,7 +62,7 @@ In order to form a basic `SELECT` query, you need to specify what columns to sel
```php
$query->select('id, name')
->from('tbl_user');
->from('user');
```
Select options can be specified as a comma-separated string, as in the above, or as an array.
@ -70,7 +70,7 @@ The array syntax is especially useful when forming the selection dynamically:
```php
$query->select(['id', 'name'])
->from('tbl_user');
->from('user');
```
> Info: You should always use the array format if your `SELECT` clause contains SQL expressions.
@ -78,14 +78,14 @@ $query->select(['id', 'name'])
> If you list it together with other columns in a string, the expression may be split into several parts
> by commas, which is not what you want to see.
When specifying columns, you may include the table prefixes or column aliases, e.g., `tbl_user.id`, `tbl_user.id AS user_id`.
When specifying columns, you may include the table prefixes or column aliases, e.g., `user.id`, `user.id AS user_id`.
If you are using array to specify the columns, you may also use the array keys to specify the column aliases,
e.g., `['user_id' => 'tbl_user.id', 'user_name' => 'tbl_user.name']`.
e.g., `['user_id' => 'user.id', 'user_name' => 'user.name']`.
To select distinct rows, you may call `distinct()`, like the following:
```php
$query->select('user_id')->distinct()->from('tbl_post');
$query->select('user_id')->distinct()->from('post');
```
### `FROM`
@ -93,30 +93,30 @@ $query->select('user_id')->distinct()->from('tbl_post');
To specify which table(s) to select data from, call `from()`:
```php
$query->select('*')->from('tbl_user');
$query->select('*')->from('user');
```
You may specify multiple tables using a comma-separated string or an array.
Table names can contain schema prefixes (e.g. `'public.tbl_user'`) and/or table aliases (e.g. `'tbl_user u'`).
Table names can contain schema prefixes (e.g. `'public.user'`) and/or table aliases (e.g. `'user u'`).
The method will automatically quote the table names unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression). For example,
```php
$query->select('u.*, p.*')->from(['tbl_user u', 'tbl_post p']);
$query->select('u.*, p.*')->from(['user u', 'post p']);
```
When the tables are specified as an array, you may also use the array keys as the table aliases
(if a table does not need alias, do not use a string key). For example,
```php
$query->select('u.*, p.*')->from(['u' => 'tbl_user u', 'p' => 'tbl_post']);
$query->select('u.*, p.*')->from(['u' => 'user u', 'p' => 'post']);
```
You may specify a sub-query using a `Query` object. In this case, the corresponding array key will be used
as the alias for the sub-query.
```php
$subQuery = (new Query())->select('id')->from('tbl_user')->where('status=1');
$subQuery = (new Query())->select('id')->from('user')->where('status=1');
$query->select('*')->from(['u' => $subQuery]);
```
@ -293,9 +293,9 @@ The `JOIN` clauses are generated in the Query Builder by using the applicable jo
This left join selects data from two related tables in one query:
```php
$query->select(['tbl_user.name AS author', 'tbl_post.title as title'])
->from('tbl_user')
->leftJoin('tbl_post', 'tbl_post.user_id = tbl_user.id');
$query->select(['user.name AS author', 'post.title as title'])
->from('user')
->leftJoin('post', 'post.user_id = user.id');
```
In the code, the `leftJoin()` method's first parameter
@ -304,7 +304,7 @@ specifies the table to join to. The second parameter defines the join condition.
If your database application supports other join types, you can use those via the generic `join` method:
```php
$query->join('FULL OUTER JOIN', 'tbl_post', 'tbl_post.user_id = tbl_user.id');
$query->join('FULL OUTER JOIN', 'post', 'post.user_id = user.id');
```
The first argument is the join type to perform. The second is the table to join to, and the third is the condition.
@ -325,10 +325,10 @@ In Yii in order to build it you can first form two query objects and then use `u
```php
$query = new Query();
$query->select("id, 'post' as type, name")->from('tbl_post')->limit(10);
$query->select("id, 'post' as type, name")->from('post')->limit(10);
$anotherQuery = new Query();
$anotherQuery->select('id, 'user' as type, name')->from('tbl_user')->limit(10);
$anotherQuery->select('id, 'user' as type, name')->from('user')->limit(10);
$query->union($anotherQuery);
```
@ -348,7 +348,7 @@ Batch query can be used like the following:
use yii\db\Query;
$query = (new Query())
->from('tbl_user')
->from('user')
->orderBy('id');
foreach ($query->batch() as $users) {
@ -377,7 +377,7 @@ will still keep the proper index. For example,
use yii\db\Query;
$query = (new Query())
->from('tbl_user')
->from('user')
->indexBy('username');
foreach ($query->batch() as $users) {

2
docs/guide/test-fixture.md

@ -44,7 +44,7 @@ class UserFixture extends ActiveFixture
The fixture data for an `ActiveFixture` fixture is usually provided in a file located at `FixturePath/data/TableName.php`,
where `FixturePath` stands for the directory containing the fixture class file, and `TableName`
is the name of the table associated with the fixture. In the example above, the file should be
`@app/tests/fixtures/data/tbl_user.php`. The data file should return an array of data rows
`@app/tests/fixtures/data/user.php`. The data file should return an array of data rows
to be inserted into the user table. For example,
```php

2
docs/guide/upgrade-from-v1.md

@ -396,7 +396,7 @@ and [[yii\db\QueryBuilder|QueryBuilder]] to generate SQL statements from query o
```php
$query = new \yii\db\Query();
$query->select('id, name')
->from('tbl_user')
->from('user')
->limit(10);
$command = $query->createCommand();

2
extensions/faker/FixtureController.php

@ -52,7 +52,7 @@ use yii\helpers\FileHelper;
*
* - `$fixture` - current fixture array.
* - `$faker` - faker generator instance
* - `$index` - current fixture index. For example if user need to generate 3 fixtures for tbl_user, it will be 0..2
* - `$index` - current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2
*
* After you set all needed fields in callback, you need to return $fixture array back from the callback.
*

2
extensions/faker/README.md

@ -62,7 +62,7 @@ If you use callback as a attribute value, then it will be called as shown with t
* ```$fixture``` - current fixture array.
* ```$faker``` - faker generator instance
* ```$index``` - current fixture index. For example if user need to generate 3 fixtures for tbl_user, it will be 0..2.
* ```$index``` - current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2.
After you set all needed fields in callback, you need to return $fixture array back from the callback.

4
extensions/gii/generators/model/Generator.php

@ -93,8 +93,8 @@ class Generator extends \yii\gii\Generator
return array_merge(parent::hints(), [
'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>',
'db' => 'This is the ID of the DB application component.',
'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>tbl_post</code>.
The table name may consist of the DB schema part if needed, e.g. <code>public.tbl_post</code>.
'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>post</code>.
The table name may consist of the DB schema part if needed, e.g. <code>public.post</code>.
The table name may end with asterisk to match multiple table names, e.g. <code>tbl_*</code>
will match tables who name starts with <code>tbl_</code>. In this case, multiple ActiveRecord classes
will be generated, one for each matching table name; and the class names will be generated from

2
extensions/sphinx/Command.php

@ -135,7 +135,7 @@ class Command extends \yii\db\Command
* For example,
*
* ~~~
* $connection->createCommand()->update('tbl_user', ['status' => 1], 'age > 30')->execute();
* $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
* ~~~
*
* The method will properly escape the column names and bind the values to be updated.

1
framework/CHANGELOG.md

@ -232,6 +232,7 @@ Yii Framework 2 Change Log
- Removed `yii\web\Controller::getCanonicalUrl`, use `yii\helpers\Url::canonical` instead.
- Chg #2691: Null parameters will not be included in the generated URLs by `UrlManager` (gonimar, qiangxue)
- Chg #2734: `FileCache::keyPrefix` defaults to empty string now (qiangxue)
- Chg #2911: Removed `tbl_` default for table prefix (samdark)
_ Chg #2912: Relative view files will be looked for under the directory containing the view currently being rendered (qiangxue)
- Chg: Renamed `yii\jui\Widget::clientEventsMap` to `clientEventMap` (qiangxue)
- Chg: Renamed `ActiveRecord::getPopulatedRelations()` to `getRelatedRecords()` (qiangxue)

4
framework/caching/DbCache.php

@ -16,7 +16,7 @@ use yii\di\Instance;
/**
* DbCache implements a cache application component by storing cached data in a database.
*
* By default, DbCache stores session data in a DB table named 'tbl_cache'. This table
* By default, DbCache stores session data in a DB table named 'cache'. This table
* must be pre-created. The table name can be changed by setting [[cacheTable]].
*
* Please refer to [[Cache]] for common cache operations that are supported by DbCache.
@ -47,7 +47,7 @@ class DbCache extends Cache
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE tbl_cache (
* CREATE TABLE cache (
* id char(128) NOT NULL PRIMARY KEY,
* expire int(11),
* data BLOB

2
framework/console/controllers/MigrateController.php

@ -33,7 +33,7 @@ use yii\helpers\FileHelper;
* create it as follows:
*
* ~~~
* CREATE TABLE tbl_migration (
* CREATE TABLE migration (
* version varchar(180) PRIMARY KEY,
* apply_time integer
* )

2
framework/data/ActiveDataProvider.php

@ -39,7 +39,7 @@ use yii\di\Instance;
* ~~~
* $query = new Query;
* $provider = new ActiveDataProvider([
* 'query' => $query->from('tbl_post'),
* 'query' => $query->from('post'),
* 'pagination' => [
* 'pageSize' => 20,
* ],

2
framework/data/ArrayDataProvider.php

@ -30,7 +30,7 @@ use yii\helpers\ArrayHelper;
* ~~~
* $query = new Query;
* $provider = new ArrayDataProvider([
* 'allModels' => $query->from('tbl_post')->all(),
* 'allModels' => $query->from('post')->all(),
* 'sort' => [
* 'attributes' => ['id', 'username', 'email'],
* ],

4
framework/data/SqlDataProvider.php

@ -26,11 +26,11 @@ use yii\di\Instance;
*
* ~~~
* $count = Yii::$app->db->createCommand('
* SELECT COUNT(*) FROM tbl_user WHERE status=:status
* SELECT COUNT(*) FROM user WHERE status=:status
* ', [':status' => 1])->queryScalar();
*
* $dataProvider = new SqlDataProvider([
* 'sql' => 'SELECT * FROM tbl_user WHERE status=:status',
* 'sql' => 'SELECT * FROM user WHERE status=:status',
* 'params' => [':status' => 1],
* 'totalCount' => $count,
* 'sort' => [

4
framework/db/ActiveQuery.php

@ -357,7 +357,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* // find all orders, eager loading "books", and sort the orders and books by the book names.
* Order::find()->joinWith([
* 'books' => function ($query) {
* $query->orderBy('tbl_item.name');
* $query->orderBy('item.name');
* }
* ])->all();
* ```
@ -628,7 +628,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* public function getItems()
* {
* return $this->hasMany(Item::className(), ['id' => 'item_id'])
* ->viaTable('tbl_order_item', ['order_id' => 'id']);
* ->viaTable('order_item', ['order_id' => 'id']);
* }
* ```
*

12
framework/db/ActiveRecord.php

@ -21,8 +21,8 @@ use yii\helpers\StringHelper;
* row in a database table. The object's attributes are mapped to the columns of the corresponding table.
* Referencing an Active Record attribute is equivalent to accessing the corresponding table column for that record.
*
* As an example, say that the `Customer` ActiveRecord class is associated with the `tbl_customer` table.
* This would mean that the class's `name` attribute is automatically mapped to the `name` column in `tbl_customer`.
* As an example, say that the `Customer` ActiveRecord class is associated with the `customer` table.
* This would mean that the class's `name` attribute is automatically mapped to the `name` column in `customer` table.
* Thanks to Active Record, assuming the variable `$customer` is an object of type `Customer`, to get the value of
* the `name` column for the table row, you can use the expression `$customer->name`.
* In this example, Active Record is providing an object-oriented interface for accessing data stored in the database.
@ -38,7 +38,7 @@ use yii\helpers\StringHelper;
* {
* public static function tableName()
* {
* return 'tbl_customer';
* return 'customer';
* }
* }
* ```
@ -58,12 +58,12 @@ use yii\helpers\StringHelper;
* ```php
* $user = new User();
* $user->name = 'Qiang';
* $user->save(); // a new row is inserted into tbl_user
* $user->save(); // a new row is inserted into user table
*
* // the following will retrieve the user 'CeBe' from the database
* $user = User::find()->where(['name' => 'CeBe'])->one();
*
* // this will get related records from table tbl_orders when relation is defined
* // this will get related records from orders table when relation is defined
* $orders = $user->orders;
* ```
*
@ -131,7 +131,7 @@ class ActiveRecord extends BaseActiveRecord
* Below is an example:
*
* ~~~
* $customers = Customer::findBySql('SELECT * FROM tbl_customer')->all();
* $customers = Customer::findBySql('SELECT * FROM customer')->all();
* ~~~
*
* @param string $sql the SQL statement to be executed

2
framework/db/BatchQueryResult.php

@ -17,7 +17,7 @@ use yii\base\Object;
* you can iterate it to obtain a batch of data in each iteration. For example,
*
* ```php
* $query = (new Query)->from('tbl_user');
* $query = (new Query)->from('user');
* foreach ($query->batch() as $i => $users) {
* // $users represents the rows in the $i-th batch
* }

12
framework/db/Command.php

@ -23,7 +23,7 @@ use yii\caching\Cache;
* For example,
*
* ~~~
* $users = $connection->createCommand('SELECT * FROM tbl_user')->queryAll();
* $users = $connection->createCommand('SELECT * FROM user')->queryAll();
* ~~~
*
* Command supports SQL statement preparation and parameter binding.
@ -36,7 +36,7 @@ use yii\caching\Cache;
* [[update()]], etc. For example,
*
* ~~~
* $connection->createCommand()->insert('tbl_user', [
* $connection->createCommand()->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ])->execute();
@ -438,7 +438,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->insert('tbl_user', [
* $connection->createCommand()->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ])->execute();
@ -465,7 +465,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [
* $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],
@ -491,7 +491,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->update('tbl_user', ['status' => 1], 'age > 30')->execute();
* $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
* ~~~
*
* The method will properly escape the column names and bind the values to be updated.
@ -517,7 +517,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->delete('tbl_user', 'status = 0')->execute();
* $connection->createCommand()->delete('user', 'status = 0')->execute();
* ~~~
*
* The method will properly escape the table and column names.

8
framework/db/Connection.php

@ -39,9 +39,9 @@ use yii\caching\Cache;
* After the DB connection is established, one can execute SQL statements like the following:
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM tbl_post');
* $command = $connection->createCommand('SELECT * FROM post');
* $posts = $command->queryAll();
* $command = $connection->createCommand('UPDATE tbl_post SET status=1');
* $command = $connection->createCommand('UPDATE post SET status=1');
* $command->execute();
* ~~~
*
@ -50,7 +50,7 @@ use yii\caching\Cache;
* to prevent SQL injection attacks. The following is an example:
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM tbl_post WHERE id=:id');
* $command = $connection->createCommand('SELECT * FROM post WHERE id=:id');
* $command->bindValue(':id', $_GET['id']);
* $post = $command->query();
* ~~~
@ -221,7 +221,7 @@ class Connection extends Component
* as `{{%TableName}}`, then the percentage character `%` will be replaced with this
* property value. For example, `{{%post}}` becomes `{{tbl_post}}`.
*/
public $tablePrefix = 'tbl_';
public $tablePrefix = '';
/**
* @var array mapping between PDO driver names and [[Schema]] classes.
* The keys of the array are PDO driver names while the values the corresponding

2
framework/db/DataReader.php

@ -17,7 +17,7 @@ use yii\base\InvalidCallException;
* iterating through the reader. For example,
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM tbl_post');
* $command = $connection->createCommand('SELECT * FROM post');
* $reader = $command->query();
*
* while ($row = $reader->read()) {

30
framework/db/Query.php

@ -25,7 +25,7 @@ use yii\base\Component;
* $query = new Query;
* // compose the query
* $query->select('id, name')
* ->from('tbl_user')
* ->from('user')
* ->limit(10);
* // build and execute the query
* $rows = $query->all();
@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface
*/
public $distinct;
/**
* @var array the table(s) to be selected from. For example, `['tbl_user', 'tbl_post']`.
* @var array the table(s) to be selected from. For example, `['user', 'post']`.
* This is used to construct the FROM clause in a SQL statement.
* @see from()
*/
@ -82,8 +82,8 @@ class Query extends Component implements QueryInterface
*
* ~~~
* [
* ['INNER JOIN', 'tbl_user', 'tbl_user.id = author_id'],
* ['LEFT JOIN', 'tbl_team', 'tbl_team.id = team_id'],
* ['INNER JOIN', 'user', 'user.id = author_id'],
* ['LEFT JOIN', 'team', 'team.id = team_id'],
* ]
* ~~~
*/
@ -143,9 +143,9 @@ class Query extends Component implements QueryInterface
* For example,
*
* ```php
* $query = (new Query)->from('tbl_user');
* $query = (new Query)->from('user');
* foreach ($query->batch() as $rows) {
* // $rows is an array of 10 or fewer rows from tbl_user
* // $rows is an array of 10 or fewer rows from user table
* }
* ```
*
@ -171,7 +171,7 @@ class Query extends Component implements QueryInterface
* only one row of data is returned. For example,
*
* ```php
* $query = (new Query)->from('tbl_user');
* $query = (new Query)->from('user');
* foreach ($query->each() as $row) {
* }
* ```
@ -383,7 +383,7 @@ class Query extends Component implements QueryInterface
* Sets the SELECT part of the query.
* @param string|array $columns the columns to be selected.
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']).
* Columns can contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_user.id AS user_id").
* Columns can be prefixed with table names (e.g. "user.id") and/or contain column aliases (e.g. "user.id AS user_id").
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
*
@ -422,9 +422,9 @@ class Query extends Component implements QueryInterface
/**
* Sets the FROM part of the query.
* @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. `'tbl_user'`)
* or an array (e.g. `['tbl_user', 'tbl_profile']`) specifying one or several table names.
* Table names can contain schema prefixes (e.g. `'public.tbl_user'`) and/or table aliases (e.g. `'tbl_user u'`).
* @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. `'user'`)
* or an array (e.g. `['user', 'profile']`) specifying one or several table names.
* Table names can contain schema prefixes (e.g. `'public.user'`) and/or table aliases (e.g. `'user u'`).
* The method will automatically quote the table names unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
@ -581,7 +581,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
@ -606,7 +606,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
@ -631,7 +631,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
@ -656,7 +656,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*

10
framework/db/QueryBuilder.php

@ -94,7 +94,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->insert('tbl_user', [
* $sql = $queryBuilder->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ], $params);
@ -141,7 +141,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->batchInsert('tbl_user', ['name', 'age'], [
* $sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],
@ -196,7 +196,7 @@ class QueryBuilder extends \yii\base\Object
*
* ~~~
* $params = [];
* $sql = $queryBuilder->update('tbl_user', ['status' => 1], 'age > 30', $params);
* $sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
* ~~~
*
* The method will properly escape the table and column names.
@ -242,7 +242,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->delete('tbl_user', 'status = 0');
* $sql = $queryBuilder->delete('user', 'status = 0');
* ~~~
*
* The method will properly escape the table and column names.
@ -276,7 +276,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->createTable('tbl_user', [
* $sql = $queryBuilder->createTable('user', [
* 'id' => 'pk',
* 'name' => 'string',
* 'age' => 'integer',

2
framework/db/sqlite/QueryBuilder.php

@ -46,7 +46,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
* For example,
*
* ~~~
* $connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [
* $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],

8
framework/i18n/DbMessageSource.php

@ -22,23 +22,23 @@ use yii\db\Query;
* The database must contain the following two tables:
*
* ~~~
* CREATE TABLE tbl_source_message (
* CREATE TABLE source_message (
* id INTEGER PRIMARY KEY AUTO_INCREMENT,
* category VARCHAR(32),
* message TEXT
* );
*
* CREATE TABLE tbl_message (
* CREATE TABLE message (
* id INTEGER,
* language VARCHAR(16),
* translation TEXT,
* PRIMARY KEY (id, language),
* CONSTRAINT fk_message_source_message FOREIGN KEY (id)
* REFERENCES tbl_source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT
* REFERENCES source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT
* );
* ~~~
*
* The `tbl_source_message` table stores the messages to be translated, and the `tbl_message` table stores
* The `source_message` table stores the messages to be translated, and the `message` table stores
* the translated messages. The name of these two tables can be customized by setting [[sourceMessageTable]]
* and [[messageTable]], respectively.
*

4
framework/log/DbTarget.php

@ -15,7 +15,7 @@ use yii\di\Instance;
/**
* DbTarget stores log messages in a database table.
*
* By default, DbTarget stores the log messages in a DB table named 'tbl_log'. This table
* By default, DbTarget stores the log messages in a DB table named 'log'. This table
* must be pre-created. The table name can be changed by setting [[logTable]].
*
* @author Qiang Xue <qiang.xue@gmail.com>
@ -34,7 +34,7 @@ class DbTarget extends Target
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE tbl_log (
* CREATE TABLE log (
* id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
* level INTEGER,
* category VARCHAR(255),

6
framework/rbac/DbManager.php

@ -39,15 +39,15 @@ class DbManager extends Manager
*/
public $db = 'db';
/**
* @var string the name of the table storing authorization items. Defaults to 'tbl_auth_item'.
* @var string the name of the table storing authorization items. Defaults to 'auth_item'.
*/
public $itemTable = '{{%auth_item}}';
/**
* @var string the name of the table storing authorization item hierarchy. Defaults to 'tbl_auth_item_child'.
* @var string the name of the table storing authorization item hierarchy. Defaults to 'auth_item_child'.
*/
public $itemChildTable = '{{%auth_item_child}}';
/**
* @var string the name of the table storing authorization item assignments. Defaults to 'tbl_auth_assignment'.
* @var string the name of the table storing authorization item assignments. Defaults to 'auth_assignment'.
*/
public $assignmentTable = '{{%auth_assignment}}';

18
framework/rbac/schema-mssql.sql

@ -9,11 +9,11 @@
* @since 2.0
*/
drop table if exists [tbl_auth_assignment];
drop table if exists [tbl_auth_item_child];
drop table if exists [tbl_auth_item];
drop table if exists [auth_assignment];
drop table if exists [auth_item_child];
drop table if exists [auth_item];
create table [tbl_auth_item]
create table [auth_item]
(
[name] varchar(64) not null,
[type] integer not null,
@ -24,21 +24,21 @@ create table [tbl_auth_item]
key [type] ([type])
);
create table [tbl_auth_item_child]
create table [auth_item_child]
(
[parent] varchar(64) not null,
[child] varchar(64) not null,
primary key ([parent],[child]),
foreign key ([parent]) references [tbl_auth_item] ([name]) on delete cascade on update cascade,
foreign key ([child]) references [tbl_auth_item] ([name]) on delete cascade on update cascade
foreign key ([parent]) references [auth_item] ([name]) on delete cascade on update cascade,
foreign key ([child]) references [auth_item] ([name]) on delete cascade on update cascade
);
create table [tbl_auth_assignment]
create table [auth_assignment]
(
[item_name] varchar(64) not null,
[user_id] varchar(64) not null,
[biz_rule] text,
[data] text,
primary key ([item_name],[user_id]),
foreign key ([item_name]) references [tbl_auth_item] ([name]) on delete cascade on update cascade
foreign key ([item_name]) references [auth_item] ([name]) on delete cascade on update cascade
);

18
framework/rbac/schema-mysql.sql

@ -9,11 +9,11 @@
* @since 2.0
*/
drop table if exists `tbl_auth_assignment`;
drop table if exists `tbl_auth_item_child`;
drop table if exists `tbl_auth_item`;
drop table if exists `auth_assignment`;
drop table if exists `auth_item_child`;
drop table if exists `auth_item`;
create table `tbl_auth_item`
create table `auth_item`
(
`name` varchar(64) not null,
`type` integer not null,
@ -24,21 +24,21 @@ create table `tbl_auth_item`
key `type` (`type`)
) engine InnoDB;
create table `tbl_auth_item_child`
create table `auth_item_child`
(
`parent` varchar(64) not null,
`child` varchar(64) not null,
primary key (`parent`,`child`),
foreign key (`parent`) references `tbl_auth_item` (`name`) on delete cascade on update cascade,
foreign key (`child`) references `tbl_auth_item` (`name`) on delete cascade on update cascade
foreign key (`parent`) references `auth_item` (`name`) on delete cascade on update cascade,
foreign key (`child`) references `auth_item` (`name`) on delete cascade on update cascade
) engine InnoDB;
create table `tbl_auth_assignment`
create table `auth_assignment`
(
`item_name` varchar(64) not null,
`user_id` varchar(64) not null,
`biz_rule` text,
`data` text,
primary key (`item_name`,`user_id`),
foreign key (`item_name`) references `tbl_auth_item` (`name`) on delete cascade on update cascade
foreign key (`item_name`) references `auth_item` (`name`) on delete cascade on update cascade
) engine InnoDB;

18
framework/rbac/schema-oci.sql

@ -9,11 +9,11 @@
* @since 2.0
*/
drop table if exists "tbl_auth_assignment";
drop table if exists "tbl_auth_item_child";
drop table if exists "tbl_auth_item";
drop table if exists "auth_assignment";
drop table if exists "auth_item_child";
drop table if exists "auth_item";
create table "tbl_auth_item"
create table "auth_item"
(
"name" varchar(64) not null,
"type" integer not null,
@ -24,21 +24,21 @@ create table "tbl_auth_item"
key "type" ("type")
);
create table "tbl_auth_item_child"
create table "auth_item_child"
(
"parent" varchar(64) not null,
"child" varchar(64) not null,
primary key ("parent","child"),
foreign key ("parent") references "tbl_auth_item" ("name") on delete cascade on update cascade,
foreign key ("child") references "tbl_auth_item" ("name") on delete cascade on update cascade
foreign key ("parent") references "auth_item" ("name") on delete cascade on update cascade,
foreign key ("child") references "auth_item" ("name") on delete cascade on update cascade
);
create table "tbl_auth_assignment"
create table "auth_assignment"
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references "tbl_auth_item" ("name") on delete cascade on update cascade
foreign key ("item_name") references "auth_item" ("name") on delete cascade on update cascade
);

20
framework/rbac/schema-pgsql.sql

@ -9,11 +9,11 @@
* @since 2.0
*/
drop table if exists "tbl_auth_assignment";
drop table if exists "tbl_auth_item_child";
drop table if exists "tbl_auth_item";
drop table if exists "auth_assignment";
drop table if exists "auth_item_child";
drop table if exists "auth_item";
create table "tbl_auth_item"
create table "auth_item"
(
"name" varchar(64) not null,
"type" integer not null,
@ -23,23 +23,23 @@ create table "tbl_auth_item"
primary key ("name")
);
create index tbl_auth_item_type_idx on "tbl_auth_item" ("type");
create index auth_item_type_idx on "auth_item" ("type");
create table "tbl_auth_item_child"
create table "auth_item_child"
(
"parent" varchar(64) not null,
"child" varchar(64) not null,
primary key ("parent","child"),
foreign key ("parent") references "tbl_auth_item" ("name") on delete cascade on update cascade,
foreign key ("child") references "tbl_auth_item" ("name") on delete cascade on update cascade
foreign key ("parent") references "auth_item" ("name") on delete cascade on update cascade,
foreign key ("child") references "auth_item" ("name") on delete cascade on update cascade
);
create table "tbl_auth_assignment"
create table "auth_assignment"
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references "tbl_auth_item" ("name") on delete cascade on update cascade
foreign key ("item_name") references "auth_item" ("name") on delete cascade on update cascade
);

18
framework/rbac/schema-sqlite.sql

@ -9,11 +9,11 @@
* @since 2.0
*/
drop table if exists 'tbl_auth_assignment';
drop table if exists 'tbl_auth_item_child';
drop table if exists 'tbl_auth_item';
drop table if exists 'auth_assignment';
drop table if exists 'auth_item_child';
drop table if exists 'auth_item';
create table 'tbl_auth_item'
create table 'auth_item'
(
"name" varchar(64) not null,
"type" integer not null,
@ -24,21 +24,21 @@ create table 'tbl_auth_item'
key "type" ("type")
);
create table 'tbl_auth_item_child'
create table 'auth_item_child'
(
"parent" varchar(64) not null,
"child" varchar(64) not null,
primary key ("parent","child"),
foreign key ("parent") references 'tbl_auth_item' ("name") on delete cascade on update cascade,
foreign key ("child") references 'tbl_auth_item' ("name") on delete cascade on update cascade
foreign key ("parent") references 'auth_item' ("name") on delete cascade on update cascade,
foreign key ("child") references 'auth_item' ("name") on delete cascade on update cascade
);
create table 'tbl_auth_assignment'
create table 'auth_assignment'
(
"item_name" varchar(64) not null,
"user_id" varchar(64) not null,
"biz_rule" text,
"data" text,
primary key ("item_name","user_id"),
foreign key ("item_name") references 'tbl_auth_item' ("name") on delete cascade on update cascade
foreign key ("item_name") references 'auth_item' ("name") on delete cascade on update cascade
);

4
framework/web/DbSession.php

@ -16,7 +16,7 @@ use yii\di\Instance;
/**
* DbSession extends [[Session]] by using database as session data storage.
*
* By default, DbSession stores session data in a DB table named 'tbl_session'. This table
* By default, DbSession stores session data in a DB table named 'session'. This table
* must be pre-created. The table name can be changed by setting [[sessionTable]].
*
* The following example shows how you can configure the application to use DbSession:
@ -48,7 +48,7 @@ class DbSession extends Session
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE tbl_session
* CREATE TABLE session
* (
* id CHAR(40) NOT NULL PRIMARY KEY,
* expire INTEGER,

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

@ -17,7 +17,7 @@ class Category extends ActiveRecord
{
public static function tableName()
{
return 'tbl_category';
return 'category';
}
public function getItems()

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

@ -25,7 +25,7 @@ class Customer extends ActiveRecord
public static function tableName()
{
return 'tbl_customer';
return 'customer';
}
public function getProfile()
@ -49,9 +49,9 @@ class Customer extends ActiveRecord
/** @var ActiveQuery $rel */
$rel = $this->hasMany(Item::className(), ['id' => 'item_id']);
return $rel->viaTable('tbl_order_item', ['order_id' => 'id'], function ($q) {
return $rel->viaTable('order_item', ['order_id' => 'id'], function ($q) {
/** @var ActiveQuery $q */
$q->viaTable('tbl_order', ['customer_id' => 'id']);
$q->viaTable('order', ['customer_id' => 'id']);
})->orderBy('id');
}

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

@ -13,7 +13,7 @@ class Item extends ActiveRecord
{
public static function tableName()
{
return 'tbl_item';
return 'item';
}
public function getCategory()

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

@ -15,6 +15,6 @@ class NullValues extends ActiveRecord
{
public static function tableName()
{
return 'tbl_null_values';
return 'null_values';
}
}

6
tests/unit/data/ar/Order.php

@ -14,7 +14,7 @@ class Order extends ActiveRecord
{
public static function tableName()
{
return 'tbl_order';
return 'order';
}
public function getCustomer()
@ -59,7 +59,7 @@ class Order extends ActiveRecord
public function getBooks()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->viaTable('tbl_order_item', ['order_id' => 'id'])
->viaTable('order_item', ['order_id' => 'id'])
->where(['category_id' => 1]);
}
@ -67,7 +67,7 @@ class Order extends ActiveRecord
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->onCondition(['category_id' => 1])
->viaTable('tbl_order_item', ['order_id' => 'id']);
->viaTable('order_item', ['order_id' => 'id']);
}
public function beforeSave($insert)

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

@ -14,7 +14,7 @@ class OrderItem extends ActiveRecord
{
public static function tableName()
{
return 'tbl_order_item';
return 'order_item';
}
public function getOrder()

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

@ -16,6 +16,6 @@ class Profile extends ActiveRecord
{
public static function tableName()
{
return 'tbl_profile';
return 'profile';
}
}

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

@ -3,7 +3,7 @@
namespace yiiunit\data\ar;
/**
* Model representing tbl_type table
* Model representing type table
*
* @property int $int_col
* @property int $int_col2 DEFAULT 1
@ -25,7 +25,7 @@ class Type extends ActiveRecord
*/
public static function tableName()
{
return 'tbl_type';
return 'type';
}
}

2
tests/unit/data/ar/elasticsearch/Order.php

@ -59,7 +59,7 @@ class Order extends ActiveRecord
// public function getBooks()
// {
// return $this->hasMany('Item', ['id' => 'item_id'])
// ->viaTable('tbl_order_item', ['order_id' => 'id'])
// ->viaTable('order_item', ['order_id' => 'id'])
// ->where(['category_id' => 1]);
// }

94
tests/unit/data/cubrid.sql

@ -3,31 +3,31 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP TABLE IF EXISTS tbl_composite_fk;
DROP TABLE IF EXISTS tbl_order_item;
DROP TABLE IF EXISTS tbl_item;
DROP TABLE IF EXISTS tbl_order;
DROP TABLE IF EXISTS tbl_category;
DROP TABLE IF EXISTS tbl_customer;
DROP TABLE IF EXISTS tbl_profile;
DROP TABLE IF EXISTS tbl_null_values;
DROP TABLE IF EXISTS tbl_type;
DROP TABLE IF EXISTS tbl_constraints;
CREATE TABLE `tbl_constraints`
DROP TABLE IF EXISTS `composite_fk`;
DROP TABLE IF EXISTS `order_item`;
DROP TABLE IF EXISTS `item`;
DROP TABLE IF EXISTS `order`;
DROP TABLE IF EXISTS `category`;
DROP TABLE IF EXISTS `customer`;
DROP TABLE IF EXISTS `profile`;
DROP TABLE IF EXISTS `null_values`;
DROP TABLE IF EXISTS `type`;
DROP TABLE IF EXISTS `constraints`;
CREATE TABLE `constraints`
(
`id` integer not null,
`field1` varchar(255)
);
CREATE TABLE `tbl_profile` (
CREATE TABLE `profile` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`description` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `tbl_customer` (
CREATE TABLE `customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL,
`name` varchar(128),
@ -37,40 +37,40 @@ CREATE TABLE `tbl_customer` (
PRIMARY KEY (`id`)
);
CREATE TABLE `tbl_category` (
CREATE TABLE `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `tbl_item` (
CREATE TABLE `item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `tbl_category` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
);
CREATE TABLE `tbl_order` (
CREATE TABLE `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`total` decimal(10,0) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `tbl_customer` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
);
CREATE TABLE `tbl_order_item` (
CREATE TABLE `order_item` (
`order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL,
`subtotal` decimal(10,0) NOT NULL,
PRIMARY KEY (`order_id`,`item_id`),
CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `tbl_order` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `tbl_item` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE CASCADE
);
CREATE TABLE tbl_null_values (
CREATE TABLE null_values (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`var1` INT NULL,
`var2` INT NULL,
@ -80,7 +80,7 @@ CREATE TABLE tbl_null_values (
);
CREATE TABLE `tbl_type` (
CREATE TABLE `type` (
`int_col` int(11) NOT NULL,
`int_col2` int(11) DEFAULT '1',
`char_col` char(100) NOT NULL,
@ -96,37 +96,37 @@ CREATE TABLE `tbl_type` (
`bool_col2` tinyint DEFAULT '1'
);
CREATE TABLE `tbl_composite_fk` (
CREATE TABLE `composite_fk` (
`id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `tbl_order_item` (`order_id`,`item_id`) ON DELETE CASCADE
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `order_item` (`order_id`,`item_id`) ON DELETE CASCADE
);
INSERT INTO tbl_profile (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3');
INSERT INTO `profile` (description) VALUES ('profile customer 1');
INSERT INTO `profile` (description) VALUES ('profile customer 3');
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO `customer` (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies');
INSERT INTO `category` (name) VALUES ('Books');
INSERT INTO `category` (name) VALUES ('Movies');
INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2);
INSERT INTO `item` (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO `item` (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO `item` (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO `item` (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO `item` (name, category_id) VALUES ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);

74
tests/unit/data/mssql.sql

@ -1,13 +1,13 @@
IF OBJECT_ID('[dbo].[tbl_order_item]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order_item];
IF OBJECT_ID('[dbo].[tbl_item]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_item];
IF OBJECT_ID('[dbo].[tbl_order]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order];
IF OBJECT_ID('[dbo].[tbl_category]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_category];
IF OBJECT_ID('[dbo].[tbl_customer]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_customer];
IF OBJECT_ID('[dbo].[tbl_profile]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_profile];
IF OBJECT_ID('[dbo].[tbl_type]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_type];
IF OBJECT_ID('[dbo].[tbl_null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_null_values];
IF OBJECT_ID('[dbo].[order_item]', 'U') IS NOT NULL DROP TABLE [dbo].[order_item];
IF OBJECT_ID('[dbo].[item]', 'U') IS NOT NULL DROP TABLE [dbo].[item];
IF OBJECT_ID('[dbo].[order]', 'U') IS NOT NULL DROP TABLE [dbo].[order];
IF OBJECT_ID('[dbo].[category]', 'U') IS NOT NULL DROP TABLE [dbo].[category];
IF OBJECT_ID('[dbo].[customer]', 'U') IS NOT NULL DROP TABLE [dbo].[customer];
IF OBJECT_ID('[dbo].[profile]', 'U') IS NOT NULL DROP TABLE [dbo].[profile];
IF OBJECT_ID('[dbo].[type]', 'U') IS NOT NULL DROP TABLE [dbo].[type];
IF OBJECT_ID('[dbo].[null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[null_values];
CREATE TABLE [dbo].[tbl_profile] (
CREATE TABLE [dbo].[profile] (
[id] [int] IDENTITY(1,1) NOT NULL,
[description] [varchar](128) NOT NULL,
CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED (
@ -15,7 +15,7 @@ CREATE TABLE [dbo].[tbl_profile] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_customer] (
CREATE TABLE [dbo].[customer] (
[id] [int] IDENTITY(1,1) NOT NULL,
[email] [varchar](128) NOT NULL,
[name] [varchar](128),
@ -27,7 +27,7 @@ CREATE TABLE [dbo].[tbl_customer] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_category] (
CREATE TABLE [dbo].[category] (
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NOT NULL,
CONSTRAINT [PK_category] PRIMARY KEY CLUSTERED (
@ -35,7 +35,7 @@ CREATE TABLE [dbo].[tbl_category] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_item] (
CREATE TABLE [dbo].[item] (
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NOT NULL,
[category_id] [int] NOT NULL,
@ -44,7 +44,7 @@ CREATE TABLE [dbo].[tbl_item] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_order] (
CREATE TABLE [dbo].[order] (
[id] [int] IDENTITY(1,1) NOT NULL,
[customer_id] [int] NOT NULL,
[created_at] [int] NOT NULL,
@ -54,7 +54,7 @@ CREATE TABLE [dbo].[tbl_order] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_order_item] (
CREATE TABLE [dbo].[order_item] (
[order_id] [int] NOT NULL,
[item_id] [int] NOT NULL,
[quantity] [int] NOT NULL,
@ -65,7 +65,7 @@ CREATE TABLE [dbo].[tbl_order_item] (
) ON [PRIMARY]
);
CREATE TABLE [dbo].[tbl_null_values] (
CREATE TABLE [dbo].[null_values] (
id [int] UNSIGNED NOT NULL,
var1 [int] UNSIGNED NULL,
var2 [int] NULL,
@ -74,7 +74,7 @@ CREATE TABLE [dbo].[tbl_null_values] (
PRIMARY KEY (id)
);
CREATE TABLE [dbo].[tbl_type] (
CREATE TABLE [dbo].[type] (
[int_col] [int] NOT NULL,
[int_col2] [int] DEFAULT '1',
[char_col] [char](100) NOT NULL,
@ -89,29 +89,29 @@ CREATE TABLE [dbo].[tbl_type] (
[bool_col2] [tinyint] DEFAULT '1'
);
INSERT INTO [dbo].[tbl_profile] ([description]) VALUES ('profile customer 1');
INSERT INTO [dbo].[tbl_profile] ([description]) VALUES ('profile customer 3');
INSERT INTO [dbo].[profile] ([description]) VALUES ('profile customer 1');
INSERT INTO [dbo].[profile] ([description]) VALUES ('profile customer 3');
INSERT INTO [dbo].[tbl_customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO [dbo].[tbl_customer] ([email], [name], [address], [status]) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO [dbo].[tbl_customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO [dbo].[customer] ([email], [name], [address], [status]) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO [dbo].[customer] ([email], [name], [address], [status], [profile_id]) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO [dbo].[tbl_category] ([name]) VALUES ('Books');
INSERT INTO [dbo].[tbl_category] ([name]) VALUES ('Movies');
INSERT INTO [dbo].[category] ([name]) VALUES ('Books');
INSERT INTO [dbo].[category] ([name]) VALUES ('Movies');
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Ice Age', 2);
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Toy Story', 2);
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Cars', 2);
INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Ice Age', 2);
INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Toy Story', 2);
INSERT INTO [dbo].[item] ([name], [category_id]) VALUES ('Cars', 2);
INSERT INTO [dbo].[tbl_order] ([customer_id], [created_at], [total]) VALUES (1, 1325282384, 110.0);
INSERT INTO [dbo].[tbl_order] ([customer_id], [created_at], [total]) VALUES (2, 1325334482, 33.0);
INSERT INTO [dbo].[tbl_order] ([customer_id], [created_at], [total]) VALUES (2, 1325502201, 40.0);
INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (1, 1325282384, 110.0);
INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (2, 1325334482, 33.0);
INSERT INTO [dbo].[order] ([customer_id], [created_at], [total]) VALUES (2, 1325502201, 40.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 1, 1, 30.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 2, 2, 40.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 4, 1, 10.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 5, 1, 15.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 3, 1, 8.0);
INSERT INTO [dbo].[tbl_order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (3, 2, 1, 40.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 1, 1, 30.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (1, 2, 2, 40.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 4, 1, 10.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 5, 1, 15.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (2, 3, 1, 8.0);
INSERT INTO [dbo].[order_item] ([order_id], [item_id], [quantity], [subtotal]) VALUES (3, 2, 1, 40.0);

122
tests/unit/data/mysql.sql

@ -3,31 +3,31 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP TABLE IF EXISTS tbl_composite_fk CASCADE;
DROP TABLE IF EXISTS tbl_order_item CASCADE;
DROP TABLE IF EXISTS tbl_item CASCADE;
DROP TABLE IF EXISTS tbl_order CASCADE;
DROP TABLE IF EXISTS tbl_category CASCADE;
DROP TABLE IF EXISTS tbl_customer CASCADE;
DROP TABLE IF EXISTS tbl_profile CASCADE;
DROP TABLE IF EXISTS tbl_null_values CASCADE;
DROP TABLE IF EXISTS tbl_type CASCADE;
DROP TABLE IF EXISTS tbl_constraints CASCADE;
CREATE TABLE `tbl_constraints`
DROP TABLE IF EXISTS `composite_fk` CASCADE;
DROP TABLE IF EXISTS `order_item` CASCADE;
DROP TABLE IF EXISTS `item` CASCADE;
DROP TABLE IF EXISTS `order` CASCADE;
DROP TABLE IF EXISTS `category` CASCADE;
DROP TABLE IF EXISTS `customer` CASCADE;
DROP TABLE IF EXISTS `profile` CASCADE;
DROP TABLE IF EXISTS `null_values` CASCADE;
DROP TABLE IF EXISTS `type` CASCADE;
DROP TABLE IF EXISTS `constraints` CASCADE;
CREATE TABLE `constraints`
(
`id` integer not null,
`field1` varchar(255)
);
CREATE TABLE `tbl_profile` (
CREATE TABLE `profile` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`description` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_customer` (
CREATE TABLE `customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL,
`name` varchar(128),
@ -37,50 +37,50 @@ CREATE TABLE `tbl_customer` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_category` (
CREATE TABLE `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_item` (
CREATE TABLE `item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_item_category_id` (`category_id`),
CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `tbl_category` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_order` (
CREATE TABLE `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`total` decimal(10,0) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `tbl_customer` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_order_item` (
CREATE TABLE `order_item` (
`order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL,
`subtotal` decimal(10,0) NOT NULL,
PRIMARY KEY (`order_id`,`item_id`),
KEY `FK_order_item_item_id` (`item_id`),
CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `tbl_order` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `tbl_item` (`id`) ON DELETE CASCADE
CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_composite_fk` (
CREATE TABLE `composite_fk` (
`id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `tbl_order_item` (`order_id`,`item_id`) ON DELETE CASCADE
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `order_item` (`order_id`,`item_id`) ON DELETE CASCADE
);
CREATE TABLE tbl_null_values (
CREATE TABLE null_values (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`var1` INT UNSIGNED NULL,
`var2` INT NULL,
@ -89,7 +89,7 @@ CREATE TABLE tbl_null_values (
PRIMARY KEY (id)
);
CREATE TABLE `tbl_type` (
CREATE TABLE `type` (
`int_col` int(11) NOT NULL,
`int_col2` int(11) DEFAULT '1',
`char_col` char(100) NOT NULL,
@ -104,61 +104,61 @@ CREATE TABLE `tbl_type` (
`bool_col2` tinyint(1) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO tbl_profile (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3');
INSERT INTO `profile` (description) VALUES ('profile customer 1');
INSERT INTO `profile` (description) VALUES ('profile customer 3');
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO `customer` (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies');
INSERT INTO `category` (name) VALUES ('Books');
INSERT INTO `category` (name) VALUES ('Movies');
INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2);
INSERT INTO `item` (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO `item` (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO `item` (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO `item` (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO `item` (name, category_id) VALUES ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
/**
* (MySQL-)Database Schema for validator tests
*/
DROP TABLE IF EXISTS tbl_validator_main CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE;
DROP TABLE IF EXISTS `validator_main` CASCADE;
DROP TABLE IF EXISTS `validator_ref` CASCADE;
CREATE TABLE tbl_validator_main (
CREATE TABLE `validator_main` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`field1` VARCHAR(255),
PRIMARY KEY (`id`)
) ENGINE =InnoDB DEFAULT CHARSET =utf8;
CREATE TABLE tbl_validator_ref (
CREATE TABLE `validator_ref` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`a_field` VARCHAR(255),
`ref` INT(11),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_3', 3);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_5', 5);
INSERT INTO `validator_main` (id, field1) VALUES (1, 'just a string1');
INSERT INTO `validator_main` (id, field1) VALUES (2, 'just a string2');
INSERT INTO `validator_main` (id, field1) VALUES (3, 'just a string3');
INSERT INTO `validator_main` (id, field1) VALUES (4, 'just a string4');
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_3', 3);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_5', 5);

118
tests/unit/data/postgres.sql

@ -4,28 +4,28 @@
* and create an account 'postgres/postgres' which owns this test database.
*/
DROP TABLE IF EXISTS tbl_order_item CASCADE;
DROP TABLE IF EXISTS tbl_item CASCADE;
DROP TABLE IF EXISTS tbl_order CASCADE;
DROP TABLE IF EXISTS tbl_category CASCADE;
DROP TABLE IF EXISTS tbl_customer CASCADE;
DROP TABLE IF EXISTS tbl_profile CASCADE;
DROP TABLE IF EXISTS tbl_type CASCADE;
DROP TABLE IF EXISTS tbl_null_values CASCADE;
DROP TABLE IF EXISTS tbl_constraints CASCADE;
CREATE TABLE tbl_constraints
DROP TABLE IF EXISTS "order_item" CASCADE;
DROP TABLE IF EXISTS "item" CASCADE;
DROP TABLE IF EXISTS "order" CASCADE;
DROP TABLE IF EXISTS "category" CASCADE;
DROP TABLE IF EXISTS "customer" CASCADE;
DROP TABLE IF EXISTS "profile" CASCADE;
DROP TABLE IF EXISTS "type" CASCADE;
DROP TABLE IF EXISTS "null_values" CASCADE;
DROP TABLE IF EXISTS "constraints" CASCADE;
CREATE TABLE "constraints"
(
id integer not null,
field1 varchar(255)
);
CREATE TABLE tbl_profile (
CREATE TABLE "profile" (
id serial not null primary key,
description varchar(128) NOT NULL
);
CREATE TABLE tbl_customer (
CREATE TABLE "customer" (
id serial not null primary key,
email varchar(128) NOT NULL,
name varchar(128),
@ -34,35 +34,35 @@ CREATE TABLE tbl_customer (
profile_id integer
);
comment on column public.tbl_customer.email is 'someone@example.com';
comment on column public.customer.email is 'someone@example.com';
CREATE TABLE tbl_category (
CREATE TABLE "category" (
id serial not null primary key,
name varchar(128) NOT NULL
);
CREATE TABLE tbl_item (
CREATE TABLE "item" (
id serial not null primary key,
name varchar(128) NOT NULL,
category_id integer NOT NULL references tbl_category(id) on UPDATE CASCADE on DELETE CASCADE
category_id integer NOT NULL references "category"(id) on UPDATE CASCADE on DELETE CASCADE
);
CREATE TABLE tbl_order (
CREATE TABLE "order" (
id serial not null primary key,
customer_id integer NOT NULL references tbl_customer(id) on UPDATE CASCADE on DELETE CASCADE,
customer_id integer NOT NULL references "customer"(id) on UPDATE CASCADE on DELETE CASCADE,
created_at integer NOT NULL,
total decimal(10,0) NOT NULL
);
CREATE TABLE tbl_order_item (
order_id integer NOT NULL references tbl_order(id) on UPDATE CASCADE on DELETE CASCADE,
item_id integer NOT NULL references tbl_item(id) on UPDATE CASCADE on DELETE CASCADE,
CREATE TABLE "order_item" (
order_id integer NOT NULL references "order"(id) on UPDATE CASCADE on DELETE CASCADE,
item_id integer NOT NULL references "item"(id) on UPDATE CASCADE on DELETE CASCADE,
quantity integer NOT NULL,
subtotal decimal(10,0) NOT NULL,
PRIMARY KEY (order_id,item_id)
);
CREATE TABLE tbl_null_values (
CREATE TABLE "null_values" (
id INT NOT NULL,
var1 INT NULL,
var2 INT NULL,
@ -71,7 +71,7 @@ CREATE TABLE tbl_null_values (
PRIMARY KEY (id)
);
CREATE TABLE tbl_type (
CREATE TABLE "type" (
int_col integer NOT NULL,
int_col2 integer DEFAULT '1',
char_col char(100) NOT NULL,
@ -86,58 +86,58 @@ CREATE TABLE tbl_type (
bool_col2 smallint DEFAULT '1'
);
INSERT INTO tbl_profile (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3');
INSERT INTO "profile" (description) VALUES ('profile customer 1');
INSERT INTO "profile" (description) VALUES ('profile customer 3');
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO "customer" (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies');
INSERT INTO "category" (name) VALUES ('Books');
INSERT INTO "category" (name) VALUES ('Movies');
INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2);
INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO "item" (name, category_id) VALUES ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
/**
* (Postgres-)Database Schema for validator tests
*/
DROP TABLE IF EXISTS tbl_validator_main CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE;
DROP TABLE IF EXISTS "validator_main" CASCADE;
DROP TABLE IF EXISTS "validator_ref" CASCADE;
CREATE TABLE tbl_validator_main (
CREATE TABLE "validator_main" (
id integer not null primary key,
field1 VARCHAR(255)
);
CREATE TABLE tbl_validator_ref (
CREATE TABLE "validator_ref" (
id integer not null primary key,
a_field VARCHAR(255),
ref integer
);
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
INSERT INTO "validator_main" (id, field1) VALUES (1, 'just a string1');
INSERT INTO "validator_main" (id, field1) VALUES (2, 'just a string2');
INSERT INTO "validator_main" (id, field1) VALUES (3, 'just a string3');
INSERT INTO "validator_main" (id, field1) VALUES (4, 'just a string4');
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (6, 'ref_to_5', 5);

118
tests/unit/data/sqlite.sql

@ -3,23 +3,23 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP TABLE IF EXISTS tbl_composite_fk;
DROP TABLE IF EXISTS tbl_order_item;
DROP TABLE IF EXISTS tbl_item;
DROP TABLE IF EXISTS tbl_order;
DROP TABLE IF EXISTS tbl_category;
DROP TABLE IF EXISTS tbl_customer;
DROP TABLE IF EXISTS tbl_profile;
DROP TABLE IF EXISTS tbl_type;
DROP TABLE IF EXISTS tbl_null_values;
CREATE TABLE tbl_profile (
DROP TABLE IF EXISTS "composite_fk";
DROP TABLE IF EXISTS "order_item";
DROP TABLE IF EXISTS "item";
DROP TABLE IF EXISTS "order";
DROP TABLE IF EXISTS "category";
DROP TABLE IF EXISTS "customer";
DROP TABLE IF EXISTS "profile";
DROP TABLE IF EXISTS "type";
DROP TABLE IF EXISTS "null_values";
CREATE TABLE "profile" (
id INTEGER NOT NULL,
description varchar(128) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tbl_customer (
CREATE TABLE "customer" (
id INTEGER NOT NULL,
email varchar(128) NOT NULL,
name varchar(128),
@ -29,20 +29,20 @@ CREATE TABLE tbl_customer (
PRIMARY KEY (id)
);
CREATE TABLE tbl_category (
CREATE TABLE "category" (
id INTEGER NOT NULL,
name varchar(128) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tbl_item (
CREATE TABLE "item" (
id INTEGER NOT NULL,
name varchar(128) NOT NULL,
category_id INTEGER NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tbl_order (
CREATE TABLE "order" (
id INTEGER NOT NULL,
customer_id INTEGER NOT NULL,
created_at INTEGER NOT NULL,
@ -50,7 +50,7 @@ CREATE TABLE tbl_order (
PRIMARY KEY (id)
);
CREATE TABLE tbl_order_item (
CREATE TABLE "order_item" (
order_id INTEGER NOT NULL,
item_id INTEGER NOT NULL,
quantity INTEGER NOT NULL,
@ -58,15 +58,15 @@ CREATE TABLE tbl_order_item (
PRIMARY KEY (order_id, item_id)
);
CREATE TABLE `tbl_composite_fk` (
`id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `tbl_order_item` (`order_id`,`item_id`) ON DELETE CASCADE
CREATE TABLE "composite_fk" (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
item_id int(11) NOT NULL,
PRIMARY KEY (id),
CONSTRAINT FK_composite_fk_order_item FOREIGN KEY (order_id, item_id) REFERENCES "order_item" (order_id, item_id) ON DELETE CASCADE
);
CREATE TABLE tbl_null_values (
CREATE TABLE "null_values" (
id INTEGER UNSIGNED PRIMARY KEY NOT NULL,
var1 INTEGER UNSIGNED,
var2 INTEGER,
@ -74,7 +74,7 @@ CREATE TABLE tbl_null_values (
stringcol VARCHAR(32) DEFAULT NULL
);
CREATE TABLE tbl_type (
CREATE TABLE "type" (
int_col INTEGER NOT NULL,
int_col2 INTEGER DEFAULT '1',
char_col char(100) NOT NULL,
@ -89,58 +89,58 @@ CREATE TABLE tbl_type (
bool_col2 tinyint(1) DEFAULT '1'
);
INSERT INTO tbl_profile (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3');
INSERT INTO "profile" (description) VALUES ('profile customer 1');
INSERT INTO "profile" (description) VALUES ('profile customer 3');
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO "customer" (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO "customer" (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies');
INSERT INTO "category" (name) VALUES ('Books');
INSERT INTO "category" (name) VALUES ('Movies');
INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2);
INSERT INTO "item" (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO "item" (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO "item" (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO "item" (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO "item" (name, category_id) VALUES ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO "order" (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO "order_item" (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
/**
* (SqLite-)Database Schema for validator tests
*/
DROP TABLE IF EXISTS tbl_validator_main;
DROP TABLE IF EXISTS tbl_validator_ref;
DROP TABLE IF EXISTS "validator_main";
DROP TABLE IF EXISTS "validator_ref";
CREATE TABLE tbl_validator_main (
CREATE TABLE "validator_main" (
id INTEGER PRIMARY KEY ,
field1 VARCHAR(255)
);
CREATE TABLE tbl_validator_ref (
CREATE TABLE "validator_ref" (
id INTEGER PRIMARY KEY ,
a_field VARCHAR(255),
ref INT(11)
);
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
INSERT INTO "validator_main" (id, field1) VALUES (1, 'just a string1');
INSERT INTO "validator_main" (id, field1) VALUES (2, 'just a string2');
INSERT INTO "validator_main" (id, field1) VALUES (3, 'just a string3');
INSERT INTO "validator_main" (id, field1) VALUES (4, 'just a string4');
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (6, 'ref_to_5', 5);

2
tests/unit/data/validators/models/ValidatorTestMainModel.php

@ -10,7 +10,7 @@ class ValidatorTestMainModel extends ActiveRecord
public static function tableName()
{
return 'tbl_validator_main';
return 'validator_main';
}
public function getReferences()

2
tests/unit/data/validators/models/ValidatorTestRefModel.php

@ -12,7 +12,7 @@ class ValidatorTestRefModel extends ActiveRecord
public static function tableName()
{
return 'tbl_validator_ref';
return 'validator_ref';
}
public function getMain()

4
tests/unit/extensions/elasticsearch/ActiveRecordTest.php

@ -102,8 +102,8 @@ class ActiveRecordTest extends ElasticSearchTestCase
$customer->setAttributes(['email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2], false);
$customer->save(false);
// INSERT INTO tbl_category (name) VALUES ('Books');
// INSERT INTO tbl_category (name) VALUES ('Movies');
// INSERT INTO category (name) VALUES ('Books');
// INSERT INTO category (name) VALUES ('Movies');
$item = new Item();
$item->id = 1;

4
tests/unit/extensions/redis/ActiveRecordTest.php

@ -71,8 +71,8 @@ class ActiveRecordTest extends RedisTestCase
$customer->setAttributes(['email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
$customer->save(false);
// INSERT INTO tbl_category (name) VALUES ('Books');
// INSERT INTO tbl_category (name) VALUES ('Movies');
// INSERT INTO category (name) VALUES ('Books');
// INSERT INTO category (name) VALUES ('Movies');
$item = new Item();
$item->setAttributes(['name' => 'Agile Web Application Development with Yii1.1 and PHP5', 'category_id' => 1], false);

4
tests/unit/extensions/sphinx/QueryTest.php

@ -28,8 +28,8 @@ class QueryTest extends SphinxTestCase
public function testFrom()
{
$query = new Query;
$query->from('tbl_user');
$this->assertEquals(['tbl_user'], $query->from);
$query->from('user');
$this->assertEquals(['user'], $query->from);
}
public function testMatch()

2
tests/unit/framework/caching/DbCacheTest.php

@ -23,7 +23,7 @@ class DbCacheTest extends CacheTestCase
parent::setUp();
$this->getConnection()->createCommand("
CREATE TABLE IF NOT EXISTS tbl_cache (
CREATE TABLE IF NOT EXISTS cache (
id char(128) NOT NULL,
expire int(11) DEFAULT NULL,
data LONGBLOB,

8
tests/unit/framework/data/ActiveDataProviderTest.php

@ -126,7 +126,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query;
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'),
'query' => $query->from('order')->orderBy('id'),
]);
$orders = $provider->getModels();
$this->assertEquals(3, count($orders));
@ -136,7 +136,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query;
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $query->from('tbl_order'),
'query' => $query->from('order'),
'pagination' => [
'pageSize' => 2,
]
@ -150,7 +150,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query;
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'),
'query' => $query->from('order')->orderBy('id'),
]);
$this->assertEquals(3, count($provider->getModels()));
@ -165,7 +165,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query;
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'),
'query' => $query->from('order')->orderBy('id'),
]);
$pagination = $provider->getPagination();
$this->assertEquals(0, $pagination->getPageCount());

50
tests/unit/framework/db/ActiveRecordTest.php

@ -104,16 +104,16 @@ class ActiveRecordTest extends DatabaseTestCase
public function testFindBySql()
{
// find one
$customer = Customer::findBySql('SELECT * FROM tbl_customer ORDER BY id DESC')->one();
$customer = Customer::findBySql('SELECT * FROM customer ORDER BY id DESC')->one();
$this->assertTrue($customer instanceof Customer);
$this->assertEquals('user3', $customer->name);
// find all
$customers = Customer::findBySql('SELECT * FROM tbl_customer')->all();
$customers = Customer::findBySql('SELECT * FROM customer')->all();
$this->assertEquals(3, count($customers));
// find with parameter binding
$customer = Customer::findBySql('SELECT * FROM tbl_customer WHERE id=:id', [':id' => 2])->one();
$customer = Customer::findBySql('SELECT * FROM customer WHERE id=:id', [':id' => 2])->one();
$this->assertTrue($customer instanceof Customer);
$this->assertEquals('user2', $customer->name);
}
@ -269,7 +269,7 @@ class ActiveRecordTest extends DatabaseTestCase
public function testJoinWith()
{
// left join and eager loading
$orders = Order::find()->joinWith('customer')->orderBy('tbl_customer.id DESC, tbl_order.id')->all();
$orders = Order::find()->joinWith('customer')->orderBy('customer.id DESC, order.id')->all();
$this->assertEquals(3, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id);
@ -281,9 +281,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering and eager loading
$orders = Order::find()->innerJoinWith([
'customer' => function ($query) {
$query->where('tbl_customer.id=2');
$query->where('customer.id=2');
},
])->orderBy('tbl_order.id')->all();
])->orderBy('order.id')->all();
$this->assertEquals(2, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id);
@ -293,9 +293,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering, eager loading, conditions on both primary and relation
$orders = Order::find()->innerJoinWith([
'customer' => function ($query) {
$query->where(['tbl_customer.id' => 2]);
$query->where(['customer.id' => 2]);
},
])->where(['tbl_order.id' => [1, 2]])->orderBy('tbl_order.id')->all();
])->where(['order.id' => [1, 2]])->orderBy('order.id')->all();
$this->assertEquals(1, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertTrue($orders[0]->isRelationPopulated('customer'));
@ -303,9 +303,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading
$orders = Order::find()->innerJoinWith([
'customer' => function ($query) {
$query->where('tbl_customer.id=2');
$query->where('customer.id=2');
},
], false)->orderBy('tbl_order.id')->all();
], false)->orderBy('order.id')->all();
$this->assertEquals(2, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id);
@ -315,15 +315,15 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading, conditions on both primary and relation
$orders = Order::find()->innerJoinWith([
'customer' => function ($query) {
$query->where(['tbl_customer.id' => 2]);
$query->where(['customer.id' => 2]);
},
], false)->where(['tbl_order.id' => [1, 2]])->orderBy('tbl_order.id')->all();
], false)->where(['order.id' => [1, 2]])->orderBy('order.id')->all();
$this->assertEquals(1, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertFalse($orders[0]->isRelationPopulated('customer'));
// join with via-relation
$orders = Order::find()->innerJoinWith('books')->orderBy('tbl_order.id')->all();
$orders = Order::find()->innerJoinWith('books')->orderBy('order.id')->all();
$this->assertEquals(2, count($orders));
$this->assertEquals(1, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id);
@ -335,12 +335,12 @@ class ActiveRecordTest extends DatabaseTestCase
// join with sub-relation
$orders = Order::find()->innerJoinWith([
'items' => function ($q) {
$q->orderBy('tbl_item.id');
$q->orderBy('item.id');
},
'items.category' => function ($q) {
$q->where('tbl_category.id = 2');
$q->where('category.id = 2');
},
])->orderBy('tbl_order.id')->all();
])->orderBy('order.id')->all();
$this->assertEquals(1, count($orders));
$this->assertTrue($orders[0]->isRelationPopulated('items'));
$this->assertEquals(2, $orders[0]->id);
@ -351,9 +351,9 @@ class ActiveRecordTest extends DatabaseTestCase
// join with table alias
$orders = Order::find()->joinWith([
'customer' => function ($q) {
$q->from('tbl_customer c');
$q->from('customer c');
}
])->orderBy('c.id DESC, tbl_order.id')->all();
])->orderBy('c.id DESC, order.id')->all();
$this->assertEquals(3, count($orders));
$this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id);
@ -363,7 +363,7 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertTrue($orders[2]->isRelationPopulated('customer'));
// join with ON condition
$orders = Order::find()->joinWith('books2')->orderBy('tbl_order.id')->all();
$orders = Order::find()->joinWith('books2')->orderBy('order.id')->all();
$this->assertEquals(3, count($orders));
$this->assertEquals(1, $orders[0]->id);
$this->assertEquals(2, $orders[1]->id);
@ -411,22 +411,22 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals(1, $customer->id);
$order = Order::find()->joinWith([
'items' => function ($q) {
$q->from(['items' => 'tbl_item'])
$q->from(['items' => 'item'])
->orderBy('items.id');
},
])->orderBy('tbl_order.id')->one();
])->orderBy('order.id')->one();
}
public function testJoinWithAndScope()
{
// hasOne inner join
$customers = Customer::find()->active()->innerJoinWith('profile')->orderBy('tbl_customer.id')->all();
$customers = Customer::find()->active()->innerJoinWith('profile')->orderBy('customer.id')->all();
$this->assertEquals(1, count($customers));
$this->assertEquals(1, $customers[0]->id);
$this->assertTrue($customers[0]->isRelationPopulated('profile'));
// hasOne outer join
$customers = Customer::find()->active()->joinWith('profile')->orderBy('tbl_customer.id')->all();
$customers = Customer::find()->active()->joinWith('profile')->orderBy('customer.id')->all();
$this->assertEquals(2, count($customers));
$this->assertEquals(1, $customers[0]->id);
$this->assertEquals(2, $customers[1]->id);
@ -438,9 +438,9 @@ class ActiveRecordTest extends DatabaseTestCase
// hasMany
$customers = Customer::find()->active()->joinWith([
'orders' => function ($q) {
$q->orderBy('tbl_order.id');
$q->orderBy('order.id');
}
])->orderBy('tbl_customer.id DESC, tbl_order.id')->all();
])->orderBy('customer.id DESC, order.id')->all();
$this->assertEquals(2, count($customers));
$this->assertEquals(2, $customers[0]->id);
$this->assertEquals(1, $customers[1]->id);

12
tests/unit/framework/db/BatchQueryResultTest.php

@ -31,7 +31,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// initialize property test
$query = new Query();
$query->from('tbl_customer')->orderBy('id');
$query->from('customer')->orderBy('id');
$result = $query->batch(2, $db);
$this->assertTrue($result instanceof BatchQueryResult);
$this->assertEquals(2, $result->batchSize);
@ -39,7 +39,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// normal query
$query = new Query();
$query->from('tbl_customer')->orderBy('id');
$query->from('customer')->orderBy('id');
$allRows = [];
$batch = $query->batch(2, $db);
foreach ($batch as $rows) {
@ -60,7 +60,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// empty query
$query = new Query();
$query->from('tbl_customer')->where(['id' => 100]);
$query->from('customer')->where(['id' => 100]);
$allRows = [];
$batch = $query->batch(2, $db);
foreach ($batch as $rows) {
@ -70,7 +70,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// query with index
$query = new Query();
$query->from('tbl_customer')->indexBy('name');
$query->from('customer')->indexBy('name');
$allRows = [];
foreach ($query->batch(2, $db) as $rows) {
$allRows = array_merge($allRows, $rows);
@ -82,7 +82,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each
$query = new Query();
$query->from('tbl_customer')->orderBy('id');
$query->from('customer')->orderBy('id');
$allRows = [];
foreach ($query->each(100, $db) as $rows) {
$allRows[] = $rows;
@ -94,7 +94,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each with key
$query = new Query();
$query->from('tbl_customer')->orderBy('id')->indexBy('name');
$query->from('customer')->orderBy('id')->indexBy('name');
$allRows = [];
foreach ($query->each(100, $db) as $key => $row) {
$allRows[$key] = $row;

58
tests/unit/framework/db/CommandTest.php

@ -19,7 +19,7 @@ class CommandTest extends DatabaseTestCase
$this->assertEquals(null, $command->sql);
// string
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql);
$this->assertEquals($sql, $command->sql);
}
@ -28,11 +28,11 @@ class CommandTest extends DatabaseTestCase
{
$db = $this->getConnection(false);
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql);
$this->assertEquals($sql, $command->sql);
$sql2 = 'SELECT * FROM tbl_order';
$sql2 = 'SELECT * FROM order';
$command->sql = $sql2;
$this->assertEquals($sql2, $command->sql);
}
@ -41,16 +41,16 @@ class CommandTest extends DatabaseTestCase
{
$db = $this->getConnection(false);
$sql = 'SELECT [[id]], [[t.name]] FROM {{tbl_customer}} t';
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
$command = $db->createCommand($sql);
$this->assertEquals("SELECT `id`, `t`.`name` FROM `tbl_customer` t", $command->sql);
$this->assertEquals("SELECT `id`, `t`.`name` FROM `customer` t", $command->sql);
}
public function testPrepareCancel()
{
$db = $this->getConnection(false);
$command = $db->createCommand('SELECT * FROM tbl_customer');
$command = $db->createCommand('SELECT * FROM customer');
$this->assertEquals(null, $command->pdoStatement);
$command->prepare();
$this->assertNotEquals(null, $command->pdoStatement);
@ -62,11 +62,11 @@ class CommandTest extends DatabaseTestCase
{
$db = $this->getConnection();
$sql = 'INSERT INTO tbl_customer(email, name , address) VALUES (\'user4@example.com\', \'user4\', \'address4\')';
$sql = 'INSERT INTO customer(email, name , address) VALUES (\'user4@example.com\', \'user4\', \'address4\')';
$command = $db->createCommand($sql);
$this->assertEquals(1, $command->execute());
$sql = 'SELECT COUNT(*) FROM tbl_customer WHERE name =\'user4\'';
$sql = 'SELECT COUNT(*) FROM customer WHERE name =\'user4\'';
$command = $db->createCommand($sql);
$this->assertEquals(1, $command->queryScalar());
@ -80,55 +80,55 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection();
// query
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$reader = $db->createCommand($sql)->query();
$this->assertTrue($reader instanceof DataReader);
// queryAll
$rows = $db->createCommand('SELECT * FROM tbl_customer')->queryAll();
$rows = $db->createCommand('SELECT * FROM customer')->queryAll();
$this->assertEquals(3, count($rows));
$row = $rows[2];
$this->assertEquals(3, $row['id']);
$this->assertEquals('user3', $row['name']);
$rows = $db->createCommand('SELECT * FROM tbl_customer WHERE id=10')->queryAll();
$rows = $db->createCommand('SELECT * FROM customer WHERE id=10')->queryAll();
$this->assertEquals([], $rows);
// queryOne
$sql = 'SELECT * FROM tbl_customer ORDER BY id';
$sql = 'SELECT * FROM customer ORDER BY id';
$row = $db->createCommand($sql)->queryOne();
$this->assertEquals(1, $row['id']);
$this->assertEquals('user1', $row['name']);
$sql = 'SELECT * FROM tbl_customer ORDER BY id';
$sql = 'SELECT * FROM customer ORDER BY id';
$command = $db->createCommand($sql);
$command->prepare();
$row = $command->queryOne();
$this->assertEquals(1, $row['id']);
$this->assertEquals('user1', $row['name']);
$sql = 'SELECT * FROM tbl_customer WHERE id=10';
$sql = 'SELECT * FROM customer WHERE id=10';
$command = $db->createCommand($sql);
$this->assertFalse($command->queryOne());
// queryColumn
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$column = $db->createCommand($sql)->queryColumn();
$this->assertEquals(range(1, 3), $column);
$command = $db->createCommand('SELECT id FROM tbl_customer WHERE id=10');
$command = $db->createCommand('SELECT id FROM customer WHERE id=10');
$this->assertEquals([], $command->queryColumn());
// queryScalar
$sql = 'SELECT * FROM tbl_customer ORDER BY id';
$sql = 'SELECT * FROM customer ORDER BY id';
$this->assertEquals($db->createCommand($sql)->queryScalar(), 1);
$sql = 'SELECT id FROM tbl_customer ORDER BY id';
$sql = 'SELECT id FROM customer ORDER BY id';
$command = $db->createCommand($sql);
$command->prepare();
$this->assertEquals(1, $command->queryScalar());
$command = $db->createCommand('SELECT id FROM tbl_customer WHERE id=10');
$command = $db->createCommand('SELECT id FROM customer WHERE id=10');
$this->assertFalse($command->queryScalar());
$command = $db->createCommand('bad SQL');
@ -141,7 +141,7 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection();
// bindParam
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)';
$command = $db->createCommand($sql);
$email = 'user4@example.com';
$name = 'user4';
@ -151,12 +151,12 @@ class CommandTest extends DatabaseTestCase
$command->bindParam(':address', $address);
$command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email';
$sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql);
$command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar());
$sql = 'INSERT INTO tbl_type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)';
$sql = 'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)';
$command = $db->createCommand($sql);
$intCol = 123;
$charCol = 'abc';
@ -172,7 +172,7 @@ class CommandTest extends DatabaseTestCase
$command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute());
$sql = 'SELECT * FROM tbl_type';
$sql = 'SELECT * FROM type';
$row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($charCol, $row['char_col']);
@ -181,12 +181,12 @@ class CommandTest extends DatabaseTestCase
$this->assertEquals($numericCol, $row['numeric_col']);
// bindValue
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$command = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com');
$command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name';
$sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql);
$command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar());
@ -197,20 +197,20 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection();
// default: FETCH_ASSOC
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql);
$result = $command->queryOne();
$this->assertTrue(is_array($result) && isset($result['id']));
// FETCH_OBJ, customized via fetchMode property
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql);
$command->fetchMode = \PDO::FETCH_OBJ;
$result = $command->queryOne();
$this->assertTrue(is_object($result));
// FETCH_NUM, customized in query method
$sql = 'SELECT * FROM tbl_customer';
$sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql);
$result = $command->queryOne([], \PDO::FETCH_NUM);
$this->assertTrue(is_array($result) && isset($result[0]));
@ -219,7 +219,7 @@ class CommandTest extends DatabaseTestCase
public function testBatchInsert()
{
$command = $this->getConnection()->createCommand();
$command->batchInsert('tbl_customer',
$command->batchInsert('customer',
['email', 'name', 'address'], [
['t1@example.com', 't1', 't1 address'],
['t2@example.com', null, false],

2
tests/unit/framework/db/QueryBuilderTest.php

@ -115,7 +115,7 @@ class QueryBuilderTest extends DatabaseTestCase
public function testAddDropPrimaryKey()
{
$tableName = 'tbl_constraints';
$tableName = 'constraints';
$pkeyName = $tableName . "_pkey";
// ADD

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

@ -29,8 +29,8 @@ class QueryTest extends DatabaseTestCase
public function testFrom()
{
$query = new Query;
$query->from('tbl_user');
$this->assertEquals(['tbl_user'], $query->from);
$query->from('user');
$this->assertEquals(['user'], $query->from);
}
public function testWhere()
@ -117,10 +117,10 @@ class QueryTest extends DatabaseTestCase
{
$db = $this->getConnection();
$result = (new Query)->from('tbl_customer')->where(['status' => 2])->one($db);
$result = (new Query)->from('customer')->where(['status' => 2])->one($db);
$this->assertEquals('user3', $result['name']);
$result = (new Query)->from('tbl_customer')->where(['status' => 3])->one($db);
$result = (new Query)->from('customer')->where(['status' => 3])->one($db);
$this->assertFalse($result);
}
}

20
tests/unit/framework/db/SchemaTest.php

@ -17,12 +17,12 @@ class SchemaTest extends DatabaseTestCase
$schema = $this->getConnection()->schema;
$tables = $schema->getTableNames();
$this->assertTrue(in_array('tbl_customer', $tables));
$this->assertTrue(in_array('tbl_category', $tables));
$this->assertTrue(in_array('tbl_item', $tables));
$this->assertTrue(in_array('tbl_order', $tables));
$this->assertTrue(in_array('tbl_order_item', $tables));
$this->assertTrue(in_array('tbl_type', $tables));
$this->assertTrue(in_array('customer', $tables));
$this->assertTrue(in_array('category', $tables));
$this->assertTrue(in_array('item', $tables));
$this->assertTrue(in_array('order', $tables));
$this->assertTrue(in_array('order_item', $tables));
$this->assertTrue(in_array('type', $tables));
}
public function testGetTableSchemas()
@ -49,8 +49,8 @@ class SchemaTest extends DatabaseTestCase
$schema->db->enableSchemaCache = true;
$schema->db->schemaCache = new FileCache();
$noCacheTable = $schema->getTableSchema('tbl_type', true);
$cachedTable = $schema->getTableSchema('tbl_type', true);
$noCacheTable = $schema->getTableSchema('type', true);
$cachedTable = $schema->getTableSchema('type', true);
$this->assertEquals($noCacheTable, $cachedTable);
}
@ -59,11 +59,11 @@ class SchemaTest extends DatabaseTestCase
/** @var Schema $schema */
$schema = $this->getConnection()->schema;
$table = $schema->getTableSchema('tbl_composite_fk');
$table = $schema->getTableSchema('composite_fk');
$this->assertCount(1, $table->foreignKeys);
$this->assertTrue(isset($table->foreignKeys[0]));
$this->assertEquals('tbl_order_item', $table->foreignKeys[0][0]);
$this->assertEquals('order_item', $table->foreignKeys[0][0]);
$this->assertEquals('order_id', $table->foreignKeys[0]['order_id']);
$this->assertEquals('item_id', $table->foreignKeys[0]['item_id']);
}

16
tests/unit/framework/db/cubrid/CubridCommandTest.php

@ -16,7 +16,7 @@ class CubridCommandTest extends CommandTest
$db = $this->getConnection();
// bindParam
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)';
$command = $db->createCommand($sql);
$email = 'user4@example.com';
$name = 'user4';
@ -26,12 +26,12 @@ class CubridCommandTest extends CommandTest
$command->bindParam(':address', $address);
$command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email';
$sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql);
$command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar());
$sql = "INSERT INTO tbl_type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col)";
$sql = "INSERT INTO type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col)";
$command = $db->createCommand($sql);
$intCol = 123;
$charCol = 'abc';
@ -49,7 +49,7 @@ class CubridCommandTest extends CommandTest
$command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute());
$sql = 'SELECT * FROM tbl_type';
$sql = 'SELECT * FROM type';
$row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($enumCol, $row['enum_col']);
@ -60,12 +60,12 @@ class CubridCommandTest extends CommandTest
$this->assertEquals($boolCol, $row['bool_col']);
// bindValue
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$command = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com');
$command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name';
$sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql);
$command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar());
@ -75,8 +75,8 @@ class CubridCommandTest extends CommandTest
{
$db = $this->getConnection(false);
$sql = 'SELECT [[id]], [[t.name]] FROM {{tbl_customer}} t';
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
$command = $db->createCommand($sql);
$this->assertEquals('SELECT "id", "t"."name" FROM "tbl_customer" t', $command->sql);
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
}
}

16
tests/unit/framework/db/mssql/MssqlCommandTest.php

@ -16,9 +16,9 @@ class MssqlCommandTest extends CommandTest
{
$db = $this->getConnection(false);
$sql = 'SELECT [[id]], [[t.name]] FROM {{tbl_customer}} t';
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
$command = $db->createCommand($sql);
$this->assertEquals("SELECT [id], [t].[name] FROM [tbl_customer] t", $command->sql);
$this->assertEquals("SELECT [id], [t].[name] FROM [customer] t", $command->sql);
}
public function testPrepareCancel()
@ -31,7 +31,7 @@ class MssqlCommandTest extends CommandTest
$db = $this->getConnection();
// bindParam
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)';
$command = $db->createCommand($sql);
$email = 'user4@example.com';
$name = 'user4';
@ -41,12 +41,12 @@ class MssqlCommandTest extends CommandTest
$command->bindParam(':address', $address);
$command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email';
$sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql);
$command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar());
$sql = 'INSERT INTO tbl_type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)';
$sql = 'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)';
$command = $db->createCommand($sql);
$intCol = 123;
$charCol = 'abc';
@ -62,7 +62,7 @@ class MssqlCommandTest extends CommandTest
$command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute());
$sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM tbl_type';
$sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM type';
$row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($charCol, trim($row['char_col']));
@ -71,12 +71,12 @@ class MssqlCommandTest extends CommandTest
$this->assertEquals($numericCol, $row['numeric_col']);
// bindValue
$sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
$command = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com');
$command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name';
$sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql);
$command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar());

4
tests/unit/framework/db/sqlite/SqliteCommandTest.php

@ -15,8 +15,8 @@ class SqliteCommandTest extends CommandTest
{
$db = $this->getConnection(false);
$sql = 'SELECT [[id]], [[t.name]] FROM {{tbl_customer}} t';
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
$command = $db->createCommand($sql);
$this->assertEquals("SELECT `id`, `t`.`name` FROM `tbl_customer` t", $command->sql);
$this->assertEquals("SELECT `id`, `t`.`name` FROM `customer` t", $command->sql);
}
}

4
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php

@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function testBatchInsert()
{
$sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
$this->assertEquals("INSERT INTO {{tbl_customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'", $sql);
$sql = $this->getQueryBuilder()->batchInsert('{{customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]);
$this->assertEquals("INSERT INTO {{customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'", $sql);
}
}

0
tests/unit/framework/test/data/tbl_customer.php → tests/unit/framework/test/data/customer.php

Loading…
Cancel
Save