Commit 5e7d7605 by Alexander Makarov

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

Fixes #2911: Removed `tbl_` default for table prefix
parents 5adcac52 abeea635
...@@ -11,7 +11,7 @@ class m130524_201442_init extends \yii\db\Migration ...@@ -11,7 +11,7 @@ class m130524_201442_init extends \yii\db\Migration
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
} }
$this->createTable('tbl_user', [ $this->createTable('user', [
'id' => Schema::TYPE_PK, 'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING . ' NOT NULL', 'username' => Schema::TYPE_STRING . ' NOT NULL',
'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL', 'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
...@@ -28,6 +28,6 @@ class m130524_201442_init extends \yii\db\Migration ...@@ -28,6 +28,6 @@ class m130524_201442_init extends \yii\db\Migration
public function down() public function down()
{ {
$this->dropTable('tbl_user'); $this->dropTable('user');
} }
} }
...@@ -66,7 +66,7 @@ class PasswordResetRequestFormTest extends DbTestCase ...@@ -66,7 +66,7 @@ class PasswordResetRequestFormTest extends DbTestCase
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/tbl_user.php' 'dataFile' => '@frontend/tests/unit/fixtures/data/user.php'
], ],
]; ];
} }
......
...@@ -29,7 +29,7 @@ class ResetPasswordFormTest extends DbTestCase ...@@ -29,7 +29,7 @@ class ResetPasswordFormTest extends DbTestCase
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/tbl_user.php' 'dataFile' => '@frontend/tests/unit/fixtures/data/user.php'
], ],
]; ];
} }
......
...@@ -9,8 +9,8 @@ class UserTest extends TestCase ...@@ -9,8 +9,8 @@ class UserTest extends TestCase
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
// uncomment the following to load fixtures for table tbl_user // uncomment the following to load fixtures for user table
//$this->loadFixtures(['tbl_user']); //$this->loadFixtures(['user']);
} }
// TODO add test methods here // TODO add test methods here
......
...@@ -7,9 +7,9 @@ an Active Record instance corresponds to a row of that table, and an attribute o ...@@ -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, 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. 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 For example, assume `Customer` is an Active Record class is associated with the `customer` table
and `name` is a column of `tbl_customer`. You can write the following code to insert a new and `name` is a column of `customer` table. You can write the following code to insert a new
row into `tbl_customer`: row into `customer` table:
```php ```php
$customer = new Customer(); $customer = new Customer();
...@@ -21,7 +21,7 @@ The above code is equivalent to using the following raw SQL statement, which is ...@@ -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: intuitive, more error prone, and may have compatibility problem for different DBMS:
```php ```php
$db->createCommand('INSERT INTO tbl_customer (name) VALUES (:name)', [ $db->createCommand('INSERT INTO customer (name) VALUES (:name)', [
':name' => 'Qiang', ':name' => 'Qiang',
])->execute(); ])->execute();
``` ```
...@@ -45,7 +45,7 @@ class Customer extends ActiveRecord ...@@ -45,7 +45,7 @@ class Customer extends ActiveRecord
*/ */
public static function tableName() public static function tableName()
{ {
return 'tbl_customer'; return 'customer';
} }
} }
``` ```
...@@ -144,7 +144,7 @@ $customers = Customer::find()->indexBy('id')->all(); ...@@ -144,7 +144,7 @@ $customers = Customer::find()->indexBy('id')->all();
// $customers array is indexed by customer IDs // $customers array is indexed by customer IDs
// to retrieve customers using a raw SQL statement: // to retrieve customers using a raw SQL statement:
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$customers = Customer::findBySql($sql)->all(); $customers = Customer::findBySql($sql)->all();
``` ```
...@@ -332,8 +332,8 @@ $orders = $customer->orders; // $orders is an array of Order objects ...@@ -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: Behind the scene, the above code executes the following two SQL queries, one for each line of code:
```sql ```sql
SELECT * FROM tbl_customer WHERE id=1; SELECT * FROM customer WHERE id=1;
SELECT * FROM tbl_order WHERE customer_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. > 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 ...@@ -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 we can customize the [[yii\db\ActiveQuery]] object by calling its [[yii\db\ActiveQuery::via()|via()]] or
[[yii\db\ActiveQuery::viaTable()|viaTable()]] method. [[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: we can declare the `items` relation in the `Order` class like the following:
```php ```php
...@@ -390,7 +390,7 @@ class Order extends \yii\db\ActiveRecord ...@@ -390,7 +390,7 @@ class Order extends \yii\db\ActiveRecord
public function getItems() public function getItems()
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) 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 ...@@ -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, if you access the same related objects again. We call this *lazy loading*. For example,
```php ```php
// SQL executed: SELECT * FROM tbl_customer WHERE id=1 // SQL executed: SELECT * FROM customer WHERE id=1
$customer = Customer::find(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; $orders = $customer->orders;
// no SQL executed // no SQL executed
$orders2 = $customer->orders; $orders2 = $customer->orders;
...@@ -437,11 +437,11 @@ $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: Lazy loading is very convenient to use. However, it may suffer from a performance issue in the following scenario:
```php ```php
// SQL executed: SELECT * FROM tbl_customer LIMIT 100 // SQL executed: SELECT * FROM customer LIMIT 100
$customers = Customer::find()->limit(100)->all(); $customers = Customer::find()->limit(100)->all();
foreach ($customers as $customer) { foreach ($customers as $customer) {
// SQL executed: SELECT * FROM tbl_order WHERE customer_id=... // SQL executed: SELECT * FROM order WHERE customer_id=...
$orders = $customer->orders; $orders = $customer->orders;
// ...handle $orders... // ...handle $orders...
} }
...@@ -454,8 +454,8 @@ is performed to bring back the orders of that customer. ...@@ -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()]]: To solve the above performance problem, you can use the so-called *eager loading* approach by calling [[yii\db\ActiveQuery::with()]]:
```php ```php
// SQL executed: SELECT * FROM tbl_customer LIMIT 100; // SQL executed: SELECT * FROM customer LIMIT 100;
// SELECT * FROM tbl_orders WHERE customer_id IN (1,2,...) // SELECT * FROM orders WHERE customer_id IN (1,2,...)
$customers = Customer::find()->limit(100) $customers = Customer::find()->limit(100)
->with('orders')->all(); ->with('orders')->all();
...@@ -486,11 +486,11 @@ done for both lazy loading and eager loading. For example, ...@@ -486,11 +486,11 @@ done for both lazy loading and eager loading. For example,
```php ```php
$customer = Customer::find(1); $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(); $orders = $customer->getOrders()->where('subtotal>100')->all();
// eager loading: SELECT * FROM tbl_customer LIMIT 100 // eager loading: SELECT * FROM customer LIMIT 100
// SELECT * FROM tbl_order WHERE customer_id IN (1,2,...) AND subtotal>100 // SELECT * FROM order WHERE customer_id IN (1,2,...) AND subtotal>100
$customers = Customer::find()->limit(100)->with([ $customers = Customer::find()->limit(100)->with([
'orders' => function($query) { 'orders' => function($query) {
$query->andWhere('subtotal>100'); $query->andWhere('subtotal>100');
...@@ -530,11 +530,11 @@ that finds those orders, and accessing `customer->orders` will trigger one SQL e ...@@ -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: the `customer` of an order will trigger another SQL execution:
```php ```php
// SELECT * FROM tbl_customer WHERE id=1 // SELECT * FROM customer WHERE id=1
$customer = Customer::find(1); $customer = Customer::find(1);
// echoes "not equal" // echoes "not equal"
// SELECT * FROM tbl_order WHERE customer_id=1 // SELECT * FROM order WHERE customer_id=1
// SELECT * FROM tbl_customer WHERE id=1 // SELECT * FROM customer WHERE id=1
if ($customer->orders[0]->customer === $customer) { if ($customer->orders[0]->customer === $customer) {
echo 'equal'; echo 'equal';
} else { } else {
...@@ -559,10 +559,10 @@ class Customer extends ActiveRecord ...@@ -559,10 +559,10 @@ class Customer extends ActiveRecord
Now if we execute the same query as shown above, we would get: Now if we execute the same query as shown above, we would get:
```php ```php
// SELECT * FROM tbl_customer WHERE id=1 // SELECT * FROM customer WHERE id=1
$customer = Customer::find(1); $customer = Customer::find(1);
// echoes "equal" // echoes "equal"
// SELECT * FROM tbl_order WHERE customer_id=1 // SELECT * FROM order WHERE customer_id=1
if ($customer->orders[0]->customer === $customer) { if ($customer->orders[0]->customer === $customer) {
echo 'equal'; echo 'equal';
} else { } else {
...@@ -574,8 +574,8 @@ In the above, we have shown how to use inverse relations in lazy loading. Invers ...@@ -574,8 +574,8 @@ In the above, we have shown how to use inverse relations in lazy loading. Invers
eager loading: eager loading:
```php ```php
// SELECT * FROM tbl_customer // SELECT * FROM customer
// SELECT * FROM tbl_order WHERE customer_id IN (1, 2, ...) // SELECT * FROM order WHERE customer_id IN (1, 2, ...)
$customers = Customer::find()->with('orders')->all(); $customers = Customer::find()->with('orders')->all();
// echoes "equal" // echoes "equal"
if ($customers[0]->orders[0]->customer === $customers[0]) { 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 ...@@ -600,7 +600,7 @@ explicitly to build up the JOIN query, you may reuse the existing relation defin
```php ```php
// find all orders and sort the orders by the customer id and the order id. also eager loading "customer" // 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" // find all orders that contain books, and eager loading "books"
$orders = Order::find()->innerJoinWith('books')->all(); $orders = Order::find()->innerJoinWith('books')->all();
``` ```
...@@ -617,7 +617,7 @@ and you may also join with sub-relations. For example, ...@@ -617,7 +617,7 @@ and you may also join with sub-relations. For example,
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'books', 'books',
'customer' => function ($query) { 'customer' => function ($query) {
$query->where('tbl_customer.created_at > ' . (time() - 24 * 3600)); $query->where('customer.created_at > ' . (time() - 24 * 3600));
} }
])->all(); ])->all();
// join with sub-relations: join with books and books' authors // 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 ...@@ -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. 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. 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`. 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 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 ...@@ -678,8 +678,8 @@ When you perform query using [[yii\db\ActiveQuery::joinWith()|joinWith()]], the
of the corresponding JOIN query. For example, of the corresponding JOIN query. For example,
```php ```php
// SELECT tbl_user.* FROM tbl_user LEFT JOIN tbl_item ON tbl_item.owner_id=tbl_user.id AND category_id=1 // SELECT user.* FROM user LEFT JOIN item ON item.owner_id=user.id AND category_id=1
// SELECT * FROM tbl_item WHERE owner_id IN (...) AND category_id=1 // SELECT * FROM item WHERE owner_id IN (...) AND category_id=1
$users = User::find()->joinWith('books')->all(); $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 ...@@ -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, in the WHERE part of the corresponding SQL statement, because there is no JOIN query involved. For example,
```php ```php
// SELECT * FROM tbl_user WHERE id=10 // SELECT * FROM user WHERE id=10
$user = User::find(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; $books = $user->books;
``` ```
......
...@@ -80,7 +80,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration ...@@ -80,7 +80,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{ {
public function up() public function up()
{ {
$this->createTable('tbl_news', [ $this->createTable('news', [
'id' => 'pk', 'id' => 'pk',
'title' => Schema::TYPE_STRING . ' NOT NULL', 'title' => Schema::TYPE_STRING . ' NOT NULL',
'content' => Schema::TYPE_TEXT, 'content' => Schema::TYPE_TEXT,
...@@ -89,7 +89,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration ...@@ -89,7 +89,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public function down() public function down()
{ {
$this->dropTable('tbl_news'); $this->dropTable('news');
} }
} }
...@@ -124,13 +124,13 @@ class m101129_185401_create_news_table extends \yii\db\Migration ...@@ -124,13 +124,13 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{ {
public function safeUp() public function safeUp()
{ {
$this->createTable('tbl_news', [ $this->createTable('news', [
'id' => 'pk', 'id' => 'pk',
'title' => Schema::TYPE_STRING . ' NOT NULL', 'title' => Schema::TYPE_STRING . ' NOT NULL',
'content' => Schema::TYPE_TEXT, 'content' => Schema::TYPE_TEXT,
]); ]);
$this->createTable('tbl_user', [ $this->createTable('user', [
'id' => 'pk', 'id' => 'pk',
'login' => Schema::TYPE_STRING . ' NOT NULL', 'login' => Schema::TYPE_STRING . ' NOT NULL',
'password' => 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 ...@@ -139,8 +139,8 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public function safeDown() public function safeDown()
{ {
$this->dropTable('tbl_news'); $this->dropTable('news');
$this->dropTable('tbl_user'); $this->dropTable('user');
} }
} }
...@@ -169,8 +169,8 @@ the migrations, it will run the `up()` method in every new migration class, one ...@@ -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 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 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 table named `migration`. This allows the tool to identify which migrations
have been applied and which are not. If the `tbl_migration` table does not exist, 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` the tool will automatically create it in the database specified by the `db`
application component. application component.
...@@ -284,7 +284,7 @@ line: ...@@ -284,7 +284,7 @@ line:
sub-directory under the application base path. sub-directory under the application base path.
* `migrationTable`: string, specifies the name of the database table for storing * `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`. structure is `version varchar(255) primary key, apply_time integer`.
* `connectionID`: string, specifies the ID of the database application component. * `connectionID`: string, specifies the ID of the database application component.
......
...@@ -31,7 +31,7 @@ And the following example shows how to use ActiveDataProvider without ActiveReco ...@@ -31,7 +31,7 @@ And the following example shows how to use ActiveDataProvider without ActiveReco
```php ```php
$query = new Query(); $query = new Query();
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'query' => $query->from('tbl_post'), 'query' => $query->from('post'),
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],
...@@ -64,7 +64,7 @@ ArrayDataProvider may be used in the following way: ...@@ -64,7 +64,7 @@ ArrayDataProvider may be used in the following way:
```php ```php
$query = new Query(); $query = new Query();
$provider = new ArrayDataProvider([ $provider = new ArrayDataProvider([
'allModels' => $query->from('tbl_post')->all(), 'allModels' => $query->from('post')->all(),
'sort' => [ 'sort' => [
'attributes' => ['id', 'username', 'email'], 'attributes' => ['id', 'username', 'email'],
], ],
...@@ -94,11 +94,11 @@ and pagination behaviors. ...@@ -94,11 +94,11 @@ and pagination behaviors.
```php ```php
$count = Yii::$app->db->createCommand(' $count = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM tbl_user WHERE status=:status SELECT COUNT(*) FROM user WHERE status=:status
', [':status' => 1])->queryScalar(); ', [':status' => 1])->queryScalar();
$dataProvider = new SqlDataProvider([ $dataProvider = new SqlDataProvider([
'sql' => 'SELECT * FROM tbl_user WHERE status=:status', 'sql' => 'SELECT * FROM user WHERE status=:status',
'params' => [':status' => 1], 'params' => [':status' => 1],
'totalCount' => $count, 'totalCount' => $count,
'sort' => [ 'sort' => [
......
...@@ -103,28 +103,28 @@ Once you have a connection instance you can execute SQL queries using [[yii\db\C ...@@ -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: When query returns a set of rows:
```php ```php
$command = $connection->createCommand('SELECT * FROM tbl_post'); $command = $connection->createCommand('SELECT * FROM post');
$posts = $command->queryAll(); $posts = $command->queryAll();
``` ```
When only a single row is returned: When only a single row is returned:
```php ```php
$command = $connection->createCommand('SELECT * FROM tbl_post WHERE id=1'); $command = $connection->createCommand('SELECT * FROM post WHERE id=1');
$post = $command->queryOne(); $post = $command->queryOne();
``` ```
When there are multiple values from the same column: When there are multiple values from the same column:
```php ```php
$command = $connection->createCommand('SELECT title FROM tbl_post'); $command = $connection->createCommand('SELECT title FROM post');
$titles = $command->queryColumn(); $titles = $command->queryColumn();
``` ```
When there's a scalar value: When there's a scalar value:
```php ```php
$command = $connection->createCommand('SELECT COUNT(*) FROM tbl_post'); $command = $connection->createCommand('SELECT COUNT(*) FROM post');
$postCount = $command->queryScalar(); $postCount = $command->queryScalar();
``` ```
...@@ -133,7 +133,7 @@ $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: If SQL executed doesn't return any data you can use command's `execute` method:
```php ```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(); $command->execute();
``` ```
...@@ -141,23 +141,23 @@ Alternatively the following syntax that takes care of proper table and column na ...@@ -141,23 +141,23 @@ Alternatively the following syntax that takes care of proper table and column na
```php ```php
// INSERT // INSERT
$connection->createCommand()->insert('tbl_user', [ $connection->createCommand()->insert('user', [
'name' => 'Sam', 'name' => 'Sam',
'age' => 30, 'age' => 30,
])->execute(); ])->execute();
// INSERT multiple rows at once // INSERT multiple rows at once
$connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [ $connection->createCommand()->batchInsert('user', ['name', 'age'], [
['Tom', 30], ['Tom', 30],
['Jane', 20], ['Jane', 20],
['Linda', 25], ['Linda', 25],
])->execute(); ])->execute();
// UPDATE // UPDATE
$connection->createCommand()->update('tbl_user', ['status' => 1], 'age > 30')->execute(); $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
// DELETE // DELETE
$connection->createCommand()->delete('tbl_user', 'status = 0')->execute(); $connection->createCommand()->delete('user', 'status = 0')->execute();
``` ```
Quoting table and column names Quoting table and column names
...@@ -189,7 +189,7 @@ Prepared statements ...@@ -189,7 +189,7 @@ Prepared statements
In order to securely pass query parameters you can use prepared statements: In order to securely pass query parameters you can use prepared statements:
```php ```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']); $command->bindValue(':id', $_GET['id']);
$post = $command->query(); $post = $command->query();
``` ```
...@@ -197,7 +197,7 @@ $post = $command->query(); ...@@ -197,7 +197,7 @@ $post = $command->query();
Another usage is performing a query multiple times while preparing it only once: Another usage is performing a query multiple times while preparing it only once:
```php ```php
$command = $connection->createCommand('DELETE FROM tbl_post WHERE id=:id'); $command = $connection->createCommand('DELETE FROM post WHERE id=:id');
$command->bindParam(':id', $id); $command->bindParam(':id', $id);
$id = 1; $id = 1;
...@@ -281,7 +281,7 @@ These can be used as follows: ...@@ -281,7 +281,7 @@ These can be used as follows:
```php ```php
// CREATE TABLE // CREATE TABLE
$connection->createCommand()->createTable('tbl_post', [ $connection->createCommand()->createTable('post', [
'id' => 'pk', 'id' => 'pk',
'title' => 'string', 'title' => 'string',
'text' => 'text', 'text' => 'text',
......
...@@ -11,7 +11,7 @@ A typical usage of the query builder looks like the following: ...@@ -11,7 +11,7 @@ A typical usage of the query builder looks like the following:
```php ```php
$rows = (new \yii\db\Query()) $rows = (new \yii\db\Query())
->select('id, name') ->select('id, name')
->from('tbl_user') ->from('user')
->limit(10) ->limit(10)
->all(); ->all();
...@@ -19,7 +19,7 @@ $rows = (new \yii\db\Query()) ...@@ -19,7 +19,7 @@ $rows = (new \yii\db\Query())
$query = (new \yii\db\Query()) $query = (new \yii\db\Query())
->select('id, name') ->select('id, name')
->from('tbl_user') ->from('user')
->limit(10); ->limit(10);
// Create a command. You can get the actual SQL using $command->sql // 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 ...@@ -62,7 +62,7 @@ In order to form a basic `SELECT` query, you need to specify what columns to sel
```php ```php
$query->select('id, name') $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. 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: ...@@ -70,7 +70,7 @@ The array syntax is especially useful when forming the selection dynamically:
```php ```php
$query->select(['id', 'name']) $query->select(['id', 'name'])
->from('tbl_user'); ->from('user');
``` ```
> Info: You should always use the array format if your `SELECT` clause contains SQL expressions. > Info: You should always use the array format if your `SELECT` clause contains SQL expressions.
...@@ -78,14 +78,14 @@ $query->select(['id', 'name']) ...@@ -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 > 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. > 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, 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: To select distinct rows, you may call `distinct()`, like the following:
```php ```php
$query->select('user_id')->distinct()->from('tbl_post'); $query->select('user_id')->distinct()->from('post');
``` ```
### `FROM` ### `FROM`
...@@ -93,30 +93,30 @@ $query->select('user_id')->distinct()->from('tbl_post'); ...@@ -93,30 +93,30 @@ $query->select('user_id')->distinct()->from('tbl_post');
To specify which table(s) to select data from, call `from()`: To specify which table(s) to select data from, call `from()`:
```php ```php
$query->select('*')->from('tbl_user'); $query->select('*')->from('user');
``` ```
You may specify multiple tables using a comma-separated string or an array. 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 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, (which means the table is given as a sub-query or DB expression). For example,
```php ```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 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, (if a table does not need alias, do not use a string key). For example,
```php ```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 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. as the alias for the sub-query.
```php ```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]); $query->select('*')->from(['u' => $subQuery]);
``` ```
...@@ -293,9 +293,9 @@ The `JOIN` clauses are generated in the Query Builder by using the applicable jo ...@@ -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: This left join selects data from two related tables in one query:
```php ```php
$query->select(['tbl_user.name AS author', 'tbl_post.title as title']) $query->select(['user.name AS author', 'post.title as title'])
->from('tbl_user') ->from('user')
->leftJoin('tbl_post', 'tbl_post.user_id = tbl_user.id'); ->leftJoin('post', 'post.user_id = user.id');
``` ```
In the code, the `leftJoin()` method's first parameter 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. ...@@ -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: If your database application supports other join types, you can use those via the generic `join` method:
```php ```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. 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 ...@@ -325,10 +325,10 @@ In Yii in order to build it you can first form two query objects and then use `u
```php ```php
$query = new Query(); $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 = 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); $query->union($anotherQuery);
``` ```
...@@ -348,7 +348,7 @@ Batch query can be used like the following: ...@@ -348,7 +348,7 @@ Batch query can be used like the following:
use yii\db\Query; use yii\db\Query;
$query = (new Query()) $query = (new Query())
->from('tbl_user') ->from('user')
->orderBy('id'); ->orderBy('id');
foreach ($query->batch() as $users) { foreach ($query->batch() as $users) {
...@@ -377,7 +377,7 @@ will still keep the proper index. For example, ...@@ -377,7 +377,7 @@ will still keep the proper index. For example,
use yii\db\Query; use yii\db\Query;
$query = (new Query()) $query = (new Query())
->from('tbl_user') ->from('user')
->indexBy('username'); ->indexBy('username');
foreach ($query->batch() as $users) { foreach ($query->batch() as $users) {
......
...@@ -44,7 +44,7 @@ class UserFixture extends ActiveFixture ...@@ -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`, 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` 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 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, to be inserted into the user table. For example,
```php ```php
......
...@@ -396,7 +396,7 @@ and [[yii\db\QueryBuilder|QueryBuilder]] to generate SQL statements from query o ...@@ -396,7 +396,7 @@ and [[yii\db\QueryBuilder|QueryBuilder]] to generate SQL statements from query o
```php ```php
$query = new \yii\db\Query(); $query = new \yii\db\Query();
$query->select('id, name') $query->select('id, name')
->from('tbl_user') ->from('user')
->limit(10); ->limit(10);
$command = $query->createCommand(); $command = $query->createCommand();
......
...@@ -52,7 +52,7 @@ use yii\helpers\FileHelper; ...@@ -52,7 +52,7 @@ use yii\helpers\FileHelper;
* *
* - `$fixture` - current fixture array. * - `$fixture` - current fixture array.
* - `$faker` - faker generator instance * - `$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. * After you set all needed fields in callback, you need to return $fixture array back from the callback.
* *
......
...@@ -62,7 +62,7 @@ If you use callback as a attribute value, then it will be called as shown with t ...@@ -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. * ```$fixture``` - current fixture array.
* ```$faker``` - faker generator instance * ```$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. After you set all needed fields in callback, you need to return $fixture array back from the callback.
......
...@@ -93,8 +93,8 @@ class Generator extends \yii\gii\Generator ...@@ -93,8 +93,8 @@ class Generator extends \yii\gii\Generator
return array_merge(parent::hints(), [ return array_merge(parent::hints(), [
'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>', '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.', '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>. '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.tbl_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> 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 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 will be generated, one for each matching table name; and the class names will be generated from
......
...@@ -135,7 +135,7 @@ class Command extends \yii\db\Command ...@@ -135,7 +135,7 @@ class Command extends \yii\db\Command
* For example, * 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. * The method will properly escape the column names and bind the values to be updated.
......
...@@ -232,6 +232,7 @@ Yii Framework 2 Change Log ...@@ -232,6 +232,7 @@ Yii Framework 2 Change Log
- Removed `yii\web\Controller::getCanonicalUrl`, use `yii\helpers\Url::canonical` instead. - 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 #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 #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 #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 `yii\jui\Widget::clientEventsMap` to `clientEventMap` (qiangxue)
- Chg: Renamed `ActiveRecord::getPopulatedRelations()` to `getRelatedRecords()` (qiangxue) - Chg: Renamed `ActiveRecord::getPopulatedRelations()` to `getRelatedRecords()` (qiangxue)
......
...@@ -16,7 +16,7 @@ use yii\di\Instance; ...@@ -16,7 +16,7 @@ use yii\di\Instance;
/** /**
* DbCache implements a cache application component by storing cached data in a database. * DbCache implements a cache application component by storing cached data in a database.
* *
* 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]]. * 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. * Please refer to [[Cache]] for common cache operations that are supported by DbCache.
...@@ -47,7 +47,7 @@ class DbCache extends Cache ...@@ -47,7 +47,7 @@ class DbCache extends Cache
* The table should be pre-created as follows: * The table should be pre-created as follows:
* *
* ~~~ * ~~~
* CREATE TABLE tbl_cache ( * CREATE TABLE cache (
* id char(128) NOT NULL PRIMARY KEY, * id char(128) NOT NULL PRIMARY KEY,
* expire int(11), * expire int(11),
* data BLOB * data BLOB
......
...@@ -33,7 +33,7 @@ use yii\helpers\FileHelper; ...@@ -33,7 +33,7 @@ use yii\helpers\FileHelper;
* create it as follows: * create it as follows:
* *
* ~~~ * ~~~
* CREATE TABLE tbl_migration ( * CREATE TABLE migration (
* version varchar(180) PRIMARY KEY, * version varchar(180) PRIMARY KEY,
* apply_time integer * apply_time integer
* ) * )
......
...@@ -39,7 +39,7 @@ use yii\di\Instance; ...@@ -39,7 +39,7 @@ use yii\di\Instance;
* ~~~ * ~~~
* $query = new Query; * $query = new Query;
* $provider = new ActiveDataProvider([ * $provider = new ActiveDataProvider([
* 'query' => $query->from('tbl_post'), * 'query' => $query->from('post'),
* 'pagination' => [ * 'pagination' => [
* 'pageSize' => 20, * 'pageSize' => 20,
* ], * ],
......
...@@ -30,7 +30,7 @@ use yii\helpers\ArrayHelper; ...@@ -30,7 +30,7 @@ use yii\helpers\ArrayHelper;
* ~~~ * ~~~
* $query = new Query; * $query = new Query;
* $provider = new ArrayDataProvider([ * $provider = new ArrayDataProvider([
* 'allModels' => $query->from('tbl_post')->all(), * 'allModels' => $query->from('post')->all(),
* 'sort' => [ * 'sort' => [
* 'attributes' => ['id', 'username', 'email'], * 'attributes' => ['id', 'username', 'email'],
* ], * ],
......
...@@ -26,11 +26,11 @@ use yii\di\Instance; ...@@ -26,11 +26,11 @@ use yii\di\Instance;
* *
* ~~~ * ~~~
* $count = Yii::$app->db->createCommand(' * $count = Yii::$app->db->createCommand('
* SELECT COUNT(*) FROM tbl_user WHERE status=:status * SELECT COUNT(*) FROM user WHERE status=:status
* ', [':status' => 1])->queryScalar(); * ', [':status' => 1])->queryScalar();
* *
* $dataProvider = new SqlDataProvider([ * $dataProvider = new SqlDataProvider([
* 'sql' => 'SELECT * FROM tbl_user WHERE status=:status', * 'sql' => 'SELECT * FROM user WHERE status=:status',
* 'params' => [':status' => 1], * 'params' => [':status' => 1],
* 'totalCount' => $count, * 'totalCount' => $count,
* 'sort' => [ * 'sort' => [
......
...@@ -357,7 +357,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface ...@@ -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. * // find all orders, eager loading "books", and sort the orders and books by the book names.
* Order::find()->joinWith([ * Order::find()->joinWith([
* 'books' => function ($query) { * 'books' => function ($query) {
* $query->orderBy('tbl_item.name'); * $query->orderBy('item.name');
* } * }
* ])->all(); * ])->all();
* ``` * ```
...@@ -628,7 +628,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface ...@@ -628,7 +628,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* public function getItems() * public function getItems()
* { * {
* return $this->hasMany(Item::className(), ['id' => 'item_id']) * return $this->hasMany(Item::className(), ['id' => 'item_id'])
* ->viaTable('tbl_order_item', ['order_id' => 'id']); * ->viaTable('order_item', ['order_id' => 'id']);
* } * }
* ``` * ```
* *
......
...@@ -21,8 +21,8 @@ use yii\helpers\StringHelper; ...@@ -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. * 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. * 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. * 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 `tbl_customer`. * 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 * 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`. * 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. * 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; ...@@ -38,7 +38,7 @@ use yii\helpers\StringHelper;
* { * {
* public static function tableName() * public static function tableName()
* { * {
* return 'tbl_customer'; * return 'customer';
* } * }
* } * }
* ``` * ```
...@@ -58,12 +58,12 @@ use yii\helpers\StringHelper; ...@@ -58,12 +58,12 @@ use yii\helpers\StringHelper;
* ```php * ```php
* $user = new User(); * $user = new User();
* $user->name = 'Qiang'; * $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 * // the following will retrieve the user 'CeBe' from the database
* $user = User::find()->where(['name' => 'CeBe'])->one(); * $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; * $orders = $user->orders;
* ``` * ```
* *
...@@ -131,7 +131,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -131,7 +131,7 @@ class ActiveRecord extends BaseActiveRecord
* Below is an example: * 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 * @param string $sql the SQL statement to be executed
......
...@@ -17,7 +17,7 @@ use yii\base\Object; ...@@ -17,7 +17,7 @@ use yii\base\Object;
* you can iterate it to obtain a batch of data in each iteration. For example, * you can iterate it to obtain a batch of data in each iteration. For example,
* *
* ```php * ```php
* $query = (new Query)->from('tbl_user'); * $query = (new Query)->from('user');
* foreach ($query->batch() as $i => $users) { * foreach ($query->batch() as $i => $users) {
* // $users represents the rows in the $i-th batch * // $users represents the rows in the $i-th batch
* } * }
......
...@@ -23,7 +23,7 @@ use yii\caching\Cache; ...@@ -23,7 +23,7 @@ use yii\caching\Cache;
* For example, * 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. * Command supports SQL statement preparation and parameter binding.
...@@ -36,7 +36,7 @@ use yii\caching\Cache; ...@@ -36,7 +36,7 @@ use yii\caching\Cache;
* [[update()]], etc. For example, * [[update()]], etc. For example,
* *
* ~~~ * ~~~
* $connection->createCommand()->insert('tbl_user', [ * $connection->createCommand()->insert('user', [
* 'name' => 'Sam', * 'name' => 'Sam',
* 'age' => 30, * 'age' => 30,
* ])->execute(); * ])->execute();
...@@ -438,7 +438,7 @@ class Command extends \yii\base\Component ...@@ -438,7 +438,7 @@ class Command extends \yii\base\Component
* For example, * For example,
* *
* ~~~ * ~~~
* $connection->createCommand()->insert('tbl_user', [ * $connection->createCommand()->insert('user', [
* 'name' => 'Sam', * 'name' => 'Sam',
* 'age' => 30, * 'age' => 30,
* ])->execute(); * ])->execute();
...@@ -465,7 +465,7 @@ class Command extends \yii\base\Component ...@@ -465,7 +465,7 @@ class Command extends \yii\base\Component
* For example, * For example,
* *
* ~~~ * ~~~
* $connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [ * $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30], * ['Tom', 30],
* ['Jane', 20], * ['Jane', 20],
* ['Linda', 25], * ['Linda', 25],
...@@ -491,7 +491,7 @@ class Command extends \yii\base\Component ...@@ -491,7 +491,7 @@ class Command extends \yii\base\Component
* For example, * 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. * 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 ...@@ -517,7 +517,7 @@ class Command extends \yii\base\Component
* For example, * 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. * The method will properly escape the table and column names.
......
...@@ -39,9 +39,9 @@ use yii\caching\Cache; ...@@ -39,9 +39,9 @@ use yii\caching\Cache;
* After the DB connection is established, one can execute SQL statements like the following: * 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(); * $posts = $command->queryAll();
* $command = $connection->createCommand('UPDATE tbl_post SET status=1'); * $command = $connection->createCommand('UPDATE post SET status=1');
* $command->execute(); * $command->execute();
* ~~~ * ~~~
* *
...@@ -50,7 +50,7 @@ use yii\caching\Cache; ...@@ -50,7 +50,7 @@ use yii\caching\Cache;
* to prevent SQL injection attacks. The following is an example: * 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']); * $command->bindValue(':id', $_GET['id']);
* $post = $command->query(); * $post = $command->query();
* ~~~ * ~~~
...@@ -221,7 +221,7 @@ class Connection extends Component ...@@ -221,7 +221,7 @@ class Connection extends Component
* as `{{%TableName}}`, then the percentage character `%` will be replaced with this * as `{{%TableName}}`, then the percentage character `%` will be replaced with this
* property value. For example, `{{%post}}` becomes `{{tbl_post}}`. * property value. For example, `{{%post}}` becomes `{{tbl_post}}`.
*/ */
public $tablePrefix = 'tbl_'; public $tablePrefix = '';
/** /**
* @var array mapping between PDO driver names and [[Schema]] classes. * @var array mapping between PDO driver names and [[Schema]] classes.
* The keys of the array are PDO driver names while the values the corresponding * The keys of the array are PDO driver names while the values the corresponding
......
...@@ -17,7 +17,7 @@ use yii\base\InvalidCallException; ...@@ -17,7 +17,7 @@ use yii\base\InvalidCallException;
* iterating through the reader. For example, * iterating through the reader. For example,
* *
* ~~~ * ~~~
* $command = $connection->createCommand('SELECT * FROM tbl_post'); * $command = $connection->createCommand('SELECT * FROM post');
* $reader = $command->query(); * $reader = $command->query();
* *
* while ($row = $reader->read()) { * while ($row = $reader->read()) {
......
...@@ -25,7 +25,7 @@ use yii\base\Component; ...@@ -25,7 +25,7 @@ use yii\base\Component;
* $query = new Query; * $query = new Query;
* // compose the query * // compose the query
* $query->select('id, name') * $query->select('id, name')
* ->from('tbl_user') * ->from('user')
* ->limit(10); * ->limit(10);
* // build and execute the query * // build and execute the query
* $rows = $query->all(); * $rows = $query->all();
...@@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface ...@@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface
*/ */
public $distinct; 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. * This is used to construct the FROM clause in a SQL statement.
* @see from() * @see from()
*/ */
...@@ -82,8 +82,8 @@ class Query extends Component implements QueryInterface ...@@ -82,8 +82,8 @@ class Query extends Component implements QueryInterface
* *
* ~~~ * ~~~
* [ * [
* ['INNER JOIN', 'tbl_user', 'tbl_user.id = author_id'], * ['INNER JOIN', 'user', 'user.id = author_id'],
* ['LEFT JOIN', 'tbl_team', 'tbl_team.id = team_id'], * ['LEFT JOIN', 'team', 'team.id = team_id'],
* ] * ]
* ~~~ * ~~~
*/ */
...@@ -143,9 +143,9 @@ class Query extends Component implements QueryInterface ...@@ -143,9 +143,9 @@ class Query extends Component implements QueryInterface
* For example, * For example,
* *
* ```php * ```php
* $query = (new Query)->from('tbl_user'); * $query = (new Query)->from('user');
* foreach ($query->batch() as $rows) { * 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 ...@@ -171,7 +171,7 @@ class Query extends Component implements QueryInterface
* only one row of data is returned. For example, * only one row of data is returned. For example,
* *
* ```php * ```php
* $query = (new Query)->from('tbl_user'); * $query = (new Query)->from('user');
* foreach ($query->each() as $row) { * foreach ($query->each() as $row) {
* } * }
* ``` * ```
...@@ -383,7 +383,7 @@ class Query extends Component implements QueryInterface ...@@ -383,7 +383,7 @@ class Query extends Component implements QueryInterface
* Sets the SELECT part of the query. * Sets the SELECT part of the query.
* @param string|array $columns the columns to be selected. * @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 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 * The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression). * (which means the column contains a DB expression).
* *
...@@ -422,9 +422,9 @@ class Query extends Component implements QueryInterface ...@@ -422,9 +422,9 @@ class Query extends Component implements QueryInterface
/** /**
* Sets the FROM part of the query. * 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'`) * @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. `['tbl_user', 'tbl_profile']`) specifying one or several table names. * or an array (e.g. `['user', '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'`). * 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 * 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). * (which means the table is given as a sub-query or DB expression).
* *
...@@ -581,7 +581,7 @@ class Query extends Component implements QueryInterface ...@@ -581,7 +581,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of 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 * 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). * (which means the table is given as a sub-query or DB expression).
* *
...@@ -606,7 +606,7 @@ class Query extends Component implements QueryInterface ...@@ -606,7 +606,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of 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 * 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). * (which means the table is given as a sub-query or DB expression).
* *
...@@ -631,7 +631,7 @@ class Query extends Component implements QueryInterface ...@@ -631,7 +631,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of 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 * 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). * (which means the table is given as a sub-query or DB expression).
* *
...@@ -656,7 +656,7 @@ class Query extends Component implements QueryInterface ...@@ -656,7 +656,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of 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 * 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). * (which means the table is given as a sub-query or DB expression).
* *
......
...@@ -94,7 +94,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -94,7 +94,7 @@ class QueryBuilder extends \yii\base\Object
* For example, * For example,
* *
* ~~~ * ~~~
* $sql = $queryBuilder->insert('tbl_user', [ * $sql = $queryBuilder->insert('user', [
* 'name' => 'Sam', * 'name' => 'Sam',
* 'age' => 30, * 'age' => 30,
* ], $params); * ], $params);
...@@ -141,7 +141,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -141,7 +141,7 @@ class QueryBuilder extends \yii\base\Object
* For example, * For example,
* *
* ~~~ * ~~~
* $sql = $queryBuilder->batchInsert('tbl_user', ['name', 'age'], [ * $sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
* ['Tom', 30], * ['Tom', 30],
* ['Jane', 20], * ['Jane', 20],
* ['Linda', 25], * ['Linda', 25],
...@@ -196,7 +196,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -196,7 +196,7 @@ class QueryBuilder extends \yii\base\Object
* *
* ~~~ * ~~~
* $params = []; * $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. * The method will properly escape the table and column names.
...@@ -242,7 +242,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -242,7 +242,7 @@ class QueryBuilder extends \yii\base\Object
* For example, * 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. * The method will properly escape the table and column names.
...@@ -276,7 +276,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -276,7 +276,7 @@ class QueryBuilder extends \yii\base\Object
* For example, * For example,
* *
* ~~~ * ~~~
* $sql = $queryBuilder->createTable('tbl_user', [ * $sql = $queryBuilder->createTable('user', [
* 'id' => 'pk', * 'id' => 'pk',
* 'name' => 'string', * 'name' => 'string',
* 'age' => 'integer', * 'age' => 'integer',
......
...@@ -46,7 +46,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -46,7 +46,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
* For example, * For example,
* *
* ~~~ * ~~~
* $connection->createCommand()->batchInsert('tbl_user', ['name', 'age'], [ * $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30], * ['Tom', 30],
* ['Jane', 20], * ['Jane', 20],
* ['Linda', 25], * ['Linda', 25],
......
...@@ -22,23 +22,23 @@ use yii\db\Query; ...@@ -22,23 +22,23 @@ use yii\db\Query;
* The database must contain the following two tables: * The database must contain the following two tables:
* *
* ~~~ * ~~~
* CREATE TABLE tbl_source_message ( * CREATE TABLE source_message (
* id INTEGER PRIMARY KEY AUTO_INCREMENT, * id INTEGER PRIMARY KEY AUTO_INCREMENT,
* category VARCHAR(32), * category VARCHAR(32),
* message TEXT * message TEXT
* ); * );
* *
* CREATE TABLE tbl_message ( * CREATE TABLE message (
* id INTEGER, * id INTEGER,
* language VARCHAR(16), * language VARCHAR(16),
* translation TEXT, * translation TEXT,
* PRIMARY KEY (id, language), * PRIMARY KEY (id, language),
* CONSTRAINT fk_message_source_message FOREIGN KEY (id) * 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]] * the translated messages. The name of these two tables can be customized by setting [[sourceMessageTable]]
* and [[messageTable]], respectively. * and [[messageTable]], respectively.
* *
......
...@@ -15,7 +15,7 @@ use yii\di\Instance; ...@@ -15,7 +15,7 @@ use yii\di\Instance;
/** /**
* DbTarget stores log messages in a database table. * 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]]. * must be pre-created. The table name can be changed by setting [[logTable]].
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
...@@ -34,7 +34,7 @@ class DbTarget extends Target ...@@ -34,7 +34,7 @@ class DbTarget extends Target
* The table should be pre-created as follows: * The table should be pre-created as follows:
* *
* ~~~ * ~~~
* CREATE TABLE tbl_log ( * CREATE TABLE log (
* id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, * id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
* level INTEGER, * level INTEGER,
* category VARCHAR(255), * category VARCHAR(255),
......
...@@ -39,15 +39,15 @@ class DbManager extends Manager ...@@ -39,15 +39,15 @@ class DbManager extends Manager
*/ */
public $db = 'db'; 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}}'; 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}}'; 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}}'; public $assignmentTable = '{{%auth_assignment}}';
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* @since 2.0 * @since 2.0
*/ */
drop table if exists [tbl_auth_assignment]; drop table if exists [auth_assignment];
drop table if exists [tbl_auth_item_child]; drop table if exists [auth_item_child];
drop table if exists [tbl_auth_item]; drop table if exists [auth_item];
create table [tbl_auth_item] create table [auth_item]
( (
[name] varchar(64) not null, [name] varchar(64) not null,
[type] integer not null, [type] integer not null,
...@@ -24,21 +24,21 @@ create table [tbl_auth_item] ...@@ -24,21 +24,21 @@ create table [tbl_auth_item]
key [type] ([type]) key [type] ([type])
); );
create table [tbl_auth_item_child] create table [auth_item_child]
( (
[parent] varchar(64) not null, [parent] varchar(64) not null,
[child] varchar(64) not null, [child] varchar(64) not null,
primary key ([parent],[child]), primary key ([parent],[child]),
foreign key ([parent]) 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 [tbl_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, [item_name] varchar(64) not null,
[user_id] varchar(64) not null, [user_id] varchar(64) not null,
[biz_rule] text, [biz_rule] text,
[data] text, [data] text,
primary key ([item_name],[user_id]), 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
); );
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* @since 2.0 * @since 2.0
*/ */
drop table if exists `tbl_auth_assignment`; drop table if exists `auth_assignment`;
drop table if exists `tbl_auth_item_child`; drop table if exists `auth_item_child`;
drop table if exists `tbl_auth_item`; drop table if exists `auth_item`;
create table `tbl_auth_item` create table `auth_item`
( (
`name` varchar(64) not null, `name` varchar(64) not null,
`type` integer not null, `type` integer not null,
...@@ -24,21 +24,21 @@ create table `tbl_auth_item` ...@@ -24,21 +24,21 @@ create table `tbl_auth_item`
key `type` (`type`) key `type` (`type`)
) engine InnoDB; ) engine InnoDB;
create table `tbl_auth_item_child` create table `auth_item_child`
( (
`parent` varchar(64) not null, `parent` varchar(64) not null,
`child` varchar(64) not null, `child` varchar(64) not null,
primary key (`parent`,`child`), primary key (`parent`,`child`),
foreign key (`parent`) 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 `tbl_auth_item` (`name`) on delete cascade on update cascade foreign key (`child`) references `auth_item` (`name`) on delete cascade on update cascade
) engine InnoDB; ) engine InnoDB;
create table `tbl_auth_assignment` create table `auth_assignment`
( (
`item_name` varchar(64) not null, `item_name` varchar(64) not null,
`user_id` varchar(64) not null, `user_id` varchar(64) not null,
`biz_rule` text, `biz_rule` text,
`data` text, `data` text,
primary key (`item_name`,`user_id`), 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; ) engine InnoDB;
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* @since 2.0 * @since 2.0
*/ */
drop table if exists "tbl_auth_assignment"; drop table if exists "auth_assignment";
drop table if exists "tbl_auth_item_child"; drop table if exists "auth_item_child";
drop table if exists "tbl_auth_item"; drop table if exists "auth_item";
create table "tbl_auth_item" create table "auth_item"
( (
"name" varchar(64) not null, "name" varchar(64) not null,
"type" integer not null, "type" integer not null,
...@@ -24,21 +24,21 @@ create table "tbl_auth_item" ...@@ -24,21 +24,21 @@ create table "tbl_auth_item"
key "type" ("type") key "type" ("type")
); );
create table "tbl_auth_item_child" create table "auth_item_child"
( (
"parent" varchar(64) not null, "parent" varchar(64) not null,
"child" varchar(64) not null, "child" varchar(64) not null,
primary key ("parent","child"), primary key ("parent","child"),
foreign key ("parent") 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 "tbl_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, "item_name" varchar(64) not null,
"user_id" varchar(64) not null, "user_id" varchar(64) not null,
"biz_rule" text, "biz_rule" text,
"data" text, "data" text,
primary key ("item_name","user_id"), 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
); );
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* @since 2.0 * @since 2.0
*/ */
drop table if exists "tbl_auth_assignment"; drop table if exists "auth_assignment";
drop table if exists "tbl_auth_item_child"; drop table if exists "auth_item_child";
drop table if exists "tbl_auth_item"; drop table if exists "auth_item";
create table "tbl_auth_item" create table "auth_item"
( (
"name" varchar(64) not null, "name" varchar(64) not null,
"type" integer not null, "type" integer not null,
...@@ -23,23 +23,23 @@ create table "tbl_auth_item" ...@@ -23,23 +23,23 @@ create table "tbl_auth_item"
primary key ("name") 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, "parent" varchar(64) not null,
"child" varchar(64) not null, "child" varchar(64) not null,
primary key ("parent","child"), primary key ("parent","child"),
foreign key ("parent") 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 "tbl_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, "item_name" varchar(64) not null,
"user_id" varchar(64) not null, "user_id" varchar(64) not null,
"biz_rule" text, "biz_rule" text,
"data" text, "data" text,
primary key ("item_name","user_id"), 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
); );
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
* @since 2.0 * @since 2.0
*/ */
drop table if exists 'tbl_auth_assignment'; drop table if exists 'auth_assignment';
drop table if exists 'tbl_auth_item_child'; drop table if exists 'auth_item_child';
drop table if exists 'tbl_auth_item'; drop table if exists 'auth_item';
create table 'tbl_auth_item' create table 'auth_item'
( (
"name" varchar(64) not null, "name" varchar(64) not null,
"type" integer not null, "type" integer not null,
...@@ -24,21 +24,21 @@ create table 'tbl_auth_item' ...@@ -24,21 +24,21 @@ create table 'tbl_auth_item'
key "type" ("type") key "type" ("type")
); );
create table 'tbl_auth_item_child' create table 'auth_item_child'
( (
"parent" varchar(64) not null, "parent" varchar(64) not null,
"child" varchar(64) not null, "child" varchar(64) not null,
primary key ("parent","child"), primary key ("parent","child"),
foreign key ("parent") 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 'tbl_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, "item_name" varchar(64) not null,
"user_id" varchar(64) not null, "user_id" varchar(64) not null,
"biz_rule" text, "biz_rule" text,
"data" text, "data" text,
primary key ("item_name","user_id"), 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
); );
...@@ -16,7 +16,7 @@ use yii\di\Instance; ...@@ -16,7 +16,7 @@ use yii\di\Instance;
/** /**
* DbSession extends [[Session]] by using database as session data storage. * 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]]. * 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: * The following example shows how you can configure the application to use DbSession:
...@@ -48,7 +48,7 @@ class DbSession extends Session ...@@ -48,7 +48,7 @@ class DbSession extends Session
* The table should be pre-created as follows: * The table should be pre-created as follows:
* *
* ~~~ * ~~~
* CREATE TABLE tbl_session * CREATE TABLE session
* ( * (
* id CHAR(40) NOT NULL PRIMARY KEY, * id CHAR(40) NOT NULL PRIMARY KEY,
* expire INTEGER, * expire INTEGER,
......
...@@ -17,7 +17,7 @@ class Category extends ActiveRecord ...@@ -17,7 +17,7 @@ class Category extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_category'; return 'category';
} }
public function getItems() public function getItems()
......
...@@ -25,7 +25,7 @@ class Customer extends ActiveRecord ...@@ -25,7 +25,7 @@ class Customer extends ActiveRecord
public static function tableName() public static function tableName()
{ {
return 'tbl_customer'; return 'customer';
} }
public function getProfile() public function getProfile()
...@@ -49,9 +49,9 @@ class Customer extends ActiveRecord ...@@ -49,9 +49,9 @@ class Customer extends ActiveRecord
/** @var ActiveQuery $rel */ /** @var ActiveQuery $rel */
$rel = $this->hasMany(Item::className(), ['id' => 'item_id']); $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 */ /** @var ActiveQuery $q */
$q->viaTable('tbl_order', ['customer_id' => 'id']); $q->viaTable('order', ['customer_id' => 'id']);
})->orderBy('id'); })->orderBy('id');
} }
......
...@@ -13,7 +13,7 @@ class Item extends ActiveRecord ...@@ -13,7 +13,7 @@ class Item extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_item'; return 'item';
} }
public function getCategory() public function getCategory()
......
...@@ -15,6 +15,6 @@ class NullValues extends ActiveRecord ...@@ -15,6 +15,6 @@ class NullValues extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_null_values'; return 'null_values';
} }
} }
...@@ -14,7 +14,7 @@ class Order extends ActiveRecord ...@@ -14,7 +14,7 @@ class Order extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_order'; return 'order';
} }
public function getCustomer() public function getCustomer()
...@@ -59,7 +59,7 @@ class Order extends ActiveRecord ...@@ -59,7 +59,7 @@ class Order extends ActiveRecord
public function getBooks() public function getBooks()
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) 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]); ->where(['category_id' => 1]);
} }
...@@ -67,7 +67,7 @@ class Order extends ActiveRecord ...@@ -67,7 +67,7 @@ class Order extends ActiveRecord
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) return $this->hasMany(Item::className(), ['id' => 'item_id'])
->onCondition(['category_id' => 1]) ->onCondition(['category_id' => 1])
->viaTable('tbl_order_item', ['order_id' => 'id']); ->viaTable('order_item', ['order_id' => 'id']);
} }
public function beforeSave($insert) public function beforeSave($insert)
......
...@@ -14,7 +14,7 @@ class OrderItem extends ActiveRecord ...@@ -14,7 +14,7 @@ class OrderItem extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_order_item'; return 'order_item';
} }
public function getOrder() public function getOrder()
......
...@@ -16,6 +16,6 @@ class Profile extends ActiveRecord ...@@ -16,6 +16,6 @@ class Profile extends ActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return 'tbl_profile'; return 'profile';
} }
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace yiiunit\data\ar; namespace yiiunit\data\ar;
/** /**
* Model representing tbl_type table * Model representing type table
* *
* @property int $int_col * @property int $int_col
* @property int $int_col2 DEFAULT 1 * @property int $int_col2 DEFAULT 1
...@@ -25,7 +25,7 @@ class Type extends ActiveRecord ...@@ -25,7 +25,7 @@ class Type extends ActiveRecord
*/ */
public static function tableName() public static function tableName()
{ {
return 'tbl_type'; return 'type';
} }
} }
\ No newline at end of file
...@@ -59,7 +59,7 @@ class Order extends ActiveRecord ...@@ -59,7 +59,7 @@ class Order extends ActiveRecord
// public function getBooks() // public function getBooks()
// { // {
// return $this->hasMany('Item', ['id' => 'item_id']) // return $this->hasMany('Item', ['id' => 'item_id'])
// ->viaTable('tbl_order_item', ['order_id' => 'id']) // ->viaTable('order_item', ['order_id' => 'id'])
// ->where(['category_id' => 1]); // ->where(['category_id' => 1]);
// } // }
......
...@@ -3,31 +3,31 @@ ...@@ -3,31 +3,31 @@
* The database setup in config.php is required to perform then relevant tests: * The database setup in config.php is required to perform then relevant tests:
*/ */
DROP TABLE IF EXISTS tbl_composite_fk; DROP TABLE IF EXISTS `composite_fk`;
DROP TABLE IF EXISTS tbl_order_item; DROP TABLE IF EXISTS `order_item`;
DROP TABLE IF EXISTS tbl_item; DROP TABLE IF EXISTS `item`;
DROP TABLE IF EXISTS tbl_order; DROP TABLE IF EXISTS `order`;
DROP TABLE IF EXISTS tbl_category; DROP TABLE IF EXISTS `category`;
DROP TABLE IF EXISTS tbl_customer; DROP TABLE IF EXISTS `customer`;
DROP TABLE IF EXISTS tbl_profile; DROP TABLE IF EXISTS `profile`;
DROP TABLE IF EXISTS tbl_null_values; DROP TABLE IF EXISTS `null_values`;
DROP TABLE IF EXISTS tbl_type; DROP TABLE IF EXISTS `type`;
DROP TABLE IF EXISTS tbl_constraints; DROP TABLE IF EXISTS `constraints`;
CREATE TABLE `tbl_constraints` CREATE TABLE `constraints`
( (
`id` integer not null, `id` integer not null,
`field1` varchar(255) `field1` varchar(255)
); );
CREATE TABLE `tbl_profile` ( CREATE TABLE `profile` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`description` varchar(128) NOT NULL, `description` varchar(128) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
CREATE TABLE `tbl_customer` ( CREATE TABLE `customer` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL, `email` varchar(128) NOT NULL,
`name` varchar(128), `name` varchar(128),
...@@ -37,40 +37,40 @@ CREATE TABLE `tbl_customer` ( ...@@ -37,40 +37,40 @@ CREATE TABLE `tbl_customer` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
CREATE TABLE `tbl_category` ( CREATE TABLE `category` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL, `name` varchar(128) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
CREATE TABLE `tbl_item` ( CREATE TABLE `item` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL, `name` varchar(128) NOT NULL,
`category_id` int(11) NOT NULL, `category_id` int(11) NOT NULL,
PRIMARY KEY (`id`), 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, `id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL, `customer_id` int(11) NOT NULL,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`total` decimal(10,0) NOT NULL, `total` decimal(10,0) NOT NULL,
PRIMARY KEY (`id`), 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, `order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL, `item_id` int(11) NOT NULL,
`quantity` int(11) NOT NULL, `quantity` int(11) NOT NULL,
`subtotal` decimal(10,0) NOT NULL, `subtotal` decimal(10,0) NOT NULL,
PRIMARY KEY (`order_id`,`item_id`), 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_order_id` FOREIGN KEY (`order_id`) REFERENCES `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_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, `id` INT(11) NOT NULL AUTO_INCREMENT,
`var1` INT NULL, `var1` INT NULL,
`var2` INT NULL, `var2` INT NULL,
...@@ -80,7 +80,7 @@ CREATE TABLE tbl_null_values ( ...@@ -80,7 +80,7 @@ CREATE TABLE tbl_null_values (
); );
CREATE TABLE `tbl_type` ( CREATE TABLE `type` (
`int_col` int(11) NOT NULL, `int_col` int(11) NOT NULL,
`int_col2` int(11) DEFAULT '1', `int_col2` int(11) DEFAULT '1',
`char_col` char(100) NOT NULL, `char_col` char(100) NOT NULL,
...@@ -96,37 +96,37 @@ CREATE TABLE `tbl_type` ( ...@@ -96,37 +96,37 @@ CREATE TABLE `tbl_type` (
`bool_col2` tinyint DEFAULT '1' `bool_col2` tinyint DEFAULT '1'
); );
CREATE TABLE `tbl_composite_fk` ( CREATE TABLE `composite_fk` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`order_id` int(11) NOT NULL, `order_id` int(11) NOT NULL,
`item_id` int(11) NOT NULL, `item_id` int(11) NOT NULL,
PRIMARY KEY (`id`), 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 `profile` (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3'); 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 `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 `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 ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books'); INSERT INTO `category` (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies'); 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 `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 `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 `item` (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2); INSERT INTO `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 ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); INSERT INTO `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 `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 (2, 1325502201, 40.0);
INSERT INTO tbl_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, 1, 1, 30.0);
INSERT INTO tbl_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 (1, 2, 2, 40.0);
INSERT INTO tbl_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, 4, 1, 10.0);
INSERT INTO tbl_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, 5, 1, 15.0);
INSERT INTO tbl_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 (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 (3, 2, 1, 40.0);
IF OBJECT_ID('[dbo].[tbl_order_item]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order_item]; IF OBJECT_ID('[dbo].[order_item]', 'U') IS NOT NULL DROP TABLE [dbo].[order_item];
IF OBJECT_ID('[dbo].[tbl_item]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_item]; IF OBJECT_ID('[dbo].[item]', 'U') IS NOT NULL DROP TABLE [dbo].[item];
IF OBJECT_ID('[dbo].[tbl_order]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order]; IF OBJECT_ID('[dbo].[order]', 'U') IS NOT NULL DROP TABLE [dbo].[order];
IF OBJECT_ID('[dbo].[tbl_category]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_category]; IF OBJECT_ID('[dbo].[category]', 'U') IS NOT NULL DROP TABLE [dbo].[category];
IF OBJECT_ID('[dbo].[tbl_customer]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_customer]; IF OBJECT_ID('[dbo].[customer]', 'U') IS NOT NULL DROP TABLE [dbo].[customer];
IF OBJECT_ID('[dbo].[tbl_profile]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_profile]; IF OBJECT_ID('[dbo].[profile]', 'U') IS NOT NULL DROP TABLE [dbo].[profile];
IF OBJECT_ID('[dbo].[tbl_type]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_type]; IF OBJECT_ID('[dbo].[type]', 'U') IS NOT NULL DROP TABLE [dbo].[type];
IF OBJECT_ID('[dbo].[tbl_null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_null_values]; 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, [id] [int] IDENTITY(1,1) NOT NULL,
[description] [varchar](128) NOT NULL, [description] [varchar](128) NOT NULL,
CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED ( CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED (
...@@ -15,7 +15,7 @@ CREATE TABLE [dbo].[tbl_profile] ( ...@@ -15,7 +15,7 @@ CREATE TABLE [dbo].[tbl_profile] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_customer] ( CREATE TABLE [dbo].[customer] (
[id] [int] IDENTITY(1,1) NOT NULL, [id] [int] IDENTITY(1,1) NOT NULL,
[email] [varchar](128) NOT NULL, [email] [varchar](128) NOT NULL,
[name] [varchar](128), [name] [varchar](128),
...@@ -27,7 +27,7 @@ CREATE TABLE [dbo].[tbl_customer] ( ...@@ -27,7 +27,7 @@ CREATE TABLE [dbo].[tbl_customer] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_category] ( CREATE TABLE [dbo].[category] (
[id] [int] IDENTITY(1,1) NOT NULL, [id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NOT NULL, [name] [varchar](128) NOT NULL,
CONSTRAINT [PK_category] PRIMARY KEY CLUSTERED ( CONSTRAINT [PK_category] PRIMARY KEY CLUSTERED (
...@@ -35,7 +35,7 @@ CREATE TABLE [dbo].[tbl_category] ( ...@@ -35,7 +35,7 @@ CREATE TABLE [dbo].[tbl_category] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_item] ( CREATE TABLE [dbo].[item] (
[id] [int] IDENTITY(1,1) NOT NULL, [id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NOT NULL, [name] [varchar](128) NOT NULL,
[category_id] [int] NOT NULL, [category_id] [int] NOT NULL,
...@@ -44,7 +44,7 @@ CREATE TABLE [dbo].[tbl_item] ( ...@@ -44,7 +44,7 @@ CREATE TABLE [dbo].[tbl_item] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_order] ( CREATE TABLE [dbo].[order] (
[id] [int] IDENTITY(1,1) NOT NULL, [id] [int] IDENTITY(1,1) NOT NULL,
[customer_id] [int] NOT NULL, [customer_id] [int] NOT NULL,
[created_at] [int] NOT NULL, [created_at] [int] NOT NULL,
...@@ -54,7 +54,7 @@ CREATE TABLE [dbo].[tbl_order] ( ...@@ -54,7 +54,7 @@ CREATE TABLE [dbo].[tbl_order] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_order_item] ( CREATE TABLE [dbo].[order_item] (
[order_id] [int] NOT NULL, [order_id] [int] NOT NULL,
[item_id] [int] NOT NULL, [item_id] [int] NOT NULL,
[quantity] [int] NOT NULL, [quantity] [int] NOT NULL,
...@@ -65,7 +65,7 @@ CREATE TABLE [dbo].[tbl_order_item] ( ...@@ -65,7 +65,7 @@ CREATE TABLE [dbo].[tbl_order_item] (
) ON [PRIMARY] ) ON [PRIMARY]
); );
CREATE TABLE [dbo].[tbl_null_values] ( CREATE TABLE [dbo].[null_values] (
id [int] UNSIGNED NOT NULL, id [int] UNSIGNED NOT NULL,
var1 [int] UNSIGNED NULL, var1 [int] UNSIGNED NULL,
var2 [int] NULL, var2 [int] NULL,
...@@ -74,7 +74,7 @@ CREATE TABLE [dbo].[tbl_null_values] ( ...@@ -74,7 +74,7 @@ CREATE TABLE [dbo].[tbl_null_values] (
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE [dbo].[tbl_type] ( CREATE TABLE [dbo].[type] (
[int_col] [int] NOT NULL, [int_col] [int] NOT NULL,
[int_col2] [int] DEFAULT '1', [int_col2] [int] DEFAULT '1',
[char_col] [char](100) NOT NULL, [char_col] [char](100) NOT NULL,
...@@ -89,29 +89,29 @@ CREATE TABLE [dbo].[tbl_type] ( ...@@ -89,29 +89,29 @@ CREATE TABLE [dbo].[tbl_type] (
[bool_col2] [tinyint] DEFAULT '1' [bool_col2] [tinyint] DEFAULT '1'
); );
INSERT INTO [dbo].[tbl_profile] ([description]) VALUES ('profile customer 1'); INSERT INTO [dbo].[profile] ([description]) VALUES ('profile customer 1');
INSERT INTO [dbo].[tbl_profile] ([description]) VALUES ('profile customer 3'); 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].[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].[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 ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO [dbo].[tbl_category] ([name]) VALUES ('Books'); INSERT INTO [dbo].[category] ([name]) VALUES ('Books');
INSERT INTO [dbo].[tbl_category] ([name]) VALUES ('Movies'); 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].[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].[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].[item] ([name], [category_id]) VALUES ('Ice Age', 2);
INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Toy Story', 2); INSERT INTO [dbo].[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 ('Cars', 2);
INSERT INTO [dbo].[tbl_order] ([customer_id], [created_at], [total]) VALUES (1, 1325282384, 110.0); INSERT INTO [dbo].[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].[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 (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].[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].[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].[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].[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].[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 (3, 2, 1, 40.0);
...@@ -4,28 +4,28 @@ ...@@ -4,28 +4,28 @@
* and create an account 'postgres/postgres' which owns this test database. * and create an account 'postgres/postgres' which owns this test database.
*/ */
DROP TABLE IF EXISTS tbl_order_item CASCADE; DROP TABLE IF EXISTS "order_item" CASCADE;
DROP TABLE IF EXISTS tbl_item CASCADE; DROP TABLE IF EXISTS "item" CASCADE;
DROP TABLE IF EXISTS tbl_order CASCADE; DROP TABLE IF EXISTS "order" CASCADE;
DROP TABLE IF EXISTS tbl_category CASCADE; DROP TABLE IF EXISTS "category" CASCADE;
DROP TABLE IF EXISTS tbl_customer CASCADE; DROP TABLE IF EXISTS "customer" CASCADE;
DROP TABLE IF EXISTS tbl_profile CASCADE; DROP TABLE IF EXISTS "profile" CASCADE;
DROP TABLE IF EXISTS tbl_type CASCADE; DROP TABLE IF EXISTS "type" CASCADE;
DROP TABLE IF EXISTS tbl_null_values CASCADE; DROP TABLE IF EXISTS "null_values" CASCADE;
DROP TABLE IF EXISTS tbl_constraints CASCADE; DROP TABLE IF EXISTS "constraints" CASCADE;
CREATE TABLE tbl_constraints CREATE TABLE "constraints"
( (
id integer not null, id integer not null,
field1 varchar(255) field1 varchar(255)
); );
CREATE TABLE tbl_profile ( CREATE TABLE "profile" (
id serial not null primary key, id serial not null primary key,
description varchar(128) NOT NULL description varchar(128) NOT NULL
); );
CREATE TABLE tbl_customer ( CREATE TABLE "customer" (
id serial not null primary key, id serial not null primary key,
email varchar(128) NOT NULL, email varchar(128) NOT NULL,
name varchar(128), name varchar(128),
...@@ -34,35 +34,35 @@ CREATE TABLE tbl_customer ( ...@@ -34,35 +34,35 @@ CREATE TABLE tbl_customer (
profile_id integer 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, id serial not null primary key,
name varchar(128) NOT NULL name varchar(128) NOT NULL
); );
CREATE TABLE tbl_item ( CREATE TABLE "item" (
id serial not null primary key, id serial not null primary key,
name varchar(128) NOT NULL, 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, 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, created_at integer NOT NULL,
total decimal(10,0) NOT NULL total decimal(10,0) NOT NULL
); );
CREATE TABLE tbl_order_item ( CREATE TABLE "order_item" (
order_id integer NOT NULL references tbl_order(id) on UPDATE CASCADE on DELETE CASCADE, order_id integer NOT NULL references "order"(id) on UPDATE CASCADE on DELETE CASCADE,
item_id integer NOT NULL references tbl_item(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, quantity integer NOT NULL,
subtotal decimal(10,0) NOT NULL, subtotal decimal(10,0) NOT NULL,
PRIMARY KEY (order_id,item_id) PRIMARY KEY (order_id,item_id)
); );
CREATE TABLE tbl_null_values ( CREATE TABLE "null_values" (
id INT NOT NULL, id INT NOT NULL,
var1 INT NULL, var1 INT NULL,
var2 INT NULL, var2 INT NULL,
...@@ -71,7 +71,7 @@ CREATE TABLE tbl_null_values ( ...@@ -71,7 +71,7 @@ CREATE TABLE tbl_null_values (
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_type ( CREATE TABLE "type" (
int_col integer NOT NULL, int_col integer NOT NULL,
int_col2 integer DEFAULT '1', int_col2 integer DEFAULT '1',
char_col char(100) NOT NULL, char_col char(100) NOT NULL,
...@@ -86,58 +86,58 @@ CREATE TABLE tbl_type ( ...@@ -86,58 +86,58 @@ CREATE TABLE tbl_type (
bool_col2 smallint DEFAULT '1' bool_col2 smallint DEFAULT '1'
); );
INSERT INTO tbl_profile (description) VALUES ('profile customer 1'); INSERT INTO "profile" (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3'); 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 "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 "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 ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies'); 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 "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 "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 "item" (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2); INSERT INTO "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 ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); INSERT INTO "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 "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 (2, 1325502201, 40.0);
INSERT INTO tbl_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, 1, 1, 30.0);
INSERT INTO tbl_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 (1, 2, 2, 40.0);
INSERT INTO tbl_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, 4, 1, 10.0);
INSERT INTO tbl_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, 5, 1, 15.0);
INSERT INTO tbl_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 (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 (3, 2, 1, 40.0);
/** /**
* (Postgres-)Database Schema for validator tests * (Postgres-)Database Schema for validator tests
*/ */
DROP TABLE IF EXISTS tbl_validator_main CASCADE; DROP TABLE IF EXISTS "validator_main" CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE; DROP TABLE IF EXISTS "validator_ref" CASCADE;
CREATE TABLE tbl_validator_main ( CREATE TABLE "validator_main" (
id integer not null primary key, id integer not null primary key,
field1 VARCHAR(255) field1 VARCHAR(255)
); );
CREATE TABLE tbl_validator_ref ( CREATE TABLE "validator_ref" (
id integer not null primary key, id integer not null primary key,
a_field VARCHAR(255), a_field VARCHAR(255),
ref integer ref integer
); );
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1'); INSERT INTO "validator_main" (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2'); INSERT INTO "validator_main" (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3'); INSERT INTO "validator_main" (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4'); INSERT INTO "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 "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 "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 "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 "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 "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_ref" (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
...@@ -3,23 +3,23 @@ ...@@ -3,23 +3,23 @@
* The database setup in config.php is required to perform then relevant tests: * The database setup in config.php is required to perform then relevant tests:
*/ */
DROP TABLE IF EXISTS tbl_composite_fk; DROP TABLE IF EXISTS "composite_fk";
DROP TABLE IF EXISTS tbl_order_item; DROP TABLE IF EXISTS "order_item";
DROP TABLE IF EXISTS tbl_item; DROP TABLE IF EXISTS "item";
DROP TABLE IF EXISTS tbl_order; DROP TABLE IF EXISTS "order";
DROP TABLE IF EXISTS tbl_category; DROP TABLE IF EXISTS "category";
DROP TABLE IF EXISTS tbl_customer; DROP TABLE IF EXISTS "customer";
DROP TABLE IF EXISTS tbl_profile; DROP TABLE IF EXISTS "profile";
DROP TABLE IF EXISTS tbl_type; DROP TABLE IF EXISTS "type";
DROP TABLE IF EXISTS tbl_null_values; DROP TABLE IF EXISTS "null_values";
CREATE TABLE tbl_profile ( CREATE TABLE "profile" (
id INTEGER NOT NULL, id INTEGER NOT NULL,
description varchar(128) NOT NULL, description varchar(128) NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_customer ( CREATE TABLE "customer" (
id INTEGER NOT NULL, id INTEGER NOT NULL,
email varchar(128) NOT NULL, email varchar(128) NOT NULL,
name varchar(128), name varchar(128),
...@@ -29,20 +29,20 @@ CREATE TABLE tbl_customer ( ...@@ -29,20 +29,20 @@ CREATE TABLE tbl_customer (
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_category ( CREATE TABLE "category" (
id INTEGER NOT NULL, id INTEGER NOT NULL,
name varchar(128) NOT NULL, name varchar(128) NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_item ( CREATE TABLE "item" (
id INTEGER NOT NULL, id INTEGER NOT NULL,
name varchar(128) NOT NULL, name varchar(128) NOT NULL,
category_id INTEGER NOT NULL, category_id INTEGER NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_order ( CREATE TABLE "order" (
id INTEGER NOT NULL, id INTEGER NOT NULL,
customer_id INTEGER NOT NULL, customer_id INTEGER NOT NULL,
created_at INTEGER NOT NULL, created_at INTEGER NOT NULL,
...@@ -50,7 +50,7 @@ CREATE TABLE tbl_order ( ...@@ -50,7 +50,7 @@ CREATE TABLE tbl_order (
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE TABLE tbl_order_item ( CREATE TABLE "order_item" (
order_id INTEGER NOT NULL, order_id INTEGER NOT NULL,
item_id INTEGER NOT NULL, item_id INTEGER NOT NULL,
quantity INTEGER NOT NULL, quantity INTEGER NOT NULL,
...@@ -58,15 +58,15 @@ CREATE TABLE tbl_order_item ( ...@@ -58,15 +58,15 @@ CREATE TABLE tbl_order_item (
PRIMARY KEY (order_id, item_id) PRIMARY KEY (order_id, item_id)
); );
CREATE TABLE `tbl_composite_fk` ( CREATE TABLE "composite_fk" (
`id` int(11) NOT NULL, id int(11) NOT NULL,
`order_id` int(11) NOT NULL, order_id int(11) NOT NULL,
`item_id` int(11) NOT NULL, item_id int(11) NOT NULL,
PRIMARY KEY (`id`), 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 INTEGER UNSIGNED PRIMARY KEY NOT NULL, id INTEGER UNSIGNED PRIMARY KEY NOT NULL,
var1 INTEGER UNSIGNED, var1 INTEGER UNSIGNED,
var2 INTEGER, var2 INTEGER,
...@@ -74,7 +74,7 @@ CREATE TABLE tbl_null_values ( ...@@ -74,7 +74,7 @@ CREATE TABLE tbl_null_values (
stringcol VARCHAR(32) DEFAULT NULL stringcol VARCHAR(32) DEFAULT NULL
); );
CREATE TABLE tbl_type ( CREATE TABLE "type" (
int_col INTEGER NOT NULL, int_col INTEGER NOT NULL,
int_col2 INTEGER DEFAULT '1', int_col2 INTEGER DEFAULT '1',
char_col char(100) NOT NULL, char_col char(100) NOT NULL,
...@@ -89,58 +89,58 @@ CREATE TABLE tbl_type ( ...@@ -89,58 +89,58 @@ CREATE TABLE tbl_type (
bool_col2 tinyint(1) DEFAULT '1' bool_col2 tinyint(1) DEFAULT '1'
); );
INSERT INTO tbl_profile (description) VALUES ('profile customer 1'); INSERT INTO "profile" (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3'); 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 "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 "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 ('user3@example.com', 'user3', 'address3', 2, 2);
INSERT INTO tbl_category (name) VALUES ('Books'); INSERT INTO "category" (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies'); 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 "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 "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 "item" (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2); INSERT INTO "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 ('Cars', 2);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0); INSERT INTO "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 "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 (2, 1325502201, 40.0);
INSERT INTO tbl_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, 1, 1, 30.0);
INSERT INTO tbl_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 (1, 2, 2, 40.0);
INSERT INTO tbl_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, 4, 1, 10.0);
INSERT INTO tbl_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, 5, 1, 15.0);
INSERT INTO tbl_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 (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 (3, 2, 1, 40.0);
/** /**
* (SqLite-)Database Schema for validator tests * (SqLite-)Database Schema for validator tests
*/ */
DROP TABLE IF EXISTS tbl_validator_main; DROP TABLE IF EXISTS "validator_main";
DROP TABLE IF EXISTS tbl_validator_ref; DROP TABLE IF EXISTS "validator_ref";
CREATE TABLE tbl_validator_main ( CREATE TABLE "validator_main" (
id INTEGER PRIMARY KEY , id INTEGER PRIMARY KEY ,
field1 VARCHAR(255) field1 VARCHAR(255)
); );
CREATE TABLE tbl_validator_ref ( CREATE TABLE "validator_ref" (
id INTEGER PRIMARY KEY , id INTEGER PRIMARY KEY ,
a_field VARCHAR(255), a_field VARCHAR(255),
ref INT(11) ref INT(11)
); );
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1'); INSERT INTO "validator_main" (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2'); INSERT INTO "validator_main" (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3'); INSERT INTO "validator_main" (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4'); INSERT INTO "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 "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 "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 "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 "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 "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_ref" (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
...@@ -10,7 +10,7 @@ class ValidatorTestMainModel extends ActiveRecord ...@@ -10,7 +10,7 @@ class ValidatorTestMainModel extends ActiveRecord
public static function tableName() public static function tableName()
{ {
return 'tbl_validator_main'; return 'validator_main';
} }
public function getReferences() public function getReferences()
......
...@@ -12,7 +12,7 @@ class ValidatorTestRefModel extends ActiveRecord ...@@ -12,7 +12,7 @@ class ValidatorTestRefModel extends ActiveRecord
public static function tableName() public static function tableName()
{ {
return 'tbl_validator_ref'; return 'validator_ref';
} }
public function getMain() public function getMain()
......
...@@ -102,8 +102,8 @@ class ActiveRecordTest extends ElasticSearchTestCase ...@@ -102,8 +102,8 @@ class ActiveRecordTest extends ElasticSearchTestCase
$customer->setAttributes(['email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2], false); $customer->setAttributes(['email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2], false);
$customer->save(false); $customer->save(false);
// INSERT INTO tbl_category (name) VALUES ('Books'); // INSERT INTO category (name) VALUES ('Books');
// INSERT INTO tbl_category (name) VALUES ('Movies'); // INSERT INTO category (name) VALUES ('Movies');
$item = new Item(); $item = new Item();
$item->id = 1; $item->id = 1;
......
...@@ -71,8 +71,8 @@ class ActiveRecordTest extends RedisTestCase ...@@ -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->setAttributes(['email' => 'user3@example.com', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
$customer->save(false); $customer->save(false);
// INSERT INTO tbl_category (name) VALUES ('Books'); // INSERT INTO category (name) VALUES ('Books');
// INSERT INTO tbl_category (name) VALUES ('Movies'); // INSERT INTO category (name) VALUES ('Movies');
$item = new Item(); $item = new Item();
$item->setAttributes(['name' => 'Agile Web Application Development with Yii1.1 and PHP5', 'category_id' => 1], false); $item->setAttributes(['name' => 'Agile Web Application Development with Yii1.1 and PHP5', 'category_id' => 1], false);
......
...@@ -28,8 +28,8 @@ class QueryTest extends SphinxTestCase ...@@ -28,8 +28,8 @@ class QueryTest extends SphinxTestCase
public function testFrom() public function testFrom()
{ {
$query = new Query; $query = new Query;
$query->from('tbl_user'); $query->from('user');
$this->assertEquals(['tbl_user'], $query->from); $this->assertEquals(['user'], $query->from);
} }
public function testMatch() public function testMatch()
......
...@@ -23,7 +23,7 @@ class DbCacheTest extends CacheTestCase ...@@ -23,7 +23,7 @@ class DbCacheTest extends CacheTestCase
parent::setUp(); parent::setUp();
$this->getConnection()->createCommand(" $this->getConnection()->createCommand("
CREATE TABLE IF NOT EXISTS tbl_cache ( CREATE TABLE IF NOT EXISTS cache (
id char(128) NOT NULL, id char(128) NOT NULL,
expire int(11) DEFAULT NULL, expire int(11) DEFAULT NULL,
data LONGBLOB, data LONGBLOB,
......
...@@ -126,7 +126,7 @@ class ActiveDataProviderTest extends DatabaseTestCase ...@@ -126,7 +126,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query; $query = new Query;
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'db' => $this->getConnection(), 'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'), 'query' => $query->from('order')->orderBy('id'),
]); ]);
$orders = $provider->getModels(); $orders = $provider->getModels();
$this->assertEquals(3, count($orders)); $this->assertEquals(3, count($orders));
...@@ -136,7 +136,7 @@ class ActiveDataProviderTest extends DatabaseTestCase ...@@ -136,7 +136,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query; $query = new Query;
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'db' => $this->getConnection(), 'db' => $this->getConnection(),
'query' => $query->from('tbl_order'), 'query' => $query->from('order'),
'pagination' => [ 'pagination' => [
'pageSize' => 2, 'pageSize' => 2,
] ]
...@@ -150,7 +150,7 @@ class ActiveDataProviderTest extends DatabaseTestCase ...@@ -150,7 +150,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query; $query = new Query;
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'db' => $this->getConnection(), 'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'), 'query' => $query->from('order')->orderBy('id'),
]); ]);
$this->assertEquals(3, count($provider->getModels())); $this->assertEquals(3, count($provider->getModels()));
...@@ -165,7 +165,7 @@ class ActiveDataProviderTest extends DatabaseTestCase ...@@ -165,7 +165,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query = new Query; $query = new Query;
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([
'db' => $this->getConnection(), 'db' => $this->getConnection(),
'query' => $query->from('tbl_order')->orderBy('id'), 'query' => $query->from('order')->orderBy('id'),
]); ]);
$pagination = $provider->getPagination(); $pagination = $provider->getPagination();
$this->assertEquals(0, $pagination->getPageCount()); $this->assertEquals(0, $pagination->getPageCount());
......
...@@ -104,16 +104,16 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -104,16 +104,16 @@ class ActiveRecordTest extends DatabaseTestCase
public function testFindBySql() public function testFindBySql()
{ {
// find one // 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->assertTrue($customer instanceof Customer);
$this->assertEquals('user3', $customer->name); $this->assertEquals('user3', $customer->name);
// find all // find all
$customers = Customer::findBySql('SELECT * FROM tbl_customer')->all(); $customers = Customer::findBySql('SELECT * FROM customer')->all();
$this->assertEquals(3, count($customers)); $this->assertEquals(3, count($customers));
// find with parameter binding // 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->assertTrue($customer instanceof Customer);
$this->assertEquals('user2', $customer->name); $this->assertEquals('user2', $customer->name);
} }
...@@ -269,7 +269,7 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -269,7 +269,7 @@ class ActiveRecordTest extends DatabaseTestCase
public function testJoinWith() public function testJoinWith()
{ {
// left join and eager loading // 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(3, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id); $this->assertEquals(3, $orders[1]->id);
...@@ -281,9 +281,9 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -281,9 +281,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering and eager loading // inner join filtering and eager loading
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'customer' => function ($query) { '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, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id); $this->assertEquals(3, $orders[1]->id);
...@@ -293,9 +293,9 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -293,9 +293,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering, eager loading, conditions on both primary and relation // inner join filtering, eager loading, conditions on both primary and relation
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'customer' => function ($query) { '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(1, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertTrue($orders[0]->isRelationPopulated('customer')); $this->assertTrue($orders[0]->isRelationPopulated('customer'));
...@@ -303,9 +303,9 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -303,9 +303,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading // inner join filtering without eager loading
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'customer' => function ($query) { '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, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id); $this->assertEquals(3, $orders[1]->id);
...@@ -315,15 +315,15 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -315,15 +315,15 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading, conditions on both primary and relation // inner join filtering without eager loading, conditions on both primary and relation
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'customer' => function ($query) { '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(1, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertFalse($orders[0]->isRelationPopulated('customer')); $this->assertFalse($orders[0]->isRelationPopulated('customer'));
// join with via-relation // 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(2, count($orders));
$this->assertEquals(1, $orders[0]->id); $this->assertEquals(1, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id); $this->assertEquals(3, $orders[1]->id);
...@@ -335,12 +335,12 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -335,12 +335,12 @@ class ActiveRecordTest extends DatabaseTestCase
// join with sub-relation // join with sub-relation
$orders = Order::find()->innerJoinWith([ $orders = Order::find()->innerJoinWith([
'items' => function ($q) { 'items' => function ($q) {
$q->orderBy('tbl_item.id'); $q->orderBy('item.id');
}, },
'items.category' => function ($q) { '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->assertEquals(1, count($orders));
$this->assertTrue($orders[0]->isRelationPopulated('items')); $this->assertTrue($orders[0]->isRelationPopulated('items'));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
...@@ -351,9 +351,9 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -351,9 +351,9 @@ class ActiveRecordTest extends DatabaseTestCase
// join with table alias // join with table alias
$orders = Order::find()->joinWith([ $orders = Order::find()->joinWith([
'customer' => function ($q) { '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(3, count($orders));
$this->assertEquals(2, $orders[0]->id); $this->assertEquals(2, $orders[0]->id);
$this->assertEquals(3, $orders[1]->id); $this->assertEquals(3, $orders[1]->id);
...@@ -363,7 +363,7 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -363,7 +363,7 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertTrue($orders[2]->isRelationPopulated('customer')); $this->assertTrue($orders[2]->isRelationPopulated('customer'));
// join with ON condition // 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(3, count($orders));
$this->assertEquals(1, $orders[0]->id); $this->assertEquals(1, $orders[0]->id);
$this->assertEquals(2, $orders[1]->id); $this->assertEquals(2, $orders[1]->id);
...@@ -411,22 +411,22 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -411,22 +411,22 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals(1, $customer->id); $this->assertEquals(1, $customer->id);
$order = Order::find()->joinWith([ $order = Order::find()->joinWith([
'items' => function ($q) { 'items' => function ($q) {
$q->from(['items' => 'tbl_item']) $q->from(['items' => 'item'])
->orderBy('items.id'); ->orderBy('items.id');
}, },
])->orderBy('tbl_order.id')->one(); ])->orderBy('order.id')->one();
} }
public function testJoinWithAndScope() public function testJoinWithAndScope()
{ {
// hasOne inner join // 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, count($customers));
$this->assertEquals(1, $customers[0]->id); $this->assertEquals(1, $customers[0]->id);
$this->assertTrue($customers[0]->isRelationPopulated('profile')); $this->assertTrue($customers[0]->isRelationPopulated('profile'));
// hasOne outer join // 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(2, count($customers));
$this->assertEquals(1, $customers[0]->id); $this->assertEquals(1, $customers[0]->id);
$this->assertEquals(2, $customers[1]->id); $this->assertEquals(2, $customers[1]->id);
...@@ -438,9 +438,9 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -438,9 +438,9 @@ class ActiveRecordTest extends DatabaseTestCase
// hasMany // hasMany
$customers = Customer::find()->active()->joinWith([ $customers = Customer::find()->active()->joinWith([
'orders' => function ($q) { '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, count($customers));
$this->assertEquals(2, $customers[0]->id); $this->assertEquals(2, $customers[0]->id);
$this->assertEquals(1, $customers[1]->id); $this->assertEquals(1, $customers[1]->id);
......
...@@ -31,7 +31,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -31,7 +31,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// initialize property test // initialize property test
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->orderBy('id'); $query->from('customer')->orderBy('id');
$result = $query->batch(2, $db); $result = $query->batch(2, $db);
$this->assertTrue($result instanceof BatchQueryResult); $this->assertTrue($result instanceof BatchQueryResult);
$this->assertEquals(2, $result->batchSize); $this->assertEquals(2, $result->batchSize);
...@@ -39,7 +39,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -39,7 +39,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// normal query // normal query
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->orderBy('id'); $query->from('customer')->orderBy('id');
$allRows = []; $allRows = [];
$batch = $query->batch(2, $db); $batch = $query->batch(2, $db);
foreach ($batch as $rows) { foreach ($batch as $rows) {
...@@ -60,7 +60,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -60,7 +60,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// empty query // empty query
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->where(['id' => 100]); $query->from('customer')->where(['id' => 100]);
$allRows = []; $allRows = [];
$batch = $query->batch(2, $db); $batch = $query->batch(2, $db);
foreach ($batch as $rows) { foreach ($batch as $rows) {
...@@ -70,7 +70,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -70,7 +70,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// query with index // query with index
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->indexBy('name'); $query->from('customer')->indexBy('name');
$allRows = []; $allRows = [];
foreach ($query->batch(2, $db) as $rows) { foreach ($query->batch(2, $db) as $rows) {
$allRows = array_merge($allRows, $rows); $allRows = array_merge($allRows, $rows);
...@@ -82,7 +82,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -82,7 +82,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each // each
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->orderBy('id'); $query->from('customer')->orderBy('id');
$allRows = []; $allRows = [];
foreach ($query->each(100, $db) as $rows) { foreach ($query->each(100, $db) as $rows) {
$allRows[] = $rows; $allRows[] = $rows;
...@@ -94,7 +94,7 @@ class BatchQueryResultTest extends DatabaseTestCase ...@@ -94,7 +94,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each with key // each with key
$query = new Query(); $query = new Query();
$query->from('tbl_customer')->orderBy('id')->indexBy('name'); $query->from('customer')->orderBy('id')->indexBy('name');
$allRows = []; $allRows = [];
foreach ($query->each(100, $db) as $key => $row) { foreach ($query->each(100, $db) as $key => $row) {
$allRows[$key] = $row; $allRows[$key] = $row;
......
...@@ -19,7 +19,7 @@ class CommandTest extends DatabaseTestCase ...@@ -19,7 +19,7 @@ class CommandTest extends DatabaseTestCase
$this->assertEquals(null, $command->sql); $this->assertEquals(null, $command->sql);
// string // string
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$this->assertEquals($sql, $command->sql); $this->assertEquals($sql, $command->sql);
} }
...@@ -28,11 +28,11 @@ class CommandTest extends DatabaseTestCase ...@@ -28,11 +28,11 @@ class CommandTest extends DatabaseTestCase
{ {
$db = $this->getConnection(false); $db = $this->getConnection(false);
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$this->assertEquals($sql, $command->sql); $this->assertEquals($sql, $command->sql);
$sql2 = 'SELECT * FROM tbl_order'; $sql2 = 'SELECT * FROM order';
$command->sql = $sql2; $command->sql = $sql2;
$this->assertEquals($sql2, $command->sql); $this->assertEquals($sql2, $command->sql);
} }
...@@ -41,16 +41,16 @@ class CommandTest extends DatabaseTestCase ...@@ -41,16 +41,16 @@ class CommandTest extends DatabaseTestCase
{ {
$db = $this->getConnection(false); $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); $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() public function testPrepareCancel()
{ {
$db = $this->getConnection(false); $db = $this->getConnection(false);
$command = $db->createCommand('SELECT * FROM tbl_customer'); $command = $db->createCommand('SELECT * FROM customer');
$this->assertEquals(null, $command->pdoStatement); $this->assertEquals(null, $command->pdoStatement);
$command->prepare(); $command->prepare();
$this->assertNotEquals(null, $command->pdoStatement); $this->assertNotEquals(null, $command->pdoStatement);
...@@ -62,11 +62,11 @@ class CommandTest extends DatabaseTestCase ...@@ -62,11 +62,11 @@ class CommandTest extends DatabaseTestCase
{ {
$db = $this->getConnection(); $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); $command = $db->createCommand($sql);
$this->assertEquals(1, $command->execute()); $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); $command = $db->createCommand($sql);
$this->assertEquals(1, $command->queryScalar()); $this->assertEquals(1, $command->queryScalar());
...@@ -80,55 +80,55 @@ class CommandTest extends DatabaseTestCase ...@@ -80,55 +80,55 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection(); $db = $this->getConnection();
// query // query
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$reader = $db->createCommand($sql)->query(); $reader = $db->createCommand($sql)->query();
$this->assertTrue($reader instanceof DataReader); $this->assertTrue($reader instanceof DataReader);
// queryAll // queryAll
$rows = $db->createCommand('SELECT * FROM tbl_customer')->queryAll(); $rows = $db->createCommand('SELECT * FROM customer')->queryAll();
$this->assertEquals(3, count($rows)); $this->assertEquals(3, count($rows));
$row = $rows[2]; $row = $rows[2];
$this->assertEquals(3, $row['id']); $this->assertEquals(3, $row['id']);
$this->assertEquals('user3', $row['name']); $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); $this->assertEquals([], $rows);
// queryOne // queryOne
$sql = 'SELECT * FROM tbl_customer ORDER BY id'; $sql = 'SELECT * FROM customer ORDER BY id';
$row = $db->createCommand($sql)->queryOne(); $row = $db->createCommand($sql)->queryOne();
$this->assertEquals(1, $row['id']); $this->assertEquals(1, $row['id']);
$this->assertEquals('user1', $row['name']); $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 = $db->createCommand($sql);
$command->prepare(); $command->prepare();
$row = $command->queryOne(); $row = $command->queryOne();
$this->assertEquals(1, $row['id']); $this->assertEquals(1, $row['id']);
$this->assertEquals('user1', $row['name']); $this->assertEquals('user1', $row['name']);
$sql = 'SELECT * FROM tbl_customer WHERE id=10'; $sql = 'SELECT * FROM customer WHERE id=10';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$this->assertFalse($command->queryOne()); $this->assertFalse($command->queryOne());
// queryColumn // queryColumn
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$column = $db->createCommand($sql)->queryColumn(); $column = $db->createCommand($sql)->queryColumn();
$this->assertEquals(range(1, 3), $column); $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()); $this->assertEquals([], $command->queryColumn());
// queryScalar // queryScalar
$sql = 'SELECT * FROM tbl_customer ORDER BY id'; $sql = 'SELECT * FROM customer ORDER BY id';
$this->assertEquals($db->createCommand($sql)->queryScalar(), 1); $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 = $db->createCommand($sql);
$command->prepare(); $command->prepare();
$this->assertEquals(1, $command->queryScalar()); $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()); $this->assertFalse($command->queryScalar());
$command = $db->createCommand('bad SQL'); $command = $db->createCommand('bad SQL');
...@@ -141,7 +141,7 @@ class CommandTest extends DatabaseTestCase ...@@ -141,7 +141,7 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection(); $db = $this->getConnection();
// bindParam // 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); $command = $db->createCommand($sql);
$email = 'user4@example.com'; $email = 'user4@example.com';
$name = 'user4'; $name = 'user4';
...@@ -151,12 +151,12 @@ class CommandTest extends DatabaseTestCase ...@@ -151,12 +151,12 @@ class CommandTest extends DatabaseTestCase
$command->bindParam(':address', $address); $command->bindParam(':address', $address);
$command->execute(); $command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email'; $sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindParam(':email', $email); $command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar()); $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); $command = $db->createCommand($sql);
$intCol = 123; $intCol = 123;
$charCol = 'abc'; $charCol = 'abc';
...@@ -172,7 +172,7 @@ class CommandTest extends DatabaseTestCase ...@@ -172,7 +172,7 @@ class CommandTest extends DatabaseTestCase
$command->bindParam(':bool_col', $boolCol); $command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute()); $this->assertEquals(1, $command->execute());
$sql = 'SELECT * FROM tbl_type'; $sql = 'SELECT * FROM type';
$row = $db->createCommand($sql)->queryOne(); $row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']); $this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($charCol, $row['char_col']); $this->assertEquals($charCol, $row['char_col']);
...@@ -181,12 +181,12 @@ class CommandTest extends DatabaseTestCase ...@@ -181,12 +181,12 @@ class CommandTest extends DatabaseTestCase
$this->assertEquals($numericCol, $row['numeric_col']); $this->assertEquals($numericCol, $row['numeric_col']);
// bindValue // 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 = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com'); $command->bindValue(':email', 'user5@example.com');
$command->execute(); $command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name'; $sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindValue(':name', 'user5'); $command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar()); $this->assertEquals('user5@example.com', $command->queryScalar());
...@@ -197,20 +197,20 @@ class CommandTest extends DatabaseTestCase ...@@ -197,20 +197,20 @@ class CommandTest extends DatabaseTestCase
$db = $this->getConnection(); $db = $this->getConnection();
// default: FETCH_ASSOC // default: FETCH_ASSOC
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$result = $command->queryOne(); $result = $command->queryOne();
$this->assertTrue(is_array($result) && isset($result['id'])); $this->assertTrue(is_array($result) && isset($result['id']));
// FETCH_OBJ, customized via fetchMode property // FETCH_OBJ, customized via fetchMode property
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->fetchMode = \PDO::FETCH_OBJ; $command->fetchMode = \PDO::FETCH_OBJ;
$result = $command->queryOne(); $result = $command->queryOne();
$this->assertTrue(is_object($result)); $this->assertTrue(is_object($result));
// FETCH_NUM, customized in query method // FETCH_NUM, customized in query method
$sql = 'SELECT * FROM tbl_customer'; $sql = 'SELECT * FROM customer';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$result = $command->queryOne([], \PDO::FETCH_NUM); $result = $command->queryOne([], \PDO::FETCH_NUM);
$this->assertTrue(is_array($result) && isset($result[0])); $this->assertTrue(is_array($result) && isset($result[0]));
...@@ -219,7 +219,7 @@ class CommandTest extends DatabaseTestCase ...@@ -219,7 +219,7 @@ class CommandTest extends DatabaseTestCase
public function testBatchInsert() public function testBatchInsert()
{ {
$command = $this->getConnection()->createCommand(); $command = $this->getConnection()->createCommand();
$command->batchInsert('tbl_customer', $command->batchInsert('customer',
['email', 'name', 'address'], [ ['email', 'name', 'address'], [
['t1@example.com', 't1', 't1 address'], ['t1@example.com', 't1', 't1 address'],
['t2@example.com', null, false], ['t2@example.com', null, false],
......
...@@ -115,7 +115,7 @@ class QueryBuilderTest extends DatabaseTestCase ...@@ -115,7 +115,7 @@ class QueryBuilderTest extends DatabaseTestCase
public function testAddDropPrimaryKey() public function testAddDropPrimaryKey()
{ {
$tableName = 'tbl_constraints'; $tableName = 'constraints';
$pkeyName = $tableName . "_pkey"; $pkeyName = $tableName . "_pkey";
// ADD // ADD
......
...@@ -29,8 +29,8 @@ class QueryTest extends DatabaseTestCase ...@@ -29,8 +29,8 @@ class QueryTest extends DatabaseTestCase
public function testFrom() public function testFrom()
{ {
$query = new Query; $query = new Query;
$query->from('tbl_user'); $query->from('user');
$this->assertEquals(['tbl_user'], $query->from); $this->assertEquals(['user'], $query->from);
} }
public function testWhere() public function testWhere()
...@@ -117,10 +117,10 @@ class QueryTest extends DatabaseTestCase ...@@ -117,10 +117,10 @@ class QueryTest extends DatabaseTestCase
{ {
$db = $this->getConnection(); $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']); $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); $this->assertFalse($result);
} }
} }
...@@ -17,12 +17,12 @@ class SchemaTest extends DatabaseTestCase ...@@ -17,12 +17,12 @@ class SchemaTest extends DatabaseTestCase
$schema = $this->getConnection()->schema; $schema = $this->getConnection()->schema;
$tables = $schema->getTableNames(); $tables = $schema->getTableNames();
$this->assertTrue(in_array('tbl_customer', $tables)); $this->assertTrue(in_array('customer', $tables));
$this->assertTrue(in_array('tbl_category', $tables)); $this->assertTrue(in_array('category', $tables));
$this->assertTrue(in_array('tbl_item', $tables)); $this->assertTrue(in_array('item', $tables));
$this->assertTrue(in_array('tbl_order', $tables)); $this->assertTrue(in_array('order', $tables));
$this->assertTrue(in_array('tbl_order_item', $tables)); $this->assertTrue(in_array('order_item', $tables));
$this->assertTrue(in_array('tbl_type', $tables)); $this->assertTrue(in_array('type', $tables));
} }
public function testGetTableSchemas() public function testGetTableSchemas()
...@@ -49,8 +49,8 @@ class SchemaTest extends DatabaseTestCase ...@@ -49,8 +49,8 @@ class SchemaTest extends DatabaseTestCase
$schema->db->enableSchemaCache = true; $schema->db->enableSchemaCache = true;
$schema->db->schemaCache = new FileCache(); $schema->db->schemaCache = new FileCache();
$noCacheTable = $schema->getTableSchema('tbl_type', true); $noCacheTable = $schema->getTableSchema('type', true);
$cachedTable = $schema->getTableSchema('tbl_type', true); $cachedTable = $schema->getTableSchema('type', true);
$this->assertEquals($noCacheTable, $cachedTable); $this->assertEquals($noCacheTable, $cachedTable);
} }
...@@ -59,11 +59,11 @@ class SchemaTest extends DatabaseTestCase ...@@ -59,11 +59,11 @@ class SchemaTest extends DatabaseTestCase
/** @var Schema $schema */ /** @var Schema $schema */
$schema = $this->getConnection()->schema; $schema = $this->getConnection()->schema;
$table = $schema->getTableSchema('tbl_composite_fk'); $table = $schema->getTableSchema('composite_fk');
$this->assertCount(1, $table->foreignKeys); $this->assertCount(1, $table->foreignKeys);
$this->assertTrue(isset($table->foreignKeys[0])); $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('order_id', $table->foreignKeys[0]['order_id']);
$this->assertEquals('item_id', $table->foreignKeys[0]['item_id']); $this->assertEquals('item_id', $table->foreignKeys[0]['item_id']);
} }
......
...@@ -16,7 +16,7 @@ class CubridCommandTest extends CommandTest ...@@ -16,7 +16,7 @@ class CubridCommandTest extends CommandTest
$db = $this->getConnection(); $db = $this->getConnection();
// bindParam // 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); $command = $db->createCommand($sql);
$email = 'user4@example.com'; $email = 'user4@example.com';
$name = 'user4'; $name = 'user4';
...@@ -26,12 +26,12 @@ class CubridCommandTest extends CommandTest ...@@ -26,12 +26,12 @@ class CubridCommandTest extends CommandTest
$command->bindParam(':address', $address); $command->bindParam(':address', $address);
$command->execute(); $command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email'; $sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindParam(':email', $email); $command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar()); $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); $command = $db->createCommand($sql);
$intCol = 123; $intCol = 123;
$charCol = 'abc'; $charCol = 'abc';
...@@ -49,7 +49,7 @@ class CubridCommandTest extends CommandTest ...@@ -49,7 +49,7 @@ class CubridCommandTest extends CommandTest
$command->bindParam(':bool_col', $boolCol); $command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute()); $this->assertEquals(1, $command->execute());
$sql = 'SELECT * FROM tbl_type'; $sql = 'SELECT * FROM type';
$row = $db->createCommand($sql)->queryOne(); $row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']); $this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($enumCol, $row['enum_col']); $this->assertEquals($enumCol, $row['enum_col']);
...@@ -60,12 +60,12 @@ class CubridCommandTest extends CommandTest ...@@ -60,12 +60,12 @@ class CubridCommandTest extends CommandTest
$this->assertEquals($boolCol, $row['bool_col']); $this->assertEquals($boolCol, $row['bool_col']);
// bindValue // 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 = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com'); $command->bindValue(':email', 'user5@example.com');
$command->execute(); $command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name'; $sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindValue(':name', 'user5'); $command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar()); $this->assertEquals('user5@example.com', $command->queryScalar());
...@@ -75,8 +75,8 @@ class CubridCommandTest extends CommandTest ...@@ -75,8 +75,8 @@ class CubridCommandTest extends CommandTest
{ {
$db = $this->getConnection(false); $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); $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,9 +16,9 @@ class MssqlCommandTest extends CommandTest ...@@ -16,9 +16,9 @@ class MssqlCommandTest extends CommandTest
{ {
$db = $this->getConnection(false); $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); $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() public function testPrepareCancel()
...@@ -31,7 +31,7 @@ class MssqlCommandTest extends CommandTest ...@@ -31,7 +31,7 @@ class MssqlCommandTest extends CommandTest
$db = $this->getConnection(); $db = $this->getConnection();
// bindParam // 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); $command = $db->createCommand($sql);
$email = 'user4@example.com'; $email = 'user4@example.com';
$name = 'user4'; $name = 'user4';
...@@ -41,12 +41,12 @@ class MssqlCommandTest extends CommandTest ...@@ -41,12 +41,12 @@ class MssqlCommandTest extends CommandTest
$command->bindParam(':address', $address); $command->bindParam(':address', $address);
$command->execute(); $command->execute();
$sql = 'SELECT name FROM tbl_customer WHERE email=:email'; $sql = 'SELECT name FROM customer WHERE email=:email';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindParam(':email', $email); $command->bindParam(':email', $email);
$this->assertEquals($name, $command->queryScalar()); $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); $command = $db->createCommand($sql);
$intCol = 123; $intCol = 123;
$charCol = 'abc'; $charCol = 'abc';
...@@ -62,7 +62,7 @@ class MssqlCommandTest extends CommandTest ...@@ -62,7 +62,7 @@ class MssqlCommandTest extends CommandTest
$command->bindParam(':bool_col', $boolCol); $command->bindParam(':bool_col', $boolCol);
$this->assertEquals(1, $command->execute()); $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(); $row = $db->createCommand($sql)->queryOne();
$this->assertEquals($intCol, $row['int_col']); $this->assertEquals($intCol, $row['int_col']);
$this->assertEquals($charCol, trim($row['char_col'])); $this->assertEquals($charCol, trim($row['char_col']));
...@@ -71,12 +71,12 @@ class MssqlCommandTest extends CommandTest ...@@ -71,12 +71,12 @@ class MssqlCommandTest extends CommandTest
$this->assertEquals($numericCol, $row['numeric_col']); $this->assertEquals($numericCol, $row['numeric_col']);
// bindValue // 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 = $db->createCommand($sql);
$command->bindValue(':email', 'user5@example.com'); $command->bindValue(':email', 'user5@example.com');
$command->execute(); $command->execute();
$sql = 'SELECT email FROM tbl_customer WHERE name=:name'; $sql = 'SELECT email FROM customer WHERE name=:name';
$command = $db->createCommand($sql); $command = $db->createCommand($sql);
$command->bindValue(':name', 'user5'); $command->bindValue(':name', 'user5');
$this->assertEquals('user5@example.com', $command->queryScalar()); $this->assertEquals('user5@example.com', $command->queryScalar());
......
...@@ -15,8 +15,8 @@ class SqliteCommandTest extends CommandTest ...@@ -15,8 +15,8 @@ class SqliteCommandTest extends CommandTest
{ {
$db = $this->getConnection(false); $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); $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);
} }
} }
...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest ...@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function testBatchInsert() public function testBatchInsert()
{ {
$sql = $this->getQueryBuilder()->batchInsert('{{tbl_customer}} t', ['t.id', 't.name'], [[1, 'a'], [2, 'b']]); $sql = $this->getQueryBuilder()->batchInsert('{{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); $this->assertEquals("INSERT INTO {{customer}} t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'", $sql);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment