Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ab799d8e
Commit
ab799d8e
authored
Mar 30, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2911: Removed `tbl_` default for table prefix
parent
1539a325
Hide whitespace changes
Inline
Side-by-side
Showing
70 changed files
with
579 additions
and
577 deletions
+579
-577
m130524_201442_init.php
apps/advanced/console/migrations/m130524_201442_init.php
+2
-2
PasswordResetRequestFormTest.php
...ontend/tests/unit/models/PasswordResetRequestFormTest.php
+1
-1
ResetPasswordFormTest.php
...nced/frontend/tests/unit/models/ResetPasswordFormTest.php
+1
-1
UserTest.php
apps/basic/tests/unit/models/UserTest.php
+2
-2
active-record.md
docs/guide/active-record.md
+33
-33
console-migrate.md
docs/guide/console-migrate.md
+9
-9
data-providers.md
docs/guide/data-providers.md
+4
-4
database-basics.md
docs/guide/database-basics.md
+12
-12
query-builder.md
docs/guide/query-builder.md
+20
-20
test-fixture.md
docs/guide/test-fixture.md
+1
-1
upgrade-from-v1.md
docs/guide/upgrade-from-v1.md
+1
-1
FixtureController.php
extensions/faker/FixtureController.php
+1
-1
README.md
extensions/faker/README.md
+1
-1
Generator.php
extensions/gii/generators/model/Generator.php
+2
-2
Command.php
extensions/sphinx/Command.php
+1
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
DbCache.php
framework/caching/DbCache.php
+2
-2
MigrateController.php
framework/console/controllers/MigrateController.php
+1
-1
ActiveDataProvider.php
framework/data/ActiveDataProvider.php
+1
-1
ArrayDataProvider.php
framework/data/ArrayDataProvider.php
+1
-1
SqlDataProvider.php
framework/data/SqlDataProvider.php
+2
-2
ActiveQuery.php
framework/db/ActiveQuery.php
+2
-2
ActiveRecord.php
framework/db/ActiveRecord.php
+6
-6
BatchQueryResult.php
framework/db/BatchQueryResult.php
+1
-1
Command.php
framework/db/Command.php
+6
-6
Connection.php
framework/db/Connection.php
+4
-4
DataReader.php
framework/db/DataReader.php
+1
-1
Query.php
framework/db/Query.php
+15
-15
QueryBuilder.php
framework/db/QueryBuilder.php
+5
-5
QueryBuilder.php
framework/db/sqlite/QueryBuilder.php
+1
-1
DbMessageSource.php
framework/i18n/DbMessageSource.php
+4
-4
DbTarget.php
framework/log/DbTarget.php
+2
-2
DbManager.php
framework/rbac/DbManager.php
+3
-3
schema-mssql.sql
framework/rbac/schema-mssql.sql
+9
-9
schema-mysql.sql
framework/rbac/schema-mysql.sql
+9
-9
schema-oci.sql
framework/rbac/schema-oci.sql
+9
-9
schema-pgsql.sql
framework/rbac/schema-pgsql.sql
+10
-10
schema-sqlite.sql
framework/rbac/schema-sqlite.sql
+9
-9
DbSession.php
framework/web/DbSession.php
+2
-2
Category.php
tests/unit/data/ar/Category.php
+1
-1
Customer.php
tests/unit/data/ar/Customer.php
+3
-3
Item.php
tests/unit/data/ar/Item.php
+1
-1
NullValues.php
tests/unit/data/ar/NullValues.php
+1
-1
Order.php
tests/unit/data/ar/Order.php
+3
-3
OrderItem.php
tests/unit/data/ar/OrderItem.php
+1
-1
Profile.php
tests/unit/data/ar/Profile.php
+1
-1
Type.php
tests/unit/data/ar/Type.php
+3
-2
Order.php
tests/unit/data/ar/elasticsearch/Order.php
+1
-1
cubrid.sql
tests/unit/data/cubrid.sql
+47
-47
mssql.sql
tests/unit/data/mssql.sql
+37
-37
mysql.sql
tests/unit/data/mysql.sql
+61
-61
postgres.sql
tests/unit/data/postgres.sql
+59
-59
sqlite.sql
tests/unit/data/sqlite.sql
+55
-55
ValidatorTestMainModel.php
tests/unit/data/validators/models/ValidatorTestMainModel.php
+1
-1
ValidatorTestRefModel.php
tests/unit/data/validators/models/ValidatorTestRefModel.php
+1
-1
ActiveRecordTest.php
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
+2
-2
ActiveRecordTest.php
tests/unit/extensions/redis/ActiveRecordTest.php
+2
-2
QueryTest.php
tests/unit/extensions/sphinx/QueryTest.php
+2
-2
DbCacheTest.php
tests/unit/framework/caching/DbCacheTest.php
+1
-1
ActiveDataProviderTest.php
tests/unit/framework/data/ActiveDataProviderTest.php
+4
-4
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+25
-25
BatchQueryResultTest.php
tests/unit/framework/db/BatchQueryResultTest.php
+6
-6
CommandTest.php
tests/unit/framework/db/CommandTest.php
+29
-29
QueryBuilderTest.php
tests/unit/framework/db/QueryBuilderTest.php
+1
-1
QueryTest.php
tests/unit/framework/db/QueryTest.php
+4
-4
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+10
-10
CubridCommandTest.php
tests/unit/framework/db/cubrid/CubridCommandTest.php
+8
-8
MssqlCommandTest.php
tests/unit/framework/db/mssql/MssqlCommandTest.php
+8
-8
SqliteCommandTest.php
tests/unit/framework/db/sqlite/SqliteCommandTest.php
+2
-2
SqliteQueryBuilderTest.php
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php
+2
-2
No files found.
apps/advanced/console/migrations/m130524_201442_init.php
View file @
ab799d8e
...
...
@@ -11,7 +11,7 @@ class m130524_201442_init extends \yii\db\Migration
$tableOptions
=
'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'
;
}
$this
->
createTable
(
'
tbl_
user'
,
[
$this
->
createTable
(
'user'
,
[
'id'
=>
Schema
::
TYPE_PK
,
'username'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
'auth_key'
=>
Schema
::
TYPE_STRING
.
'(32) NOT NULL'
,
...
...
@@ -28,6 +28,6 @@ class m130524_201442_init extends \yii\db\Migration
public
function
down
()
{
$this
->
dropTable
(
'
tbl_
user'
);
$this
->
dropTable
(
'user'
);
}
}
apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php
View file @
ab799d8e
...
...
@@ -66,7 +66,7 @@ class PasswordResetRequestFormTest extends DbTestCase
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/
tbl_
user.php'
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/user.php'
],
];
}
...
...
apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php
View file @
ab799d8e
...
...
@@ -29,7 +29,7 @@ class ResetPasswordFormTest extends DbTestCase
return
[
'user'
=>
[
'class'
=>
UserFixture
::
className
(),
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/
tbl_
user.php'
'dataFile'
=>
'@frontend/tests/unit/fixtures/data/user.php'
],
];
}
...
...
apps/basic/tests/unit/models/UserTest.php
View file @
ab799d8e
...
...
@@ -9,8 +9,8 @@ class UserTest extends TestCase
protected
function
setUp
()
{
parent
::
setUp
();
// uncomment the following to load fixtures for
table tbl_user
//$this->loadFixtures(['
tbl_
user']);
// uncomment the following to load fixtures for
user table
//$this->loadFixtures(['user']);
}
// TODO add test methods here
...
...
docs/guide/active-record.md
View file @
ab799d8e
...
...
@@ -7,9 +7,9 @@ an Active Record instance corresponds to a row of that table, and an attribute o
instance represents the value of a column in that row. Instead of writing raw SQL statements,
you can work with Active Record in an object-oriented fashion to manipulate the data in database tables.
For example, assume
`Customer`
is an Active Record class is associated with the
`
tbl_
customer`
table
and
`name`
is a column of
`
tbl_customer`
. You can write the following code to insert a new
row into
`
tbl_customer`
:
For example, assume
`Customer`
is an Active Record class is associated with the
`customer`
table
and
`name`
is a column of
`
customer`
table
. You can write the following code to insert a new
row into
`
customer`
table
:
```
php
$customer
=
new
Customer
();
...
...
@@ -21,7 +21,7 @@ The above code is equivalent to using the following raw SQL statement, which is
intuitive, more error prone, and may have compatibility problem for different DBMS:
```
php
$db
->
createCommand
(
'INSERT INTO
tbl_
customer (name) VALUES (:name)'
,
[
$db
->
createCommand
(
'INSERT INTO customer (name) VALUES (:name)'
,
[
':name'
=>
'Qiang'
,
])
->
execute
();
```
...
...
@@ -45,7 +45,7 @@ class Customer extends ActiveRecord
*/
public
static
function
tableName
()
{
return
'
tbl_
customer'
;
return
'customer'
;
}
}
```
...
...
@@ -144,7 +144,7 @@ $customers = Customer::find()->indexBy('id')->all();
// $customers array is indexed by customer IDs
// to retrieve customers using a raw SQL statement:
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$customers
=
Customer
::
findBySql
(
$sql
)
->
all
();
```
...
...
@@ -332,8 +332,8 @@ $orders = $customer->orders; // $orders is an array of Order objects
Behind the scene, the above code executes the following two SQL queries, one for each line of code:
```
sql
SELECT
*
FROM
tbl_
customer
WHERE
id
=
1
;
SELECT
*
FROM
tbl_
order
WHERE
customer_id
=
1
;
SELECT
*
FROM
customer
WHERE
id
=
1
;
SELECT
*
FROM
order
WHERE
customer_id
=
1
;
```
> Tip: If you access the expression `$customer->orders` again, it will not perform the second SQL query again.
...
...
@@ -381,7 +381,7 @@ Sometimes, two tables are related together via an intermediary table called [piv
we can customize the
[
[yii\db\ActiveQuery
]
] object by calling its
[
[yii\db\ActiveQuery::via()|via()
]
] or
[
[yii\db\ActiveQuery::viaTable()|viaTable()
]
] method.
For example, if table
`
tbl_order`
and table
`tbl_item`
are related via pivot table
`tbl_
order_item`
,
For example, if table
`
order`
and table
`item`
are related via pivot table
`
order_item`
,
we can declare the
`items`
relation in the
`Order`
class like the following:
```
php
...
...
@@ -390,7 +390,7 @@ class Order extends \yii\db\ActiveRecord
public
function
getItems
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
viaTable
(
'
tbl_
order_item'
,
[
'order_id'
=>
'id'
]);
->
viaTable
(
'order_item'
,
[
'order_id'
=>
'id'
]);
}
}
```
...
...
@@ -426,9 +426,9 @@ to retrieve the corresponding data and populate it into the related objects. No
if you access the same related objects again. We call this
*lazy loading*
. For example,
```
php
// SQL executed: SELECT * FROM
tbl_
customer WHERE id=1
// SQL executed: SELECT * FROM customer WHERE id=1
$customer
=
Customer
::
find
(
1
);
// SQL executed: SELECT * FROM
tbl_
order WHERE customer_id=1
// SQL executed: SELECT * FROM order WHERE customer_id=1
$orders
=
$customer
->
orders
;
// no SQL executed
$orders2
=
$customer
->
orders
;
...
...
@@ -437,11 +437,11 @@ $orders2 = $customer->orders;
Lazy loading is very convenient to use. However, it may suffer from a performance issue in the following scenario:
```
php
// SQL executed: SELECT * FROM
tbl_
customer LIMIT 100
// SQL executed: SELECT * FROM customer LIMIT 100
$customers
=
Customer
::
find
()
->
limit
(
100
)
->
all
();
foreach
(
$customers
as
$customer
)
{
// SQL executed: SELECT * FROM
tbl_
order WHERE customer_id=...
// SQL executed: SELECT * FROM order WHERE customer_id=...
$orders
=
$customer
->
orders
;
// ...handle $orders...
}
...
...
@@ -454,8 +454,8 @@ is performed to bring back the orders of that customer.
To solve the above performance problem, you can use the so-called
*eager loading*
approach by calling
[
[yii\db\ActiveQuery::with()
]
]:
```
php
// SQL executed: SELECT * FROM
tbl_
customer LIMIT 100;
// SELECT * FROM
tbl_
orders WHERE customer_id IN (1,2,...)
// SQL executed: SELECT * FROM customer LIMIT 100;
// SELECT * FROM orders WHERE customer_id IN (1,2,...)
$customers
=
Customer
::
find
()
->
limit
(
100
)
->
with
(
'orders'
)
->
all
();
...
...
@@ -486,11 +486,11 @@ done for both lazy loading and eager loading. For example,
```
php
$customer
=
Customer
::
find
(
1
);
// lazy loading: SELECT * FROM
tbl_
order WHERE customer_id=1 AND subtotal>100
// lazy loading: SELECT * FROM order WHERE customer_id=1 AND subtotal>100
$orders
=
$customer
->
getOrders
()
->
where
(
'subtotal>100'
)
->
all
();
// eager loading: SELECT * FROM
tbl_
customer LIMIT 100
// SELECT * FROM
tbl_
order WHERE customer_id IN (1,2,...) AND subtotal>100
// eager loading: SELECT * FROM customer LIMIT 100
// SELECT * FROM order WHERE customer_id IN (1,2,...) AND subtotal>100
$customers
=
Customer
::
find
()
->
limit
(
100
)
->
with
([
'orders'
=>
function
(
$query
)
{
$query
->
andWhere
(
'subtotal>100'
);
...
...
@@ -530,11 +530,11 @@ that finds those orders, and accessing `customer->orders` will trigger one SQL e
the
`customer`
of an order will trigger another SQL execution:
```
php
// SELECT * FROM
tbl_
customer WHERE id=1
// SELECT * FROM customer WHERE id=1
$customer
=
Customer
::
find
(
1
);
// echoes "not equal"
// SELECT * FROM
tbl_
order WHERE customer_id=1
// SELECT * FROM
tbl_
customer WHERE id=1
// SELECT * FROM order WHERE customer_id=1
// SELECT * FROM customer WHERE id=1
if
(
$customer
->
orders
[
0
]
->
customer
===
$customer
)
{
echo
'equal'
;
}
else
{
...
...
@@ -559,10 +559,10 @@ class Customer extends ActiveRecord
Now if we execute the same query as shown above, we would get:
```
php
// SELECT * FROM
tbl_
customer WHERE id=1
// SELECT * FROM customer WHERE id=1
$customer
=
Customer
::
find
(
1
);
// echoes "equal"
// SELECT * FROM
tbl_
order WHERE customer_id=1
// SELECT * FROM order WHERE customer_id=1
if
(
$customer
->
orders
[
0
]
->
customer
===
$customer
)
{
echo
'equal'
;
}
else
{
...
...
@@ -574,8 +574,8 @@ In the above, we have shown how to use inverse relations in lazy loading. Invers
eager loading:
```
php
// SELECT * FROM
tbl_
customer
// SELECT * FROM
tbl_
order WHERE customer_id IN (1, 2, ...)
// SELECT * FROM customer
// SELECT * FROM order WHERE customer_id IN (1, 2, ...)
$customers
=
Customer
::
find
()
->
with
(
'orders'
)
->
all
();
// echoes "equal"
if
(
$customers
[
0
]
->
orders
[
0
]
->
customer
===
$customers
[
0
])
{
...
...
@@ -600,7 +600,7 @@ explicitly to build up the JOIN query, you may reuse the existing relation defin
```
php
// find all orders and sort the orders by the customer id and the order id. also eager loading "customer"
$orders
=
Order
::
find
()
->
joinWith
(
'customer'
)
->
orderBy
(
'
tbl_customer.id, tbl_
order.id'
)
->
all
();
$orders
=
Order
::
find
()
->
joinWith
(
'customer'
)
->
orderBy
(
'
customer.id,
order.id'
)
->
all
();
// find all orders that contain books, and eager loading "books"
$orders
=
Order
::
find
()
->
innerJoinWith
(
'books'
)
->
all
();
```
...
...
@@ -617,7 +617,7 @@ and you may also join with sub-relations. For example,
$orders
=
Order
::
find
()
->
innerJoinWith
([
'books'
,
'customer'
=>
function
(
$query
)
{
$query
->
where
(
'
tbl_
customer.created_at > '
.
(
time
()
-
24
*
3600
));
$query
->
where
(
'customer.created_at > '
.
(
time
()
-
24
*
3600
));
}
])
->
all
();
// join with sub-relations: join with books and books' authors
...
...
@@ -638,7 +638,7 @@ For example, you may filter the primary models by the conditions on the related
above. You may also sort the primary models using columns from the related tables.
When using
[
[yii\db\ActiveQuery::joinWith()|joinWith()
]
], you are responsible to disambiguate column names.
In the above examples, we use
`
tbl_item.id`
and
`tbl_
order.id`
to disambiguate the
`id`
column references
In the above examples, we use
`
item.id`
and
`
order.id`
to disambiguate the
`id`
column references
because both of the order table and the item table contain a column named
`id`
.
By default, when you join with a relation, the relation will also be eagerly loaded. You may change this behavior
...
...
@@ -678,8 +678,8 @@ When you perform query using [[yii\db\ActiveQuery::joinWith()|joinWith()]], the
of the corresponding JOIN query. For example,
```
php
// SELECT
tbl_user.* FROM tbl_user LEFT JOIN tbl_item ON tbl_item.owner_id=tbl_
user.id AND category_id=1
// SELECT * FROM
tbl_
item WHERE owner_id IN (...) AND category_id=1
// SELECT
user.* FROM user LEFT JOIN item ON item.owner_id=
user.id AND category_id=1
// SELECT * FROM item WHERE owner_id IN (...) AND category_id=1
$users
=
User
::
find
()
->
joinWith
(
'books'
)
->
all
();
```
...
...
@@ -687,9 +687,9 @@ Note that if you use eager loading via [[yii\db\ActiveQuery::with()]] or lazy lo
in the WHERE part of the corresponding SQL statement, because there is no JOIN query involved. For example,
```
php
// SELECT * FROM
tbl_
user WHERE id=10
// SELECT * FROM user WHERE id=10
$user
=
User
::
find
(
10
);
// SELECT * FROM
tbl_
item WHERE owner_id=10 AND category_id=1
// SELECT * FROM item WHERE owner_id=10 AND category_id=1
$books
=
$user
->
books
;
```
...
...
docs/guide/console-migrate.md
View file @
ab799d8e
...
...
@@ -80,7 +80,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{
public
function
up
()
{
$this
->
createTable
(
'
tbl_
news'
,
[
$this
->
createTable
(
'news'
,
[
'id'
=>
'pk'
,
'title'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
'content'
=>
Schema
::
TYPE_TEXT
,
...
...
@@ -89,7 +89,7 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public
function
down
()
{
$this
->
dropTable
(
'
tbl_
news'
);
$this
->
dropTable
(
'news'
);
}
}
...
...
@@ -124,13 +124,13 @@ class m101129_185401_create_news_table extends \yii\db\Migration
{
public
function
safeUp
()
{
$this
->
createTable
(
'
tbl_
news'
,
[
$this
->
createTable
(
'news'
,
[
'id'
=>
'pk'
,
'title'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
'content'
=>
Schema
::
TYPE_TEXT
,
]);
$this
->
createTable
(
'
tbl_
user'
,
[
$this
->
createTable
(
'user'
,
[
'id'
=>
'pk'
,
'login'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
'password'
=>
Schema
::
TYPE_STRING
.
' NOT NULL'
,
...
...
@@ -139,8 +139,8 @@ class m101129_185401_create_news_table extends \yii\db\Migration
public
function
safeDown
()
{
$this
->
dropTable
(
'
tbl_
news'
);
$this
->
dropTable
(
'
tbl_
user'
);
$this
->
dropTable
(
'news'
);
$this
->
dropTable
(
'user'
);
}
}
...
...
@@ -169,8 +169,8 @@ the migrations, it will run the `up()` method in every new migration class, one
after another, in the order of the timestamp value in the class name.
After applying a migration, the migration tool will keep a record in a database
table named
`
tbl_
migration`
. This allows the tool to identify which migrations
have been applied and which are not. If the
`
tbl_
migration`
table does not exist,
table named
`migration`
. This allows the tool to identify which migrations
have been applied and which are not. If the
`migration`
table does not exist,
the tool will automatically create it in the database specified by the
`db`
application component.
...
...
@@ -284,7 +284,7 @@ line:
sub-directory under the application base path.
*
`migrationTable`
: string, specifies the name of the database table for storing
migration history information. It defaults to
`
tbl_
migration`
. The table
migration history information. It defaults to
`migration`
. The table
structure is
`version varchar(255) primary key, apply_time integer`
.
*
`connectionID`
: string, specifies the ID of the database application component.
...
...
docs/guide/data-providers.md
View file @
ab799d8e
...
...
@@ -31,7 +31,7 @@ And the following example shows how to use ActiveDataProvider without ActiveReco
```
php
$query = new Query();
$provider = new ActiveDataProvider(
[
'query' => $query->from('
tbl_
post'),
'query' => $query->from('post'),
'pagination' =>
[
'pageSize' => 20,
],
...
...
@@ -64,7 +64,7 @@ ArrayDataProvider may be used in the following way:
```
php
$query = new Query();
$provider = new ArrayDataProvider(
[
'allModels' => $query->from('
tbl_
post')->all(),
'allModels' => $query->from('post')->all(),
'sort' =>
[
'attributes' =>
[
'id', 'username', 'email'
]
,
],
...
...
@@ -94,11 +94,11 @@ and pagination behaviors.
```
php
$count = Yii::$app->db->createCommand('
SELECT COUNT(
*
) FROM
tbl_
user WHERE status=:status
SELECT COUNT(
*
) FROM user WHERE status=:status
',
[
':status' => 1
]
)->queryScalar();
$dataProvider = new SqlDataProvider(
[
'sql' => 'SELECT
*
FROM
tbl_
user WHERE status=:status',
'sql' => 'SELECT
*
FROM user WHERE status=:status',
'params' =>
[
':status' => 1
]
,
'totalCount' => $count,
'sort' =>
[
...
...
docs/guide/database-basics.md
View file @
ab799d8e
...
...
@@ -103,28 +103,28 @@ Once you have a connection instance you can execute SQL queries using [[yii\db\C
When query returns a set of rows:
```
php
$command
=
$connection
->
createCommand
(
'SELECT * FROM
tbl_
post'
);
$command
=
$connection
->
createCommand
(
'SELECT * FROM post'
);
$posts
=
$command
->
queryAll
();
```
When only a single row is returned:
```
php
$command
=
$connection
->
createCommand
(
'SELECT * FROM
tbl_
post WHERE id=1'
);
$command
=
$connection
->
createCommand
(
'SELECT * FROM post WHERE id=1'
);
$post
=
$command
->
queryOne
();
```
When there are multiple values from the same column:
```
php
$command
=
$connection
->
createCommand
(
'SELECT title FROM
tbl_
post'
);
$command
=
$connection
->
createCommand
(
'SELECT title FROM post'
);
$titles
=
$command
->
queryColumn
();
```
When there's a scalar value:
```
php
$command
=
$connection
->
createCommand
(
'SELECT COUNT(*) FROM
tbl_
post'
);
$command
=
$connection
->
createCommand
(
'SELECT COUNT(*) FROM post'
);
$postCount
=
$command
->
queryScalar
();
```
...
...
@@ -133,7 +133,7 @@ $postCount = $command->queryScalar();
If SQL executed doesn't return any data you can use command's
`execute`
method:
```
php
$command
=
$connection
->
createCommand
(
'UPDATE
tbl_
post SET status=1 WHERE id=1'
);
$command
=
$connection
->
createCommand
(
'UPDATE post SET status=1 WHERE id=1'
);
$command
->
execute
();
```
...
...
@@ -141,23 +141,23 @@ Alternatively the following syntax that takes care of proper table and column na
```
php
// INSERT
$connection
->
createCommand
()
->
insert
(
'
tbl_
user'
,
[
$connection
->
createCommand
()
->
insert
(
'user'
,
[
'name'
=>
'Sam'
,
'age'
=>
30
,
])
->
execute
();
// INSERT multiple rows at once
$connection
->
createCommand
()
->
batchInsert
(
'
tbl_
user'
,
[
'name'
,
'age'
],
[
$connection
->
createCommand
()
->
batchInsert
(
'user'
,
[
'name'
,
'age'
],
[
[
'Tom'
,
30
],
[
'Jane'
,
20
],
[
'Linda'
,
25
],
])
->
execute
();
// UPDATE
$connection
->
createCommand
()
->
update
(
'
tbl_
user'
,
[
'status'
=>
1
],
'age > 30'
)
->
execute
();
$connection
->
createCommand
()
->
update
(
'user'
,
[
'status'
=>
1
],
'age > 30'
)
->
execute
();
// DELETE
$connection
->
createCommand
()
->
delete
(
'
tbl_
user'
,
'status = 0'
)
->
execute
();
$connection
->
createCommand
()
->
delete
(
'user'
,
'status = 0'
)
->
execute
();
```
Quoting table and column names
...
...
@@ -189,7 +189,7 @@ Prepared statements
In order to securely pass query parameters you can use prepared statements:
```
php
$command = $connection->createCommand('SELECT
*
FROM
tbl_
post WHERE id=:id');
$command = $connection->createCommand('SELECT
*
FROM post WHERE id=:id');
$command->bindValue(':id', $_GET
[
'id'
]
);
$post = $command->query();
```
...
...
@@ -197,7 +197,7 @@ $post = $command->query();
Another usage is performing a query multiple times while preparing it only once:
```
php
$command = $connection->createCommand('DELETE FROM
tbl_
post WHERE id=:id');
$command = $connection->createCommand('DELETE FROM post WHERE id=:id');
$command->bindParam(':id', $id);
$id = 1;
...
...
@@ -281,7 +281,7 @@ These can be used as follows:
```
php
// CREATE TABLE
$connection->createCommand()->createTable('
tbl_
post',
[
$connection->createCommand()->createTable('post',
[
'id' => 'pk',
'title' => 'string',
'text' => 'text',
...
...
docs/guide/query-builder.md
View file @
ab799d8e
...
...
@@ -11,7 +11,7 @@ A typical usage of the query builder looks like the following:
```
php
$rows
=
(
new
\yii\db\Query
())
->
select
(
'id, name'
)
->
from
(
'
tbl_
user'
)
->
from
(
'user'
)
->
limit
(
10
)
->
all
();
...
...
@@ -19,7 +19,7 @@ $rows = (new \yii\db\Query())
$query
=
(
new
\yii\db\Query
())
->
select
(
'id, name'
)
->
from
(
'
tbl_
user'
)
->
from
(
'user'
)
->
limit
(
10
);
// Create a command. You can get the actual SQL using $command->sql
...
...
@@ -62,7 +62,7 @@ In order to form a basic `SELECT` query, you need to specify what columns to sel
```
php
$query
->
select
(
'id, name'
)
->
from
(
'
tbl_
user'
);
->
from
(
'user'
);
```
Select options can be specified as a comma-separated string, as in the above, or as an array.
...
...
@@ -70,7 +70,7 @@ The array syntax is especially useful when forming the selection dynamically:
```
php
$query
->
select
([
'id'
,
'name'
])
->
from
(
'
tbl_
user'
);
->
from
(
'user'
);
```
> Info: You should always use the array format if your `SELECT` clause contains SQL expressions.
...
...
@@ -78,14 +78,14 @@ $query->select(['id', 'name'])
> If you list it together with other columns in a string, the expression may be split into several parts
> by commas, which is not what you want to see.
When specifying columns, you may include the table prefixes or column aliases, e.g.,
`
tbl_user.id`
,
`tbl_
user.id AS user_id`
.
When specifying columns, you may include the table prefixes or column aliases, e.g.,
`
user.id`
,
`
user.id AS user_id`
.
If you are using array to specify the columns, you may also use the array keys to specify the column aliases,
e.g.,
`['user_id' => '
tbl_user.id', 'user_name' => 'tbl_
user.name']`
.
e.g.,
`['user_id' => '
user.id', 'user_name' => '
user.name']`
.
To select distinct rows, you may call
`distinct()`
, like the following:
```
php
$query
->
select
(
'user_id'
)
->
distinct
()
->
from
(
'
tbl_
post'
);
$query
->
select
(
'user_id'
)
->
distinct
()
->
from
(
'post'
);
```
### `FROM`
...
...
@@ -93,30 +93,30 @@ $query->select('user_id')->distinct()->from('tbl_post');
To specify which table(s) to select data from, call
`from()`
:
```
php
$query
->
select
(
'*'
)
->
from
(
'
tbl_
user'
);
$query
->
select
(
'*'
)
->
from
(
'user'
);
```
You may specify multiple tables using a comma-separated string or an array.
Table names can contain schema prefixes (e.g.
`'public.
tbl_user'`
) and/or table aliases (e.g.
`'tbl_
user u'`
).
Table names can contain schema prefixes (e.g.
`'public.
user'`
) and/or table aliases (e.g.
`'
user u'`
).
The method will automatically quote the table names unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression). For example,
```
php
$query
->
select
(
'u.*, p.*'
)
->
from
([
'
tbl_user u'
,
'tbl_
post p'
]);
$query
->
select
(
'u.*, p.*'
)
->
from
([
'
user u'
,
'
post p'
]);
```
When the tables are specified as an array, you may also use the array keys as the table aliases
(if a table does not need alias, do not use a string key). For example,
```
php
$query
->
select
(
'u.*, p.*'
)
->
from
([
'u'
=>
'
tbl_user u'
,
'p'
=>
'tbl_
post'
]);
$query
->
select
(
'u.*, p.*'
)
->
from
([
'u'
=>
'
user u'
,
'p'
=>
'
post'
]);
```
You may specify a sub-query using a
`Query`
object. In this case, the corresponding array key will be used
as the alias for the sub-query.
```
php
$subQuery
=
(
new
Query
())
->
select
(
'id'
)
->
from
(
'
tbl_
user'
)
->
where
(
'status=1'
);
$subQuery
=
(
new
Query
())
->
select
(
'id'
)
->
from
(
'user'
)
->
where
(
'status=1'
);
$query
->
select
(
'*'
)
->
from
([
'u'
=>
$subQuery
]);
```
...
...
@@ -293,9 +293,9 @@ The `JOIN` clauses are generated in the Query Builder by using the applicable jo
This left join selects data from two related tables in one query:
```
php
$query->select(
[
'
tbl_user.name AS author', 'tbl_
post.title as title'
]
)
->from('
tbl_
user')
->leftJoin('
tbl_post', 'tbl_post.user_id = tbl_
user.id');
$query->select(
[
'
user.name AS author', '
post.title as title'
]
)
->from('user')
->leftJoin('
post', 'post.user_id =
user.id');
```
In the code, the `leftJoin()` method's first parameter
...
...
@@ -304,7 +304,7 @@ specifies the table to join to. The second parameter defines the join condition.
If your database application supports other join types, you can use those via the generic `join` method:
```
php
$query->join('FULL OUTER JOIN', '
tbl_post', 'tbl_post.user_id = tbl_
user.id');
$query->join('FULL OUTER JOIN', '
post', 'post.user_id =
user.id');
```
The first argument is the join type to perform. The second is the table to join to, and the third is the condition.
...
...
@@ -325,10 +325,10 @@ In Yii in order to build it you can first form two query objects and then use `u
```
php
$query = new Query();
$query->select("id, 'post' as type, name")->from('
tbl_
post')->limit(10);
$query->select("id, 'post' as type, name")->from('post')->limit(10);
$anotherQuery = new Query();
$anotherQuery->select('id, 'user' as type, name')->from('
tbl_
user')->limit(10);
$anotherQuery->select('id, 'user' as type, name')->from('user')->limit(10);
$query->union($anotherQuery);
```
...
...
@@ -348,7 +348,7 @@ Batch query can be used like the following:
use yii
\d
b
\Q
uery;
$query = (new Query())
->from('
tbl_
user')
->from('user')
->orderBy('id');
foreach ($query->batch() as $users) {
...
...
@@ -377,7 +377,7 @@ will still keep the proper index. For example,
use yii
\d
b
\Q
uery;
$query = (new Query())
->from('
tbl_
user')
->from('user')
->indexBy('username');
foreach ($query->batch() as $users) {
...
...
docs/guide/test-fixture.md
View file @
ab799d8e
...
...
@@ -44,7 +44,7 @@ class UserFixture extends ActiveFixture
The fixture data for an
`ActiveFixture`
fixture is usually provided in a file located at
`FixturePath/data/TableName.php`
,
where
`FixturePath`
stands for the directory containing the fixture class file, and
`TableName`
is the name of the table associated with the fixture. In the example above, the file should be
`@app/tests/fixtures/data/
tbl_
user.php`
. The data file should return an array of data rows
`@app/tests/fixtures/data/user.php`
. The data file should return an array of data rows
to be inserted into the user table. For example,
```
php
...
...
docs/guide/upgrade-from-v1.md
View file @
ab799d8e
...
...
@@ -396,7 +396,7 @@ and [[yii\db\QueryBuilder|QueryBuilder]] to generate SQL statements from query o
```
php
$query
=
new
\yii\db\Query
();
$query
->
select
(
'id, name'
)
->
from
(
'
tbl_
user'
)
->
from
(
'user'
)
->
limit
(
10
);
$command
=
$query
->
createCommand
();
...
...
extensions/faker/FixtureController.php
View file @
ab799d8e
...
...
@@ -52,7 +52,7 @@ use yii\helpers\FileHelper;
*
* - `$fixture` - current fixture array.
* - `$faker` - faker generator instance
* - `$index` - current fixture index. For example if user need to generate 3 fixtures for
tbl_user
, it will be 0..2
* - `$index` - current fixture index. For example if user need to generate 3 fixtures for
user table
, it will be 0..2
*
* After you set all needed fields in callback, you need to return $fixture array back from the callback.
*
...
...
extensions/faker/README.md
View file @
ab799d8e
...
...
@@ -62,7 +62,7 @@ If you use callback as a attribute value, then it will be called as shown with t
*
```$fixture```
- current fixture array.
*
```$faker```
- faker generator instance
*
```$index```
- current fixture index. For example if user need to generate 3 fixtures for
tbl_user
, it will be 0..2.
*
```$index```
- current fixture index. For example if user need to generate 3 fixtures for
user table
, it will be 0..2.
After you set all needed fields in callback, you need to return $fixture array back from the callback.
...
...
extensions/gii/generators/model/Generator.php
View file @
ab799d8e
...
...
@@ -93,8 +93,8 @@ class Generator extends \yii\gii\Generator
return
array_merge
(
parent
::
hints
(),
[
'ns'
=>
'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>'
,
'db'
=>
'This is the ID of the DB application component.'
,
'tableName'
=>
'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>
tbl_
post</code>.
The table name may consist of the DB schema part if needed, e.g. <code>public.
tbl_
post</code>.
'tableName'
=>
'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>post</code>.
The table name may consist of the DB schema part if needed, e.g. <code>public.post</code>.
The table name may end with asterisk to match multiple table names, e.g. <code>tbl_*</code>
will match tables who name starts with <code>tbl_</code>. In this case, multiple ActiveRecord classes
will be generated, one for each matching table name; and the class names will be generated from
...
...
extensions/sphinx/Command.php
View file @
ab799d8e
...
...
@@ -135,7 +135,7 @@ class Command extends \yii\db\Command
* For example,
*
* ~~~
* $connection->createCommand()->update('
tbl_
user', ['status' => 1], 'age > 30')->execute();
* $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
* ~~~
*
* The method will properly escape the column names and bind the values to be updated.
...
...
framework/CHANGELOG.md
View file @
ab799d8e
...
...
@@ -228,6 +228,7 @@ Yii Framework 2 Change Log
-
Removed
`yii\web\Controller::getCanonicalUrl`
, use
`yii\helpers\Url::canonical`
instead.
-
Chg #2691: Null parameters will not be included in the generated URLs by
`UrlManager`
(gonimar, qiangxue)
-
Chg #2734:
`FileCache::keyPrefix`
defaults to empty string now (qiangxue)
-
Chg #2911: Removed
`tbl_`
default for table prefix (samdark)
_ Chg #2912: Relative view files will be looked for under the directory containing the view currently being rendered (qiangxue)
-
Chg: Renamed
`yii\jui\Widget::clientEventsMap`
to
`clientEventMap`
(qiangxue)
-
Chg: Renamed
`ActiveRecord::getPopulatedRelations()`
to
`getRelatedRecords()`
(qiangxue)
...
...
framework/caching/DbCache.php
View file @
ab799d8e
...
...
@@ -16,7 +16,7 @@ use yii\di\Instance;
/**
* DbCache implements a cache application component by storing cached data in a database.
*
* By default, DbCache stores session data in a DB table named '
tbl_
cache'. This table
* By default, DbCache stores session data in a DB table named 'cache'. This table
* must be pre-created. The table name can be changed by setting [[cacheTable]].
*
* Please refer to [[Cache]] for common cache operations that are supported by DbCache.
...
...
@@ -47,7 +47,7 @@ class DbCache extends Cache
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE
tbl_
cache (
* CREATE TABLE cache (
* id char(128) NOT NULL PRIMARY KEY,
* expire int(11),
* data BLOB
...
...
framework/console/controllers/MigrateController.php
View file @
ab799d8e
...
...
@@ -33,7 +33,7 @@ use yii\helpers\FileHelper;
* create it as follows:
*
* ~~~
* CREATE TABLE
tbl_
migration (
* CREATE TABLE migration (
* version varchar(180) PRIMARY KEY,
* apply_time integer
* )
...
...
framework/data/ActiveDataProvider.php
View file @
ab799d8e
...
...
@@ -39,7 +39,7 @@ use yii\di\Instance;
* ~~~
* $query = new Query;
* $provider = new ActiveDataProvider([
* 'query' => $query->from('
tbl_
post'),
* 'query' => $query->from('post'),
* 'pagination' => [
* 'pageSize' => 20,
* ],
...
...
framework/data/ArrayDataProvider.php
View file @
ab799d8e
...
...
@@ -30,7 +30,7 @@ use yii\helpers\ArrayHelper;
* ~~~
* $query = new Query;
* $provider = new ArrayDataProvider([
* 'allModels' => $query->from('
tbl_
post')->all(),
* 'allModels' => $query->from('post')->all(),
* 'sort' => [
* 'attributes' => ['id', 'username', 'email'],
* ],
...
...
framework/data/SqlDataProvider.php
View file @
ab799d8e
...
...
@@ -26,11 +26,11 @@ use yii\di\Instance;
*
* ~~~
* $count = Yii::$app->db->createCommand('
* SELECT COUNT(*) FROM
tbl_
user WHERE status=:status
* SELECT COUNT(*) FROM user WHERE status=:status
* ', [':status' => 1])->queryScalar();
*
* $dataProvider = new SqlDataProvider([
* 'sql' => 'SELECT * FROM
tbl_
user WHERE status=:status',
* 'sql' => 'SELECT * FROM user WHERE status=:status',
* 'params' => [':status' => 1],
* 'totalCount' => $count,
* 'sort' => [
...
...
framework/db/ActiveQuery.php
View file @
ab799d8e
...
...
@@ -357,7 +357,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* // find all orders, eager loading "books", and sort the orders and books by the book names.
* Order::find()->joinWith([
* 'books' => function ($query) {
* $query->orderBy('
tbl_
item.name');
* $query->orderBy('item.name');
* }
* ])->all();
* ```
...
...
@@ -628,7 +628,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* public function getItems()
* {
* return $this->hasMany(Item::className(), ['id' => 'item_id'])
* ->viaTable('
tbl_
order_item', ['order_id' => 'id']);
* ->viaTable('order_item', ['order_id' => 'id']);
* }
* ```
*
...
...
framework/db/ActiveRecord.php
View file @
ab799d8e
...
...
@@ -21,8 +21,8 @@ use yii\helpers\StringHelper;
* row in a database table. The object's attributes are mapped to the columns of the corresponding table.
* Referencing an Active Record attribute is equivalent to accessing the corresponding table column for that record.
*
* As an example, say that the `Customer` ActiveRecord class is associated with the `
tbl_
customer` table.
* This would mean that the class's `name` attribute is automatically mapped to the `name` column in `
tbl_customer`
.
* As an example, say that the `Customer` ActiveRecord class is associated with the `customer` table.
* This would mean that the class's `name` attribute is automatically mapped to the `name` column in `
customer` table
.
* Thanks to Active Record, assuming the variable `$customer` is an object of type `Customer`, to get the value of
* the `name` column for the table row, you can use the expression `$customer->name`.
* In this example, Active Record is providing an object-oriented interface for accessing data stored in the database.
...
...
@@ -38,7 +38,7 @@ use yii\helpers\StringHelper;
* {
* public static function tableName()
* {
* return '
tbl_
customer';
* return 'customer';
* }
* }
* ```
...
...
@@ -58,12 +58,12 @@ use yii\helpers\StringHelper;
* ```php
* $user = new User();
* $user->name = 'Qiang';
* $user->save(); // a new row is inserted into
tbl_user
* $user->save(); // a new row is inserted into
user table
*
* // the following will retrieve the user 'CeBe' from the database
* $user = User::find()->where(['name' => 'CeBe'])->one();
*
* // this will get related records from
table tbl_orders
when relation is defined
* // this will get related records from
orders table
when relation is defined
* $orders = $user->orders;
* ```
*
...
...
@@ -131,7 +131,7 @@ class ActiveRecord extends BaseActiveRecord
* Below is an example:
*
* ~~~
* $customers = Customer::findBySql('SELECT * FROM
tbl_
customer')->all();
* $customers = Customer::findBySql('SELECT * FROM customer')->all();
* ~~~
*
* @param string $sql the SQL statement to be executed
...
...
framework/db/BatchQueryResult.php
View file @
ab799d8e
...
...
@@ -17,7 +17,7 @@ use yii\base\Object;
* you can iterate it to obtain a batch of data in each iteration. For example,
*
* ```php
* $query = (new Query)->from('
tbl_
user');
* $query = (new Query)->from('user');
* foreach ($query->batch() as $i => $users) {
* // $users represents the rows in the $i-th batch
* }
...
...
framework/db/Command.php
View file @
ab799d8e
...
...
@@ -23,7 +23,7 @@ use yii\caching\Cache;
* For example,
*
* ~~~
* $users = $connection->createCommand('SELECT * FROM
tbl_
user')->queryAll();
* $users = $connection->createCommand('SELECT * FROM user')->queryAll();
* ~~~
*
* Command supports SQL statement preparation and parameter binding.
...
...
@@ -36,7 +36,7 @@ use yii\caching\Cache;
* [[update()]], etc. For example,
*
* ~~~
* $connection->createCommand()->insert('
tbl_
user', [
* $connection->createCommand()->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ])->execute();
...
...
@@ -438,7 +438,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->insert('
tbl_
user', [
* $connection->createCommand()->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ])->execute();
...
...
@@ -465,7 +465,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->batchInsert('
tbl_
user', ['name', 'age'], [
* $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],
...
...
@@ -491,7 +491,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->update('
tbl_
user', ['status' => 1], 'age > 30')->execute();
* $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
* ~~~
*
* The method will properly escape the column names and bind the values to be updated.
...
...
@@ -517,7 +517,7 @@ class Command extends \yii\base\Component
* For example,
*
* ~~~
* $connection->createCommand()->delete('
tbl_
user', 'status = 0')->execute();
* $connection->createCommand()->delete('user', 'status = 0')->execute();
* ~~~
*
* The method will properly escape the table and column names.
...
...
framework/db/Connection.php
View file @
ab799d8e
...
...
@@ -39,9 +39,9 @@ use yii\caching\Cache;
* After the DB connection is established, one can execute SQL statements like the following:
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM
tbl_
post');
* $command = $connection->createCommand('SELECT * FROM post');
* $posts = $command->queryAll();
* $command = $connection->createCommand('UPDATE
tbl_
post SET status=1');
* $command = $connection->createCommand('UPDATE post SET status=1');
* $command->execute();
* ~~~
*
...
...
@@ -50,7 +50,7 @@ use yii\caching\Cache;
* to prevent SQL injection attacks. The following is an example:
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM
tbl_
post WHERE id=:id');
* $command = $connection->createCommand('SELECT * FROM post WHERE id=:id');
* $command->bindValue(':id', $_GET['id']);
* $post = $command->query();
* ~~~
...
...
@@ -221,7 +221,7 @@ class Connection extends Component
* as `{{%TableName}}`, then the percentage character `%` will be replaced with this
* property value. For example, `{{%post}}` becomes `{{tbl_post}}`.
*/
public
$tablePrefix
=
'
tbl_
'
;
public
$tablePrefix
=
''
;
/**
* @var array mapping between PDO driver names and [[Schema]] classes.
* The keys of the array are PDO driver names while the values the corresponding
...
...
framework/db/DataReader.php
View file @
ab799d8e
...
...
@@ -17,7 +17,7 @@ use yii\base\InvalidCallException;
* iterating through the reader. For example,
*
* ~~~
* $command = $connection->createCommand('SELECT * FROM
tbl_
post');
* $command = $connection->createCommand('SELECT * FROM post');
* $reader = $command->query();
*
* while ($row = $reader->read()) {
...
...
framework/db/Query.php
View file @
ab799d8e
...
...
@@ -25,7 +25,7 @@ use yii\base\Component;
* $query = new Query;
* // compose the query
* $query->select('id, name')
* ->from('
tbl_
user')
* ->from('user')
* ->limit(10);
* // build and execute the query
* $rows = $query->all();
...
...
@@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface
*/
public
$distinct
;
/**
* @var array the table(s) to be selected from. For example, `['
tbl_user', 'tbl_
post']`.
* @var array the table(s) to be selected from. For example, `['
user', '
post']`.
* This is used to construct the FROM clause in a SQL statement.
* @see from()
*/
...
...
@@ -82,8 +82,8 @@ class Query extends Component implements QueryInterface
*
* ~~~
* [
* ['INNER JOIN', '
tbl_user', 'tbl_
user.id = author_id'],
* ['LEFT JOIN', 't
bl_team', 'tbl_
team.id = team_id'],
* ['INNER JOIN', '
user', '
user.id = author_id'],
* ['LEFT JOIN', 't
eam', '
team.id = team_id'],
* ]
* ~~~
*/
...
...
@@ -143,9 +143,9 @@ class Query extends Component implements QueryInterface
* For example,
*
* ```php
* $query = (new Query)->from('
tbl_
user');
* $query = (new Query)->from('user');
* foreach ($query->batch() as $rows) {
* // $rows is an array of 10 or fewer rows from
tbl_user
* // $rows is an array of 10 or fewer rows from
user table
* }
* ```
*
...
...
@@ -171,7 +171,7 @@ class Query extends Component implements QueryInterface
* only one row of data is returned. For example,
*
* ```php
* $query = (new Query)->from('
tbl_
user');
* $query = (new Query)->from('user');
* foreach ($query->each() as $row) {
* }
* ```
...
...
@@ -383,7 +383,7 @@ class Query extends Component implements QueryInterface
* Sets the SELECT part of the query.
* @param string|array $columns the columns to be selected.
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']).
* Columns can
contain table prefixes (e.g. "tbl_user.id") and/or column aliases (e.g. "tbl_
user.id AS user_id").
* Columns can
be prefixed with table names (e.g. "user.id") and/or contain column aliases (e.g. "
user.id AS user_id").
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
*
...
...
@@ -422,9 +422,9 @@ class Query extends Component implements QueryInterface
/**
* Sets the FROM part of the query.
* @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. `'
tbl_
user'`)
* or an array (e.g. `['
tbl_user', 'tbl_
profile']`) specifying one or several table names.
* Table names can contain schema prefixes (e.g. `'public.
tbl_user'`) and/or table aliases (e.g. `'tbl_
user u'`).
* @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. `'user'`)
* or an array (e.g. `['
user', '
profile']`) specifying one or several table names.
* Table names can contain schema prefixes (e.g. `'public.
user'`) and/or table aliases (e.g. `'
user u'`).
* The method will automatically quote the table names unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
...
...
@@ -581,7 +581,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.
tbl_user') and/or table alias (e.g. 'tbl_
user u').
* Table name can contain schema prefix (e.g. 'public.
user') and/or table alias (e.g. '
user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
...
...
@@ -606,7 +606,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.
tbl_user') and/or table alias (e.g. 'tbl_
user u').
* Table name can contain schema prefix (e.g. 'public.
user') and/or table alias (e.g. '
user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
...
...
@@ -631,7 +631,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.
tbl_user') and/or table alias (e.g. 'tbl_
user u').
* Table name can contain schema prefix (e.g. 'public.
user') and/or table alias (e.g. '
user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
...
...
@@ -656,7 +656,7 @@ class Query extends Component implements QueryInterface
* @param string|array $table the table to be joined.
*
* Use string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.
tbl_user') and/or table alias (e.g. 'tbl_
user u').
* Table name can contain schema prefix (e.g. 'public.
user') and/or table alias (e.g. '
user u').
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
*
...
...
framework/db/QueryBuilder.php
View file @
ab799d8e
...
...
@@ -94,7 +94,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->insert('
tbl_
user', [
* $sql = $queryBuilder->insert('user', [
* 'name' => 'Sam',
* 'age' => 30,
* ], $params);
...
...
@@ -141,7 +141,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->batchInsert('
tbl_
user', ['name', 'age'], [
* $sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],
...
...
@@ -196,7 +196,7 @@ class QueryBuilder extends \yii\base\Object
*
* ~~~
* $params = [];
* $sql = $queryBuilder->update('
tbl_
user', ['status' => 1], 'age > 30', $params);
* $sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
* ~~~
*
* The method will properly escape the table and column names.
...
...
@@ -242,7 +242,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->delete('
tbl_
user', 'status = 0');
* $sql = $queryBuilder->delete('user', 'status = 0');
* ~~~
*
* The method will properly escape the table and column names.
...
...
@@ -276,7 +276,7 @@ class QueryBuilder extends \yii\base\Object
* For example,
*
* ~~~
* $sql = $queryBuilder->createTable('
tbl_
user', [
* $sql = $queryBuilder->createTable('user', [
* 'id' => 'pk',
* 'name' => 'string',
* 'age' => 'integer',
...
...
framework/db/sqlite/QueryBuilder.php
View file @
ab799d8e
...
...
@@ -46,7 +46,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
* For example,
*
* ~~~
* $connection->createCommand()->batchInsert('
tbl_
user', ['name', 'age'], [
* $connection->createCommand()->batchInsert('user', ['name', 'age'], [
* ['Tom', 30],
* ['Jane', 20],
* ['Linda', 25],
...
...
framework/i18n/DbMessageSource.php
View file @
ab799d8e
...
...
@@ -22,23 +22,23 @@ use yii\db\Query;
* The database must contain the following two tables:
*
* ~~~
* CREATE TABLE
tbl_
source_message (
* CREATE TABLE source_message (
* id INTEGER PRIMARY KEY AUTO_INCREMENT,
* category VARCHAR(32),
* message TEXT
* );
*
* CREATE TABLE
tbl_
message (
* CREATE TABLE message (
* id INTEGER,
* language VARCHAR(16),
* translation TEXT,
* PRIMARY KEY (id, language),
* CONSTRAINT fk_message_source_message FOREIGN KEY (id)
* REFERENCES
tbl_
source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT
* REFERENCES source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT
* );
* ~~~
*
* The `
tbl_source_message` table stores the messages to be translated, and the `tbl_
message` table stores
* The `
source_message` table stores the messages to be translated, and the `
message` table stores
* the translated messages. The name of these two tables can be customized by setting [[sourceMessageTable]]
* and [[messageTable]], respectively.
*
...
...
framework/log/DbTarget.php
View file @
ab799d8e
...
...
@@ -15,7 +15,7 @@ use yii\di\Instance;
/**
* DbTarget stores log messages in a database table.
*
* By default, DbTarget stores the log messages in a DB table named '
tbl_
log'. This table
* By default, DbTarget stores the log messages in a DB table named 'log'. This table
* must be pre-created. The table name can be changed by setting [[logTable]].
*
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -34,7 +34,7 @@ class DbTarget extends Target
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE
tbl_
log (
* CREATE TABLE log (
* id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
* level INTEGER,
* category VARCHAR(255),
...
...
framework/rbac/DbManager.php
View file @
ab799d8e
...
...
@@ -39,15 +39,15 @@ class DbManager extends Manager
*/
public
$db
=
'db'
;
/**
* @var string the name of the table storing authorization items. Defaults to '
tbl_
auth_item'.
* @var string the name of the table storing authorization items. Defaults to 'auth_item'.
*/
public
$itemTable
=
'{{%auth_item}}'
;
/**
* @var string the name of the table storing authorization item hierarchy. Defaults to '
tbl_
auth_item_child'.
* @var string the name of the table storing authorization item hierarchy. Defaults to 'auth_item_child'.
*/
public
$itemChildTable
=
'{{%auth_item_child}}'
;
/**
* @var string the name of the table storing authorization item assignments. Defaults to '
tbl_
auth_assignment'.
* @var string the name of the table storing authorization item assignments. Defaults to 'auth_assignment'.
*/
public
$assignmentTable
=
'{{%auth_assignment}}'
;
...
...
framework/rbac/schema-mssql.sql
View file @
ab799d8e
...
...
@@ -9,11 +9,11 @@
* @since 2.0
*/
drop
table
if
exists
[
tbl_
auth_assignment
];
drop
table
if
exists
[
tbl_
auth_item_child
];
drop
table
if
exists
[
tbl_
auth_item
];
drop
table
if
exists
[
auth_assignment
];
drop
table
if
exists
[
auth_item_child
];
drop
table
if
exists
[
auth_item
];
create
table
[
tbl_
auth_item
]
create
table
[
auth_item
]
(
[
name
]
varchar
(
64
)
not
null
,
[
type
]
integer
not
null
,
...
...
@@ -24,21 +24,21 @@ create table [tbl_auth_item]
key
[
type
]
([
type
])
);
create
table
[
tbl_
auth_item_child
]
create
table
[
auth_item_child
]
(
[
parent
]
varchar
(
64
)
not
null
,
[
child
]
varchar
(
64
)
not
null
,
primary
key
([
parent
],[
child
]),
foreign
key
([
parent
])
references
[
tbl_
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
,
foreign
key
([
child
])
references
[
tbl_
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
foreign
key
([
parent
])
references
[
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
,
foreign
key
([
child
])
references
[
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
);
create
table
[
tbl_
auth_assignment
]
create
table
[
auth_assignment
]
(
[
item_name
]
varchar
(
64
)
not
null
,
[
user_id
]
varchar
(
64
)
not
null
,
[
biz_rule
]
text
,
[
data
]
text
,
primary
key
([
item_name
],[
user_id
]),
foreign
key
([
item_name
])
references
[
tbl_
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
foreign
key
([
item_name
])
references
[
auth_item
]
([
name
])
on
delete
cascade
on
update
cascade
);
framework/rbac/schema-mysql.sql
View file @
ab799d8e
...
...
@@ -9,11 +9,11 @@
* @since 2.0
*/
drop
table
if
exists
`
tbl_
auth_assignment`
;
drop
table
if
exists
`
tbl_
auth_item_child`
;
drop
table
if
exists
`
tbl_
auth_item`
;
drop
table
if
exists
`auth_assignment`
;
drop
table
if
exists
`auth_item_child`
;
drop
table
if
exists
`auth_item`
;
create
table
`
tbl_
auth_item`
create
table
`auth_item`
(
`name`
varchar
(
64
)
not
null
,
`type`
integer
not
null
,
...
...
@@ -24,21 +24,21 @@ create table `tbl_auth_item`
key
`type`
(
`type`
)
)
engine
InnoDB
;
create
table
`
tbl_
auth_item_child`
create
table
`auth_item_child`
(
`parent`
varchar
(
64
)
not
null
,
`child`
varchar
(
64
)
not
null
,
primary
key
(
`parent`
,
`child`
),
foreign
key
(
`parent`
)
references
`
tbl_
auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
`child`
)
references
`
tbl_
auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
foreign
key
(
`parent`
)
references
`auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
`child`
)
references
`auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
)
engine
InnoDB
;
create
table
`
tbl_
auth_assignment`
create
table
`auth_assignment`
(
`item_name`
varchar
(
64
)
not
null
,
`user_id`
varchar
(
64
)
not
null
,
`biz_rule`
text
,
`data`
text
,
primary
key
(
`item_name`
,
`user_id`
),
foreign
key
(
`item_name`
)
references
`
tbl_
auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
foreign
key
(
`item_name`
)
references
`auth_item`
(
`name`
)
on
delete
cascade
on
update
cascade
)
engine
InnoDB
;
framework/rbac/schema-oci.sql
View file @
ab799d8e
...
...
@@ -9,11 +9,11 @@
* @since 2.0
*/
drop
table
if
exists
"
tbl_
auth_assignment"
;
drop
table
if
exists
"
tbl_
auth_item_child"
;
drop
table
if
exists
"
tbl_
auth_item"
;
drop
table
if
exists
"auth_assignment"
;
drop
table
if
exists
"auth_item_child"
;
drop
table
if
exists
"auth_item"
;
create
table
"
tbl_
auth_item"
create
table
"auth_item"
(
"name"
varchar
(
64
)
not
null
,
"type"
integer
not
null
,
...
...
@@ -24,21 +24,21 @@ create table "tbl_auth_item"
key
"type"
(
"type"
)
);
create
table
"
tbl_
auth_item_child"
create
table
"auth_item_child"
(
"parent"
varchar
(
64
)
not
null
,
"child"
varchar
(
64
)
not
null
,
primary
key
(
"parent"
,
"child"
),
foreign
key
(
"parent"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"parent"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
);
create
table
"
tbl_
auth_assignment"
create
table
"auth_assignment"
(
"item_name"
varchar
(
64
)
not
null
,
"user_id"
varchar
(
64
)
not
null
,
"biz_rule"
text
,
"data"
text
,
primary
key
(
"item_name"
,
"user_id"
),
foreign
key
(
"item_name"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"item_name"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
);
framework/rbac/schema-pgsql.sql
View file @
ab799d8e
...
...
@@ -9,11 +9,11 @@
* @since 2.0
*/
drop
table
if
exists
"
tbl_
auth_assignment"
;
drop
table
if
exists
"
tbl_
auth_item_child"
;
drop
table
if
exists
"
tbl_
auth_item"
;
drop
table
if
exists
"auth_assignment"
;
drop
table
if
exists
"auth_item_child"
;
drop
table
if
exists
"auth_item"
;
create
table
"
tbl_
auth_item"
create
table
"auth_item"
(
"name"
varchar
(
64
)
not
null
,
"type"
integer
not
null
,
...
...
@@ -23,23 +23,23 @@ create table "tbl_auth_item"
primary
key
(
"name"
)
);
create
index
tbl_auth_item_type_idx
on
"tbl_
auth_item"
(
"type"
);
create
index
auth_item_type_idx
on
"
auth_item"
(
"type"
);
create
table
"
tbl_
auth_item_child"
create
table
"auth_item_child"
(
"parent"
varchar
(
64
)
not
null
,
"child"
varchar
(
64
)
not
null
,
primary
key
(
"parent"
,
"child"
),
foreign
key
(
"parent"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"parent"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
);
create
table
"
tbl_
auth_assignment"
create
table
"auth_assignment"
(
"item_name"
varchar
(
64
)
not
null
,
"user_id"
varchar
(
64
)
not
null
,
"biz_rule"
text
,
"data"
text
,
primary
key
(
"item_name"
,
"user_id"
),
foreign
key
(
"item_name"
)
references
"
tbl_
auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"item_name"
)
references
"auth_item"
(
"name"
)
on
delete
cascade
on
update
cascade
);
framework/rbac/schema-sqlite.sql
View file @
ab799d8e
...
...
@@ -9,11 +9,11 @@
* @since 2.0
*/
drop
table
if
exists
'
tbl_
auth_assignment'
;
drop
table
if
exists
'
tbl_
auth_item_child'
;
drop
table
if
exists
'
tbl_
auth_item'
;
drop
table
if
exists
'auth_assignment'
;
drop
table
if
exists
'auth_item_child'
;
drop
table
if
exists
'auth_item'
;
create
table
'
tbl_
auth_item'
create
table
'auth_item'
(
"name"
varchar
(
64
)
not
null
,
"type"
integer
not
null
,
...
...
@@ -24,21 +24,21 @@ create table 'tbl_auth_item'
key
"type"
(
"type"
)
);
create
table
'
tbl_
auth_item_child'
create
table
'auth_item_child'
(
"parent"
varchar
(
64
)
not
null
,
"child"
varchar
(
64
)
not
null
,
primary
key
(
"parent"
,
"child"
),
foreign
key
(
"parent"
)
references
'
tbl_
auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
'
tbl_
auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"parent"
)
references
'auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
,
foreign
key
(
"child"
)
references
'auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
);
create
table
'
tbl_
auth_assignment'
create
table
'auth_assignment'
(
"item_name"
varchar
(
64
)
not
null
,
"user_id"
varchar
(
64
)
not
null
,
"biz_rule"
text
,
"data"
text
,
primary
key
(
"item_name"
,
"user_id"
),
foreign
key
(
"item_name"
)
references
'
tbl_
auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
foreign
key
(
"item_name"
)
references
'auth_item'
(
"name"
)
on
delete
cascade
on
update
cascade
);
framework/web/DbSession.php
View file @
ab799d8e
...
...
@@ -16,7 +16,7 @@ use yii\di\Instance;
/**
* DbSession extends [[Session]] by using database as session data storage.
*
* By default, DbSession stores session data in a DB table named '
tbl_
session'. This table
* By default, DbSession stores session data in a DB table named 'session'. This table
* must be pre-created. The table name can be changed by setting [[sessionTable]].
*
* The following example shows how you can configure the application to use DbSession:
...
...
@@ -48,7 +48,7 @@ class DbSession extends Session
* The table should be pre-created as follows:
*
* ~~~
* CREATE TABLE
tbl_
session
* CREATE TABLE session
* (
* id CHAR(40) NOT NULL PRIMARY KEY,
* expire INTEGER,
...
...
tests/unit/data/ar/Category.php
View file @
ab799d8e
...
...
@@ -17,7 +17,7 @@ class Category extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
category'
;
return
'category'
;
}
public
function
getItems
()
...
...
tests/unit/data/ar/Customer.php
View file @
ab799d8e
...
...
@@ -25,7 +25,7 @@ class Customer extends ActiveRecord
public
static
function
tableName
()
{
return
'
tbl_
customer'
;
return
'customer'
;
}
public
function
getProfile
()
...
...
@@ -49,9 +49,9 @@ class Customer extends ActiveRecord
/** @var ActiveQuery $rel */
$rel
=
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
]);
return
$rel
->
viaTable
(
'
tbl_
order_item'
,
[
'order_id'
=>
'id'
],
function
(
$q
)
{
return
$rel
->
viaTable
(
'order_item'
,
[
'order_id'
=>
'id'
],
function
(
$q
)
{
/** @var ActiveQuery $q */
$q
->
viaTable
(
'
tbl_
order'
,
[
'customer_id'
=>
'id'
]);
$q
->
viaTable
(
'order'
,
[
'customer_id'
=>
'id'
]);
})
->
orderBy
(
'id'
);
}
...
...
tests/unit/data/ar/Item.php
View file @
ab799d8e
...
...
@@ -13,7 +13,7 @@ class Item extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
item'
;
return
'item'
;
}
public
function
getCategory
()
...
...
tests/unit/data/ar/NullValues.php
View file @
ab799d8e
...
...
@@ -15,6 +15,6 @@ class NullValues extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
null_values'
;
return
'null_values'
;
}
}
tests/unit/data/ar/Order.php
View file @
ab799d8e
...
...
@@ -14,7 +14,7 @@ class Order extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
order'
;
return
'order'
;
}
public
function
getCustomer
()
...
...
@@ -59,7 +59,7 @@ class Order extends ActiveRecord
public
function
getBooks
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
viaTable
(
'
tbl_
order_item'
,
[
'order_id'
=>
'id'
])
->
viaTable
(
'order_item'
,
[
'order_id'
=>
'id'
])
->
where
([
'category_id'
=>
1
]);
}
...
...
@@ -67,7 +67,7 @@ class Order extends ActiveRecord
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
onCondition
([
'category_id'
=>
1
])
->
viaTable
(
'
tbl_
order_item'
,
[
'order_id'
=>
'id'
]);
->
viaTable
(
'order_item'
,
[
'order_id'
=>
'id'
]);
}
public
function
beforeSave
(
$insert
)
...
...
tests/unit/data/ar/OrderItem.php
View file @
ab799d8e
...
...
@@ -14,7 +14,7 @@ class OrderItem extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
order_item'
;
return
'order_item'
;
}
public
function
getOrder
()
...
...
tests/unit/data/ar/Profile.php
View file @
ab799d8e
...
...
@@ -16,6 +16,6 @@ class Profile extends ActiveRecord
{
public
static
function
tableName
()
{
return
'
tbl_
profile'
;
return
'profile'
;
}
}
tests/unit/data/ar/Type.php
View file @
ab799d8e
...
...
@@ -3,7 +3,7 @@
namespace
yiiunit\data\ar
;
/**
* Model representing t
bl_t
ype table
* Model representing type table
*
* @property int $int_col
* @property int $int_col2 DEFAULT 1
...
...
@@ -25,7 +25,7 @@ class Type extends ActiveRecord
*/
public
static
function
tableName
()
{
return
't
bl_t
ype'
;
return
'type'
;
}
}
\ No newline at end of file
tests/unit/data/ar/elasticsearch/Order.php
View file @
ab799d8e
...
...
@@ -59,7 +59,7 @@ class Order extends ActiveRecord
// public function getBooks()
// {
// return $this->hasMany('Item', ['id' => 'item_id'])
// ->viaTable('
tbl_
order_item', ['order_id' => 'id'])
// ->viaTable('order_item', ['order_id' => 'id'])
// ->where(['category_id' => 1]);
// }
...
...
tests/unit/data/cubrid.sql
View file @
ab799d8e
...
...
@@ -3,31 +3,31 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP
TABLE
IF
EXISTS
tbl_
composite_fk
;
DROP
TABLE
IF
EXISTS
tbl_
order_item
;
DROP
TABLE
IF
EXISTS
tbl_
item
;
DROP
TABLE
IF
EXISTS
tbl_
order
;
DROP
TABLE
IF
EXISTS
tbl_
category
;
DROP
TABLE
IF
EXISTS
tbl_
customer
;
DROP
TABLE
IF
EXISTS
tbl_
profile
;
DROP
TABLE
IF
EXISTS
tbl_
null_values
;
DROP
TABLE
IF
EXISTS
t
bl_t
ype
;
DROP
TABLE
IF
EXISTS
tbl_
constraints
;
CREATE
TABLE
`
tbl_
constraints`
DROP
TABLE
IF
EXISTS
composite_fk
;
DROP
TABLE
IF
EXISTS
order_item
;
DROP
TABLE
IF
EXISTS
item
;
DROP
TABLE
IF
EXISTS
order
;
DROP
TABLE
IF
EXISTS
category
;
DROP
TABLE
IF
EXISTS
customer
;
DROP
TABLE
IF
EXISTS
profile
;
DROP
TABLE
IF
EXISTS
null_values
;
DROP
TABLE
IF
EXISTS
type
;
DROP
TABLE
IF
EXISTS
constraints
;
CREATE
TABLE
`constraints`
(
`id`
integer
not
null
,
`field1`
varchar
(
255
)
);
CREATE
TABLE
`
tbl_
profile`
(
CREATE
TABLE
`profile`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`description`
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
);
CREATE
TABLE
`
tbl_
customer`
(
CREATE
TABLE
`customer`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`email`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
),
...
...
@@ -37,40 +37,40 @@ CREATE TABLE `tbl_customer` (
PRIMARY
KEY
(
`id`
)
);
CREATE
TABLE
`
tbl_
category`
(
CREATE
TABLE
`category`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
);
CREATE
TABLE
`
tbl_
item`
(
CREATE
TABLE
`item`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
128
)
NOT
NULL
,
`category_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_item_category_id`
FOREIGN
KEY
(
`category_id`
)
REFERENCES
`
tbl_
category`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_item_category_id`
FOREIGN
KEY
(
`category_id`
)
REFERENCES
`category`
(
`id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
`
tbl_
order`
(
CREATE
TABLE
`order`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`customer_id`
int
(
11
)
NOT
NULL
,
`created_at`
int
(
11
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`
tbl_
customer`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`customer`
(
`id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
`
tbl_
order_item`
(
CREATE
TABLE
`order_item`
(
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
`quantity`
int
(
11
)
NOT
NULL
,
`subtotal`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`order_id`
,
`item_id`
),
CONSTRAINT
`FK_order_item_order_id`
FOREIGN
KEY
(
`order_id`
)
REFERENCES
`
tbl_
order`
(
`id`
)
ON
DELETE
CASCADE
,
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`
tbl_
item`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_item_order_id`
FOREIGN
KEY
(
`order_id`
)
REFERENCES
`order`
(
`id`
)
ON
DELETE
CASCADE
,
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`item`
(
`id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
tbl_
null_values
(
CREATE
TABLE
null_values
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`var1`
INT
NULL
,
`var2`
INT
NULL
,
...
...
@@ -80,7 +80,7 @@ CREATE TABLE tbl_null_values (
);
CREATE
TABLE
`t
bl_t
ype`
(
CREATE
TABLE
`type`
(
`int_col`
int
(
11
)
NOT
NULL
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
`char_col`
char
(
100
)
NOT
NULL
,
...
...
@@ -96,37 +96,37 @@ CREATE TABLE `tbl_type` (
`bool_col2`
tinyint
DEFAULT
'1'
);
CREATE
TABLE
`
tbl_
composite_fk`
(
CREATE
TABLE
`composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`
tbl_
order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
tests/unit/data/mssql.sql
View file @
ab799d8e
IF
OBJECT_ID
(
'[dbo].[
tbl_order_item]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
order_item
];
IF
OBJECT_ID
(
'[dbo].[
tbl_item]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
item
];
IF
OBJECT_ID
(
'[dbo].[
tbl_order]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
order
];
IF
OBJECT_ID
(
'[dbo].[
tbl_category]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
category
];
IF
OBJECT_ID
(
'[dbo].[
tbl_customer]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
customer
];
IF
OBJECT_ID
(
'[dbo].[
tbl_profile]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
profile
];
IF
OBJECT_ID
(
'[dbo].[t
bl_type]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
type
];
IF
OBJECT_ID
(
'[dbo].[
tbl_null_values]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_
null_values
];
IF
OBJECT_ID
(
'[dbo].[
order_item]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
order_item
];
IF
OBJECT_ID
(
'[dbo].[
item]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
item
];
IF
OBJECT_ID
(
'[dbo].[
order]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
order
];
IF
OBJECT_ID
(
'[dbo].[
category]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
category
];
IF
OBJECT_ID
(
'[dbo].[
customer]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
customer
];
IF
OBJECT_ID
(
'[dbo].[
profile]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
profile
];
IF
OBJECT_ID
(
'[dbo].[t
ype]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
type
];
IF
OBJECT_ID
(
'[dbo].[
null_values]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
null_values
];
CREATE
TABLE
[
dbo
].[
tbl_
profile
]
(
CREATE
TABLE
[
dbo
].[
profile
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
description
]
[
varchar
](
128
)
NOT
NULL
,
CONSTRAINT
[
PK_customer
]
PRIMARY
KEY
CLUSTERED
(
...
...
@@ -15,7 +15,7 @@ CREATE TABLE [dbo].[tbl_profile] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
customer
]
(
CREATE
TABLE
[
dbo
].[
customer
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
email
]
[
varchar
](
128
)
NOT
NULL
,
[
name
]
[
varchar
](
128
),
...
...
@@ -27,7 +27,7 @@ CREATE TABLE [dbo].[tbl_customer] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
category
]
(
CREATE
TABLE
[
dbo
].[
category
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
name
]
[
varchar
](
128
)
NOT
NULL
,
CONSTRAINT
[
PK_category
]
PRIMARY
KEY
CLUSTERED
(
...
...
@@ -35,7 +35,7 @@ CREATE TABLE [dbo].[tbl_category] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
item
]
(
CREATE
TABLE
[
dbo
].[
item
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
name
]
[
varchar
](
128
)
NOT
NULL
,
[
category_id
]
[
int
]
NOT
NULL
,
...
...
@@ -44,7 +44,7 @@ CREATE TABLE [dbo].[tbl_item] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
order
]
(
CREATE
TABLE
[
dbo
].[
order
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
customer_id
]
[
int
]
NOT
NULL
,
[
created_at
]
[
int
]
NOT
NULL
,
...
...
@@ -54,7 +54,7 @@ CREATE TABLE [dbo].[tbl_order] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
order_item
]
(
CREATE
TABLE
[
dbo
].[
order_item
]
(
[
order_id
]
[
int
]
NOT
NULL
,
[
item_id
]
[
int
]
NOT
NULL
,
[
quantity
]
[
int
]
NOT
NULL
,
...
...
@@ -65,7 +65,7 @@ CREATE TABLE [dbo].[tbl_order_item] (
)
ON
[
PRIMARY
]
);
CREATE
TABLE
[
dbo
].[
tbl_
null_values
]
(
CREATE
TABLE
[
dbo
].[
null_values
]
(
id
[
int
]
UNSIGNED
NOT
NULL
,
var1
[
int
]
UNSIGNED
NULL
,
var2
[
int
]
NULL
,
...
...
@@ -74,7 +74,7 @@ CREATE TABLE [dbo].[tbl_null_values] (
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
[
dbo
].[
t
bl_t
ype
]
(
CREATE
TABLE
[
dbo
].[
type
]
(
[
int_col
]
[
int
]
NOT
NULL
,
[
int_col2
]
[
int
]
DEFAULT
'1'
,
[
char_col
]
[
char
](
100
)
NOT
NULL
,
...
...
@@ -89,29 +89,29 @@ CREATE TABLE [dbo].[tbl_type] (
[
bool_col2
]
[
tinyint
]
DEFAULT
'1'
);
INSERT
INTO
[
dbo
].[
tbl_
profile
]
([
description
])
VALUES
(
'profile customer 1'
);
INSERT
INTO
[
dbo
].[
tbl_
profile
]
([
description
])
VALUES
(
'profile customer 3'
);
INSERT
INTO
[
dbo
].[
profile
]
([
description
])
VALUES
(
'profile customer 1'
);
INSERT
INTO
[
dbo
].[
profile
]
([
description
])
VALUES
(
'profile customer 3'
);
INSERT
INTO
[
dbo
].[
tbl_
customer
]
([
email
],
[
name
],
[
address
],
[
status
],
[
profile_id
])
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
[
dbo
].[
tbl_
customer
]
([
email
],
[
name
],
[
address
],
[
status
])
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
[
dbo
].[
tbl_
customer
]
([
email
],
[
name
],
[
address
],
[
status
],
[
profile_id
])
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
[
dbo
].[
customer
]
([
email
],
[
name
],
[
address
],
[
status
],
[
profile_id
])
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
[
dbo
].[
customer
]
([
email
],
[
name
],
[
address
],
[
status
])
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
[
dbo
].[
customer
]
([
email
],
[
name
],
[
address
],
[
status
],
[
profile_id
])
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
[
dbo
].[
tbl_
category
]
([
name
])
VALUES
(
'Books'
);
INSERT
INTO
[
dbo
].[
tbl_
category
]
([
name
])
VALUES
(
'Movies'
);
INSERT
INTO
[
dbo
].[
category
]
([
name
])
VALUES
(
'Books'
);
INSERT
INTO
[
dbo
].[
category
]
([
name
])
VALUES
(
'Movies'
);
INSERT
INTO
[
dbo
].[
tbl_
item
]
([
name
],
[
category_id
])
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
[
dbo
].[
tbl_
item
]
([
name
],
[
category_id
])
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
[
dbo
].[
tbl_
item
]
([
name
],
[
category_id
])
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_
item
]
([
name
],
[
category_id
])
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_
item
]
([
name
],
[
category_id
])
VALUES
(
'Cars'
,
2
);
INSERT
INTO
[
dbo
].[
item
]
([
name
],
[
category_id
])
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
[
dbo
].[
item
]
([
name
],
[
category_id
])
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
[
dbo
].[
item
]
([
name
],
[
category_id
])
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
[
dbo
].[
item
]
([
name
],
[
category_id
])
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
[
dbo
].[
item
]
([
name
],
[
category_id
])
VALUES
(
'Cars'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
[
dbo
].[
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
[
dbo
].[
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
[
dbo
].[
order
]
([
customer_id
],
[
created_at
],
[
total
])
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
[
dbo
].[
tbl_
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
3
,
2
,
1
,
40
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
[
dbo
].[
order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
3
,
2
,
1
,
40
.
0
);
tests/unit/data/mysql.sql
View file @
ab799d8e
...
...
@@ -3,31 +3,31 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP
TABLE
IF
EXISTS
tbl_
composite_fk
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
order
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
profile
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
t
bl_t
ype
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
constraints
CASCADE
;
CREATE
TABLE
`
tbl_
constraints`
DROP
TABLE
IF
EXISTS
composite_fk
CASCADE
;
DROP
TABLE
IF
EXISTS
order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
item
CASCADE
;
DROP
TABLE
IF
EXISTS
order
CASCADE
;
DROP
TABLE
IF
EXISTS
category
CASCADE
;
DROP
TABLE
IF
EXISTS
customer
CASCADE
;
DROP
TABLE
IF
EXISTS
profile
CASCADE
;
DROP
TABLE
IF
EXISTS
null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
type
CASCADE
;
DROP
TABLE
IF
EXISTS
constraints
CASCADE
;
CREATE
TABLE
`constraints`
(
`id`
integer
not
null
,
`field1`
varchar
(
255
)
);
CREATE
TABLE
`
tbl_
profile`
(
CREATE
TABLE
`profile`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`description`
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
customer`
(
CREATE
TABLE
`customer`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`email`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
),
...
...
@@ -37,50 +37,50 @@ CREATE TABLE `tbl_customer` (
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
category`
(
CREATE
TABLE
`category`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
item`
(
CREATE
TABLE
`item`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
128
)
NOT
NULL
,
`category_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
KEY
`FK_item_category_id`
(
`category_id`
),
CONSTRAINT
`FK_item_category_id`
FOREIGN
KEY
(
`category_id`
)
REFERENCES
`
tbl_
category`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_item_category_id`
FOREIGN
KEY
(
`category_id`
)
REFERENCES
`category`
(
`id`
)
ON
DELETE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
order`
(
CREATE
TABLE
`order`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`customer_id`
int
(
11
)
NOT
NULL
,
`created_at`
int
(
11
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`
tbl_
customer`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`customer`
(
`id`
)
ON
DELETE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
order_item`
(
CREATE
TABLE
`order_item`
(
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
`quantity`
int
(
11
)
NOT
NULL
,
`subtotal`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`order_id`
,
`item_id`
),
KEY
`FK_order_item_item_id`
(
`item_id`
),
CONSTRAINT
`FK_order_item_order_id`
FOREIGN
KEY
(
`order_id`
)
REFERENCES
`
tbl_
order`
(
`id`
)
ON
DELETE
CASCADE
,
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`
tbl_
item`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_item_order_id`
FOREIGN
KEY
(
`order_id`
)
REFERENCES
`order`
(
`id`
)
ON
DELETE
CASCADE
,
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`item`
(
`id`
)
ON
DELETE
CASCADE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`
tbl_
composite_fk`
(
CREATE
TABLE
`composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`
tbl_
order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
tbl_
null_values
(
CREATE
TABLE
null_values
(
`id`
INT
(
11
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,
`var1`
INT
UNSIGNED
NULL
,
`var2`
INT
NULL
,
...
...
@@ -89,7 +89,7 @@ CREATE TABLE tbl_null_values (
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
`t
bl_t
ype`
(
CREATE
TABLE
`type`
(
`int_col`
int
(
11
)
NOT
NULL
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
`char_col`
char
(
100
)
NOT
NULL
,
...
...
@@ -104,61 +104,61 @@ CREATE TABLE `tbl_type` (
`bool_col2`
tinyint
(
1
)
DEFAULT
'1'
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
/**
* (MySQL-)Database Schema for validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_
validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
validator_ref
CASCADE
;
DROP
TABLE
IF
EXISTS
validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
validator_ref
CASCADE
;
CREATE
TABLE
tbl_
validator_main
(
CREATE
TABLE
validator_main
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`field1`
VARCHAR
(
255
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
tbl_
validator_ref
(
CREATE
TABLE
validator_ref
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`a_field`
VARCHAR
(
255
),
`ref`
INT
(
11
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_3'
,
3
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_5'
,
5
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_3'
,
3
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
a_field
,
ref
)
VALUES
(
'ref_to_5'
,
5
);
tests/unit/data/postgres.sql
View file @
ab799d8e
...
...
@@ -4,28 +4,28 @@
* and create an account 'postgres/postgres' which owns this test database.
*/
DROP
TABLE
IF
EXISTS
tbl_
order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
item
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
order
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
profile
CASCADE
;
DROP
TABLE
IF
EXISTS
t
bl_t
ype
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
constraints
CASCADE
;
CREATE
TABLE
tbl_
constraints
DROP
TABLE
IF
EXISTS
order_item
CASCADE
;
DROP
TABLE
IF
EXISTS
item
CASCADE
;
DROP
TABLE
IF
EXISTS
order
CASCADE
;
DROP
TABLE
IF
EXISTS
category
CASCADE
;
DROP
TABLE
IF
EXISTS
customer
CASCADE
;
DROP
TABLE
IF
EXISTS
profile
CASCADE
;
DROP
TABLE
IF
EXISTS
type
CASCADE
;
DROP
TABLE
IF
EXISTS
null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
constraints
CASCADE
;
CREATE
TABLE
constraints
(
id
integer
not
null
,
field1
varchar
(
255
)
);
CREATE
TABLE
tbl_
profile
(
CREATE
TABLE
profile
(
id
serial
not
null
primary
key
,
description
varchar
(
128
)
NOT
NULL
);
CREATE
TABLE
tbl_
customer
(
CREATE
TABLE
customer
(
id
serial
not
null
primary
key
,
email
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
),
...
...
@@ -34,35 +34,35 @@ CREATE TABLE tbl_customer (
profile_id
integer
);
comment
on
column
public
.
tbl_
customer
.
email
is
'someone@example.com'
;
comment
on
column
public
.
customer
.
email
is
'someone@example.com'
;
CREATE
TABLE
tbl_
category
(
CREATE
TABLE
category
(
id
serial
not
null
primary
key
,
name
varchar
(
128
)
NOT
NULL
);
CREATE
TABLE
tbl_
item
(
CREATE
TABLE
item
(
id
serial
not
null
primary
key
,
name
varchar
(
128
)
NOT
NULL
,
category_id
integer
NOT
NULL
references
tbl_
category
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
category_id
integer
NOT
NULL
references
category
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
);
CREATE
TABLE
tbl_
order
(
CREATE
TABLE
order
(
id
serial
not
null
primary
key
,
customer_id
integer
NOT
NULL
references
tbl_
customer
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
customer_id
integer
NOT
NULL
references
customer
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
created_at
integer
NOT
NULL
,
total
decimal
(
10
,
0
)
NOT
NULL
);
CREATE
TABLE
tbl_
order_item
(
order_id
integer
NOT
NULL
references
tbl_
order
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
item_id
integer
NOT
NULL
references
tbl_
item
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
CREATE
TABLE
order_item
(
order_id
integer
NOT
NULL
references
order
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
item_id
integer
NOT
NULL
references
item
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
quantity
integer
NOT
NULL
,
subtotal
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
order_id
,
item_id
)
);
CREATE
TABLE
tbl_
null_values
(
CREATE
TABLE
null_values
(
id
INT
NOT
NULL
,
var1
INT
NULL
,
var2
INT
NULL
,
...
...
@@ -71,7 +71,7 @@ CREATE TABLE tbl_null_values (
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
t
bl_t
ype
(
CREATE
TABLE
type
(
int_col
integer
NOT
NULL
,
int_col2
integer
DEFAULT
'1'
,
char_col
char
(
100
)
NOT
NULL
,
...
...
@@ -86,58 +86,58 @@ CREATE TABLE tbl_type (
bool_col2
smallint
DEFAULT
'1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
/**
* (Postgres-)Database Schema for validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_
validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_
validator_ref
CASCADE
;
DROP
TABLE
IF
EXISTS
validator_main
CASCADE
;
DROP
TABLE
IF
EXISTS
validator_ref
CASCADE
;
CREATE
TABLE
tbl_
validator_main
(
CREATE
TABLE
validator_main
(
id
integer
not
null
primary
key
,
field1
VARCHAR
(
255
)
);
CREATE
TABLE
tbl_
validator_ref
(
CREATE
TABLE
validator_ref
(
id
integer
not
null
primary
key
,
a_field
VARCHAR
(
255
),
ref
integer
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
tests/unit/data/sqlite.sql
View file @
ab799d8e
...
...
@@ -3,23 +3,23 @@
* The database setup in config.php is required to perform then relevant tests:
*/
DROP
TABLE
IF
EXISTS
tbl_
composite_fk
;
DROP
TABLE
IF
EXISTS
tbl_
order_item
;
DROP
TABLE
IF
EXISTS
tbl_
item
;
DROP
TABLE
IF
EXISTS
tbl_
order
;
DROP
TABLE
IF
EXISTS
tbl_
category
;
DROP
TABLE
IF
EXISTS
tbl_
customer
;
DROP
TABLE
IF
EXISTS
tbl_
profile
;
DROP
TABLE
IF
EXISTS
t
bl_t
ype
;
DROP
TABLE
IF
EXISTS
tbl_
null_values
;
CREATE
TABLE
tbl_
profile
(
DROP
TABLE
IF
EXISTS
composite_fk
;
DROP
TABLE
IF
EXISTS
order_item
;
DROP
TABLE
IF
EXISTS
item
;
DROP
TABLE
IF
EXISTS
order
;
DROP
TABLE
IF
EXISTS
category
;
DROP
TABLE
IF
EXISTS
customer
;
DROP
TABLE
IF
EXISTS
profile
;
DROP
TABLE
IF
EXISTS
type
;
DROP
TABLE
IF
EXISTS
null_values
;
CREATE
TABLE
profile
(
id
INTEGER
NOT
NULL
,
description
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_
customer
(
CREATE
TABLE
customer
(
id
INTEGER
NOT
NULL
,
email
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
),
...
...
@@ -29,20 +29,20 @@ CREATE TABLE tbl_customer (
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_
category
(
CREATE
TABLE
category
(
id
INTEGER
NOT
NULL
,
name
varchar
(
128
)
NOT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_
item
(
CREATE
TABLE
item
(
id
INTEGER
NOT
NULL
,
name
varchar
(
128
)
NOT
NULL
,
category_id
INTEGER
NOT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_
order
(
CREATE
TABLE
order
(
id
INTEGER
NOT
NULL
,
customer_id
INTEGER
NOT
NULL
,
created_at
INTEGER
NOT
NULL
,
...
...
@@ -50,7 +50,7 @@ CREATE TABLE tbl_order (
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_
order_item
(
CREATE
TABLE
order_item
(
order_id
INTEGER
NOT
NULL
,
item_id
INTEGER
NOT
NULL
,
quantity
INTEGER
NOT
NULL
,
...
...
@@ -58,15 +58,15 @@ CREATE TABLE tbl_order_item (
PRIMARY
KEY
(
order_id
,
item_id
)
);
CREATE
TABLE
`
tbl_
composite_fk`
(
CREATE
TABLE
`composite_fk`
(
`id`
int
(
11
)
NOT
NULL
,
`order_id`
int
(
11
)
NOT
NULL
,
`item_id`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`
tbl_
order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
CREATE
TABLE
tbl_
null_values
(
CREATE
TABLE
null_values
(
id
INTEGER
UNSIGNED
PRIMARY
KEY
NOT
NULL
,
var1
INTEGER
UNSIGNED
,
var2
INTEGER
,
...
...
@@ -74,7 +74,7 @@ CREATE TABLE tbl_null_values (
stringcol
VARCHAR
(
32
)
DEFAULT
NULL
);
CREATE
TABLE
t
bl_t
ype
(
CREATE
TABLE
type
(
int_col
INTEGER
NOT
NULL
,
int_col2
INTEGER
DEFAULT
'1'
,
char_col
char
(
100
)
NOT
NULL
,
...
...
@@ -89,58 +89,58 @@ CREATE TABLE tbl_type (
bool_col2
tinyint
(
1
)
DEFAULT
'1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
tbl_
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
profile
(
description
)
VALUES
(
'profile customer 3'
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
tbl_
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user1@example.com'
,
'user1'
,
'address1'
,
1
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
)
VALUES
(
'user2@example.com'
,
'user2'
,
'address2'
,
1
);
INSERT
INTO
customer
(
email
,
name
,
address
,
status
,
profile_id
)
VALUES
(
'user3@example.com'
,
'user3'
,
'address3'
,
2
,
2
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
tbl_
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Books'
);
INSERT
INTO
category
(
name
)
VALUES
(
'Movies'
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Agile Web Application Development with Yii1.1 and PHP5'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Yii 1.1 Application Development Cookbook'
,
1
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Ice Age'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
order
(
customer_id
,
created_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
tbl_
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
4
,
1
,
10
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
5
,
1
,
15
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
2
,
3
,
1
,
8
.
0
);
INSERT
INTO
order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
3
,
2
,
1
,
40
.
0
);
/**
* (SqLite-)Database Schema for validator tests
*/
DROP
TABLE
IF
EXISTS
tbl_
validator_main
;
DROP
TABLE
IF
EXISTS
tbl_
validator_ref
;
DROP
TABLE
IF
EXISTS
validator_main
;
DROP
TABLE
IF
EXISTS
validator_ref
;
CREATE
TABLE
tbl_
validator_main
(
CREATE
TABLE
validator_main
(
id
INTEGER
PRIMARY
KEY
,
field1
VARCHAR
(
255
)
);
CREATE
TABLE
tbl_
validator_ref
(
CREATE
TABLE
validator_ref
(
id
INTEGER
PRIMARY
KEY
,
a_field
VARCHAR
(
255
),
ref
INT
(
11
)
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
tbl_
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
1
,
'just a string1'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
2
,
'just a string2'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
3
,
'just a string3'
);
INSERT
INTO
validator_main
(
id
,
field1
)
VALUES
(
4
,
'just a string4'
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
1
,
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
2
,
'ref_to_2'
,
2
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
tests/unit/data/validators/models/ValidatorTestMainModel.php
View file @
ab799d8e
...
...
@@ -10,7 +10,7 @@ class ValidatorTestMainModel extends ActiveRecord
public
static
function
tableName
()
{
return
'
tbl_
validator_main'
;
return
'validator_main'
;
}
public
function
getReferences
()
...
...
tests/unit/data/validators/models/ValidatorTestRefModel.php
View file @
ab799d8e
...
...
@@ -12,7 +12,7 @@ class ValidatorTestRefModel extends ActiveRecord
public
static
function
tableName
()
{
return
'
tbl_
validator_ref'
;
return
'validator_ref'
;
}
public
function
getMain
()
...
...
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
View file @
ab799d8e
...
...
@@ -102,8 +102,8 @@ class ActiveRecordTest extends ElasticSearchTestCase
$customer
->
setAttributes
([
'email'
=>
'user3@example.com'
,
'name'
=>
'user3'
,
'address'
=>
'address3'
,
'status'
=>
2
],
false
);
$customer
->
save
(
false
);
// INSERT INTO
tbl_
category (name) VALUES ('Books');
// INSERT INTO
tbl_
category (name) VALUES ('Movies');
// INSERT INTO category (name) VALUES ('Books');
// INSERT INTO category (name) VALUES ('Movies');
$item
=
new
Item
();
$item
->
id
=
1
;
...
...
tests/unit/extensions/redis/ActiveRecordTest.php
View file @
ab799d8e
...
...
@@ -71,8 +71,8 @@ class ActiveRecordTest extends RedisTestCase
$customer
->
setAttributes
([
'email'
=>
'user3@example.com'
,
'name'
=>
'user3'
,
'address'
=>
'address3'
,
'status'
=>
2
,
'profile_id'
=>
2
],
false
);
$customer
->
save
(
false
);
// INSERT INTO
tbl_
category (name) VALUES ('Books');
// INSERT INTO
tbl_
category (name) VALUES ('Movies');
// INSERT INTO category (name) VALUES ('Books');
// INSERT INTO category (name) VALUES ('Movies');
$item
=
new
Item
();
$item
->
setAttributes
([
'name'
=>
'Agile Web Application Development with Yii1.1 and PHP5'
,
'category_id'
=>
1
],
false
);
...
...
tests/unit/extensions/sphinx/QueryTest.php
View file @
ab799d8e
...
...
@@ -28,8 +28,8 @@ class QueryTest extends SphinxTestCase
public
function
testFrom
()
{
$query
=
new
Query
;
$query
->
from
(
'
tbl_
user'
);
$this
->
assertEquals
([
'
tbl_
user'
],
$query
->
from
);
$query
->
from
(
'user'
);
$this
->
assertEquals
([
'user'
],
$query
->
from
);
}
public
function
testMatch
()
...
...
tests/unit/framework/caching/DbCacheTest.php
View file @
ab799d8e
...
...
@@ -23,7 +23,7 @@ class DbCacheTest extends CacheTestCase
parent
::
setUp
();
$this
->
getConnection
()
->
createCommand
(
"
CREATE TABLE IF NOT EXISTS
tbl_
cache (
CREATE TABLE IF NOT EXISTS cache (
id char(128) NOT NULL,
expire int(11) DEFAULT NULL,
data LONGBLOB,
...
...
tests/unit/framework/data/ActiveDataProviderTest.php
View file @
ab799d8e
...
...
@@ -126,7 +126,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
([
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'
tbl_
order'
)
->
orderBy
(
'id'
),
'query'
=>
$query
->
from
(
'order'
)
->
orderBy
(
'id'
),
]);
$orders
=
$provider
->
getModels
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
...
...
@@ -136,7 +136,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
([
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'
tbl_
order'
),
'query'
=>
$query
->
from
(
'order'
),
'pagination'
=>
[
'pageSize'
=>
2
,
]
...
...
@@ -150,7 +150,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
([
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'
tbl_
order'
)
->
orderBy
(
'id'
),
'query'
=>
$query
->
from
(
'order'
)
->
orderBy
(
'id'
),
]);
$this
->
assertEquals
(
3
,
count
(
$provider
->
getModels
()));
...
...
@@ -165,7 +165,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
([
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'
tbl_
order'
)
->
orderBy
(
'id'
),
'query'
=>
$query
->
from
(
'order'
)
->
orderBy
(
'id'
),
]);
$pagination
=
$provider
->
getPagination
();
$this
->
assertEquals
(
0
,
$pagination
->
getPageCount
());
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
ab799d8e
...
...
@@ -104,16 +104,16 @@ class ActiveRecordTest extends DatabaseTestCase
public
function
testFindBySql
()
{
// find one
$customer
=
Customer
::
findBySql
(
'SELECT * FROM
tbl_
customer ORDER BY id DESC'
)
->
one
();
$customer
=
Customer
::
findBySql
(
'SELECT * FROM customer ORDER BY id DESC'
)
->
one
();
$this
->
assertTrue
(
$customer
instanceof
Customer
);
$this
->
assertEquals
(
'user3'
,
$customer
->
name
);
// find all
$customers
=
Customer
::
findBySql
(
'SELECT * FROM
tbl_
customer'
)
->
all
();
$customers
=
Customer
::
findBySql
(
'SELECT * FROM customer'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$customers
));
// find with parameter binding
$customer
=
Customer
::
findBySql
(
'SELECT * FROM
tbl_
customer WHERE id=:id'
,
[
':id'
=>
2
])
->
one
();
$customer
=
Customer
::
findBySql
(
'SELECT * FROM customer WHERE id=:id'
,
[
':id'
=>
2
])
->
one
();
$this
->
assertTrue
(
$customer
instanceof
Customer
);
$this
->
assertEquals
(
'user2'
,
$customer
->
name
);
}
...
...
@@ -269,7 +269,7 @@ class ActiveRecordTest extends DatabaseTestCase
public
function
testJoinWith
()
{
// left join and eager loading
$orders
=
Order
::
find
()
->
joinWith
(
'customer'
)
->
orderBy
(
'
tbl_customer.id DESC, tbl_
order.id'
)
->
all
();
$orders
=
Order
::
find
()
->
joinWith
(
'customer'
)
->
orderBy
(
'
customer.id DESC,
order.id'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$orders
[
1
]
->
id
);
...
...
@@ -281,9 +281,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering and eager loading
$orders
=
Order
::
find
()
->
innerJoinWith
([
'customer'
=>
function
(
$query
)
{
$query
->
where
(
'
tbl_
customer.id=2'
);
$query
->
where
(
'customer.id=2'
);
},
])
->
orderBy
(
'
tbl_
order.id'
)
->
all
();
])
->
orderBy
(
'order.id'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$orders
[
1
]
->
id
);
...
...
@@ -293,9 +293,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering, eager loading, conditions on both primary and relation
$orders
=
Order
::
find
()
->
innerJoinWith
([
'customer'
=>
function
(
$query
)
{
$query
->
where
([
'
tbl_
customer.id'
=>
2
]);
$query
->
where
([
'customer.id'
=>
2
]);
},
])
->
where
([
'
tbl_order.id'
=>
[
1
,
2
]])
->
orderBy
(
'tbl_
order.id'
)
->
all
();
])
->
where
([
'
order.id'
=>
[
1
,
2
]])
->
orderBy
(
'
order.id'
)
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
...
...
@@ -303,9 +303,9 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading
$orders
=
Order
::
find
()
->
innerJoinWith
([
'customer'
=>
function
(
$query
)
{
$query
->
where
(
'
tbl_
customer.id=2'
);
$query
->
where
(
'customer.id=2'
);
},
],
false
)
->
orderBy
(
'
tbl_
order.id'
)
->
all
();
],
false
)
->
orderBy
(
'order.id'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$orders
[
1
]
->
id
);
...
...
@@ -315,15 +315,15 @@ class ActiveRecordTest extends DatabaseTestCase
// inner join filtering without eager loading, conditions on both primary and relation
$orders
=
Order
::
find
()
->
innerJoinWith
([
'customer'
=>
function
(
$query
)
{
$query
->
where
([
'
tbl_
customer.id'
=>
2
]);
$query
->
where
([
'customer.id'
=>
2
]);
},
],
false
)
->
where
([
'
tbl_order.id'
=>
[
1
,
2
]])
->
orderBy
(
'tbl_
order.id'
)
->
all
();
],
false
)
->
where
([
'
order.id'
=>
[
1
,
2
]])
->
orderBy
(
'
order.id'
)
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertFalse
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
// join with via-relation
$orders
=
Order
::
find
()
->
innerJoinWith
(
'books'
)
->
orderBy
(
'
tbl_
order.id'
)
->
all
();
$orders
=
Order
::
find
()
->
innerJoinWith
(
'books'
)
->
orderBy
(
'order.id'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertEquals
(
1
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$orders
[
1
]
->
id
);
...
...
@@ -335,12 +335,12 @@ class ActiveRecordTest extends DatabaseTestCase
// join with sub-relation
$orders
=
Order
::
find
()
->
innerJoinWith
([
'items'
=>
function
(
$q
)
{
$q
->
orderBy
(
'
tbl_
item.id'
);
$q
->
orderBy
(
'item.id'
);
},
'items.category'
=>
function
(
$q
)
{
$q
->
where
(
'
tbl_
category.id = 2'
);
$q
->
where
(
'category.id = 2'
);
},
])
->
orderBy
(
'
tbl_
order.id'
)
->
all
();
])
->
orderBy
(
'order.id'
)
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'items'
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
...
...
@@ -351,9 +351,9 @@ class ActiveRecordTest extends DatabaseTestCase
// join with table alias
$orders
=
Order
::
find
()
->
joinWith
([
'customer'
=>
function
(
$q
)
{
$q
->
from
(
'
tbl_
customer c'
);
$q
->
from
(
'customer c'
);
}
])
->
orderBy
(
'c.id DESC,
tbl_
order.id'
)
->
all
();
])
->
orderBy
(
'c.id DESC, order.id'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$orders
[
1
]
->
id
);
...
...
@@ -363,7 +363,7 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertTrue
(
$orders
[
2
]
->
isRelationPopulated
(
'customer'
));
// join with ON condition
$orders
=
Order
::
find
()
->
joinWith
(
'books2'
)
->
orderBy
(
'
tbl_
order.id'
)
->
all
();
$orders
=
Order
::
find
()
->
joinWith
(
'books2'
)
->
orderBy
(
'order.id'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
1
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$orders
[
1
]
->
id
);
...
...
@@ -411,22 +411,22 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
1
,
$customer
->
id
);
$order
=
Order
::
find
()
->
joinWith
([
'items'
=>
function
(
$q
)
{
$q
->
from
([
'items'
=>
'
tbl_
item'
])
$q
->
from
([
'items'
=>
'item'
])
->
orderBy
(
'items.id'
);
},
])
->
orderBy
(
'
tbl_
order.id'
)
->
one
();
])
->
orderBy
(
'order.id'
)
->
one
();
}
public
function
testJoinWithAndScope
()
{
// hasOne inner join
$customers
=
Customer
::
find
()
->
active
()
->
innerJoinWith
(
'profile'
)
->
orderBy
(
'
tbl_
customer.id'
)
->
all
();
$customers
=
Customer
::
find
()
->
active
()
->
innerJoinWith
(
'profile'
)
->
orderBy
(
'customer.id'
)
->
all
();
$this
->
assertEquals
(
1
,
count
(
$customers
));
$this
->
assertEquals
(
1
,
$customers
[
0
]
->
id
);
$this
->
assertTrue
(
$customers
[
0
]
->
isRelationPopulated
(
'profile'
));
// hasOne outer join
$customers
=
Customer
::
find
()
->
active
()
->
joinWith
(
'profile'
)
->
orderBy
(
'
tbl_
customer.id'
)
->
all
();
$customers
=
Customer
::
find
()
->
active
()
->
joinWith
(
'profile'
)
->
orderBy
(
'customer.id'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$customers
));
$this
->
assertEquals
(
1
,
$customers
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$customers
[
1
]
->
id
);
...
...
@@ -438,9 +438,9 @@ class ActiveRecordTest extends DatabaseTestCase
// hasMany
$customers
=
Customer
::
find
()
->
active
()
->
joinWith
([
'orders'
=>
function
(
$q
)
{
$q
->
orderBy
(
'
tbl_
order.id'
);
$q
->
orderBy
(
'order.id'
);
}
])
->
orderBy
(
'
tbl_customer.id DESC, tbl_
order.id'
)
->
all
();
])
->
orderBy
(
'
customer.id DESC,
order.id'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$customers
));
$this
->
assertEquals
(
2
,
$customers
[
0
]
->
id
);
$this
->
assertEquals
(
1
,
$customers
[
1
]
->
id
);
...
...
tests/unit/framework/db/BatchQueryResultTest.php
View file @
ab799d8e
...
...
@@ -31,7 +31,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// initialize property test
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
orderBy
(
'id'
);
$query
->
from
(
'customer'
)
->
orderBy
(
'id'
);
$result
=
$query
->
batch
(
2
,
$db
);
$this
->
assertTrue
(
$result
instanceof
BatchQueryResult
);
$this
->
assertEquals
(
2
,
$result
->
batchSize
);
...
...
@@ -39,7 +39,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// normal query
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
orderBy
(
'id'
);
$query
->
from
(
'customer'
)
->
orderBy
(
'id'
);
$allRows
=
[];
$batch
=
$query
->
batch
(
2
,
$db
);
foreach
(
$batch
as
$rows
)
{
...
...
@@ -60,7 +60,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// empty query
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
where
([
'id'
=>
100
]);
$query
->
from
(
'customer'
)
->
where
([
'id'
=>
100
]);
$allRows
=
[];
$batch
=
$query
->
batch
(
2
,
$db
);
foreach
(
$batch
as
$rows
)
{
...
...
@@ -70,7 +70,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// query with index
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
indexBy
(
'name'
);
$query
->
from
(
'customer'
)
->
indexBy
(
'name'
);
$allRows
=
[];
foreach
(
$query
->
batch
(
2
,
$db
)
as
$rows
)
{
$allRows
=
array_merge
(
$allRows
,
$rows
);
...
...
@@ -82,7 +82,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
orderBy
(
'id'
);
$query
->
from
(
'customer'
)
->
orderBy
(
'id'
);
$allRows
=
[];
foreach
(
$query
->
each
(
100
,
$db
)
as
$rows
)
{
$allRows
[]
=
$rows
;
...
...
@@ -94,7 +94,7 @@ class BatchQueryResultTest extends DatabaseTestCase
// each with key
$query
=
new
Query
();
$query
->
from
(
'
tbl_
customer'
)
->
orderBy
(
'id'
)
->
indexBy
(
'name'
);
$query
->
from
(
'customer'
)
->
orderBy
(
'id'
)
->
indexBy
(
'name'
);
$allRows
=
[];
foreach
(
$query
->
each
(
100
,
$db
)
as
$key
=>
$row
)
{
$allRows
[
$key
]
=
$row
;
...
...
tests/unit/framework/db/CommandTest.php
View file @
ab799d8e
...
...
@@ -19,7 +19,7 @@ class CommandTest extends DatabaseTestCase
$this
->
assertEquals
(
null
,
$command
->
sql
);
// string
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
$sql
,
$command
->
sql
);
}
...
...
@@ -28,11 +28,11 @@ class CommandTest extends DatabaseTestCase
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
$sql
,
$command
->
sql
);
$sql2
=
'SELECT * FROM
tbl_
order'
;
$sql2
=
'SELECT * FROM order'
;
$command
->
sql
=
$sql2
;
$this
->
assertEquals
(
$sql2
,
$command
->
sql
);
}
...
...
@@ -41,16 +41,16 @@ class CommandTest extends DatabaseTestCase
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{
tbl_
customer}} t'
;
$sql
=
'SELECT [[id]], [[t.name]] FROM {{customer}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
"SELECT `id`, `t`.`name` FROM `
tbl_
customer` t"
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT `id`, `t`.`name` FROM `customer` t"
,
$command
->
sql
);
}
public
function
testPrepareCancel
()
{
$db
=
$this
->
getConnection
(
false
);
$command
=
$db
->
createCommand
(
'SELECT * FROM
tbl_
customer'
);
$command
=
$db
->
createCommand
(
'SELECT * FROM customer'
);
$this
->
assertEquals
(
null
,
$command
->
pdoStatement
);
$command
->
prepare
();
$this
->
assertNotEquals
(
null
,
$command
->
pdoStatement
);
...
...
@@ -62,11 +62,11 @@ class CommandTest extends DatabaseTestCase
{
$db
=
$this
->
getConnection
();
$sql
=
'INSERT INTO
tbl_
customer(email, name , address) VALUES (\'user4@example.com\', \'user4\', \'address4\')'
;
$sql
=
'INSERT INTO customer(email, name , address) VALUES (\'user4@example.com\', \'user4\', \'address4\')'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT COUNT(*) FROM
tbl_
customer WHERE name =\'user4\''
;
$sql
=
'SELECT COUNT(*) FROM customer WHERE name =\'user4\''
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
...
...
@@ -80,55 +80,55 @@ class CommandTest extends DatabaseTestCase
$db
=
$this
->
getConnection
();
// query
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$reader
=
$db
->
createCommand
(
$sql
)
->
query
();
$this
->
assertTrue
(
$reader
instanceof
DataReader
);
// queryAll
$rows
=
$db
->
createCommand
(
'SELECT * FROM
tbl_
customer'
)
->
queryAll
();
$rows
=
$db
->
createCommand
(
'SELECT * FROM customer'
)
->
queryAll
();
$this
->
assertEquals
(
3
,
count
(
$rows
));
$row
=
$rows
[
2
];
$this
->
assertEquals
(
3
,
$row
[
'id'
]);
$this
->
assertEquals
(
'user3'
,
$row
[
'name'
]);
$rows
=
$db
->
createCommand
(
'SELECT * FROM
tbl_
customer WHERE id=10'
)
->
queryAll
();
$rows
=
$db
->
createCommand
(
'SELECT * FROM customer WHERE id=10'
)
->
queryAll
();
$this
->
assertEquals
([],
$rows
);
// queryOne
$sql
=
'SELECT * FROM
tbl_
customer ORDER BY id'
;
$sql
=
'SELECT * FROM customer ORDER BY id'
;
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
$this
->
assertEquals
(
1
,
$row
[
'id'
]);
$this
->
assertEquals
(
'user1'
,
$row
[
'name'
]);
$sql
=
'SELECT * FROM
tbl_
customer ORDER BY id'
;
$sql
=
'SELECT * FROM customer ORDER BY id'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
prepare
();
$row
=
$command
->
queryOne
();
$this
->
assertEquals
(
1
,
$row
[
'id'
]);
$this
->
assertEquals
(
'user1'
,
$row
[
'name'
]);
$sql
=
'SELECT * FROM
tbl_
customer WHERE id=10'
;
$sql
=
'SELECT * FROM customer WHERE id=10'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertFalse
(
$command
->
queryOne
());
// queryColumn
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$column
=
$db
->
createCommand
(
$sql
)
->
queryColumn
();
$this
->
assertEquals
(
range
(
1
,
3
),
$column
);
$command
=
$db
->
createCommand
(
'SELECT id FROM
tbl_
customer WHERE id=10'
);
$command
=
$db
->
createCommand
(
'SELECT id FROM customer WHERE id=10'
);
$this
->
assertEquals
([],
$command
->
queryColumn
());
// queryScalar
$sql
=
'SELECT * FROM
tbl_
customer ORDER BY id'
;
$sql
=
'SELECT * FROM customer ORDER BY id'
;
$this
->
assertEquals
(
$db
->
createCommand
(
$sql
)
->
queryScalar
(),
1
);
$sql
=
'SELECT id FROM
tbl_
customer ORDER BY id'
;
$sql
=
'SELECT id FROM customer ORDER BY id'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
prepare
();
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'SELECT id FROM
tbl_
customer WHERE id=10'
);
$command
=
$db
->
createCommand
(
'SELECT id FROM customer WHERE id=10'
);
$this
->
assertFalse
(
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'bad SQL'
);
...
...
@@ -141,7 +141,7 @@ class CommandTest extends DatabaseTestCase
$db
=
$this
->
getConnection
();
// bindParam
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, :name, :address)'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)'
;
$command
=
$db
->
createCommand
(
$sql
);
$email
=
'user4@example.com'
;
$name
=
'user4'
;
...
...
@@ -151,12 +151,12 @@ class CommandTest extends DatabaseTestCase
$command
->
bindParam
(
':address'
,
$address
);
$command
->
execute
();
$sql
=
'SELECT name FROM
tbl_
customer WHERE email=:email'
;
$sql
=
'SELECT name FROM customer WHERE email=:email'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindParam
(
':email'
,
$email
);
$this
->
assertEquals
(
$name
,
$command
->
queryScalar
());
$sql
=
'INSERT INTO t
bl_t
ype (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)'
;
$sql
=
'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)'
;
$command
=
$db
->
createCommand
(
$sql
);
$intCol
=
123
;
$charCol
=
'abc'
;
...
...
@@ -172,7 +172,7 @@ class CommandTest extends DatabaseTestCase
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT * FROM t
bl_t
ype'
;
$sql
=
'SELECT * FROM type'
;
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
$this
->
assertEquals
(
$intCol
,
$row
[
'int_col'
]);
$this
->
assertEquals
(
$charCol
,
$row
[
'char_col'
]);
...
...
@@ -181,12 +181,12 @@ class CommandTest extends DatabaseTestCase
$this
->
assertEquals
(
$numericCol
,
$row
[
'numeric_col'
]);
// bindValue
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':email'
,
'user5@example.com'
);
$command
->
execute
();
$sql
=
'SELECT email FROM
tbl_
customer WHERE name=:name'
;
$sql
=
'SELECT email FROM customer WHERE name=:name'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':name'
,
'user5'
);
$this
->
assertEquals
(
'user5@example.com'
,
$command
->
queryScalar
());
...
...
@@ -197,20 +197,20 @@ class CommandTest extends DatabaseTestCase
$db
=
$this
->
getConnection
();
// default: FETCH_ASSOC
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$command
=
$db
->
createCommand
(
$sql
);
$result
=
$command
->
queryOne
();
$this
->
assertTrue
(
is_array
(
$result
)
&&
isset
(
$result
[
'id'
]));
// FETCH_OBJ, customized via fetchMode property
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
fetchMode
=
\PDO
::
FETCH_OBJ
;
$result
=
$command
->
queryOne
();
$this
->
assertTrue
(
is_object
(
$result
));
// FETCH_NUM, customized in query method
$sql
=
'SELECT * FROM
tbl_
customer'
;
$sql
=
'SELECT * FROM customer'
;
$command
=
$db
->
createCommand
(
$sql
);
$result
=
$command
->
queryOne
([],
\PDO
::
FETCH_NUM
);
$this
->
assertTrue
(
is_array
(
$result
)
&&
isset
(
$result
[
0
]));
...
...
@@ -219,7 +219,7 @@ class CommandTest extends DatabaseTestCase
public
function
testBatchInsert
()
{
$command
=
$this
->
getConnection
()
->
createCommand
();
$command
->
batchInsert
(
'
tbl_
customer'
,
$command
->
batchInsert
(
'customer'
,
[
'email'
,
'name'
,
'address'
],
[
[
't1@example.com'
,
't1'
,
't1 address'
],
[
't2@example.com'
,
null
,
false
],
...
...
tests/unit/framework/db/QueryBuilderTest.php
View file @
ab799d8e
...
...
@@ -115,7 +115,7 @@ class QueryBuilderTest extends DatabaseTestCase
public
function
testAddDropPrimaryKey
()
{
$tableName
=
'
tbl_
constraints'
;
$tableName
=
'constraints'
;
$pkeyName
=
$tableName
.
"_pkey"
;
// ADD
...
...
tests/unit/framework/db/QueryTest.php
View file @
ab799d8e
...
...
@@ -29,8 +29,8 @@ class QueryTest extends DatabaseTestCase
public
function
testFrom
()
{
$query
=
new
Query
;
$query
->
from
(
'
tbl_
user'
);
$this
->
assertEquals
([
'
tbl_
user'
],
$query
->
from
);
$query
->
from
(
'user'
);
$this
->
assertEquals
([
'user'
],
$query
->
from
);
}
public
function
testWhere
()
...
...
@@ -117,10 +117,10 @@ class QueryTest extends DatabaseTestCase
{
$db
=
$this
->
getConnection
();
$result
=
(
new
Query
)
->
from
(
'
tbl_
customer'
)
->
where
([
'status'
=>
2
])
->
one
(
$db
);
$result
=
(
new
Query
)
->
from
(
'customer'
)
->
where
([
'status'
=>
2
])
->
one
(
$db
);
$this
->
assertEquals
(
'user3'
,
$result
[
'name'
]);
$result
=
(
new
Query
)
->
from
(
'
tbl_
customer'
)
->
where
([
'status'
=>
3
])
->
one
(
$db
);
$result
=
(
new
Query
)
->
from
(
'customer'
)
->
where
([
'status'
=>
3
])
->
one
(
$db
);
$this
->
assertFalse
(
$result
);
}
}
tests/unit/framework/db/SchemaTest.php
View file @
ab799d8e
...
...
@@ -17,12 +17,12 @@ class SchemaTest extends DatabaseTestCase
$schema
=
$this
->
getConnection
()
->
schema
;
$tables
=
$schema
->
getTableNames
();
$this
->
assertTrue
(
in_array
(
'
tbl_
customer'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'
tbl_
category'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'
tbl_
item'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'
tbl_
order'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'
tbl_
order_item'
,
$tables
));
$this
->
assertTrue
(
in_array
(
't
bl_t
ype'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'customer'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'category'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'item'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'order'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'order_item'
,
$tables
));
$this
->
assertTrue
(
in_array
(
'type'
,
$tables
));
}
public
function
testGetTableSchemas
()
...
...
@@ -49,8 +49,8 @@ class SchemaTest extends DatabaseTestCase
$schema
->
db
->
enableSchemaCache
=
true
;
$schema
->
db
->
schemaCache
=
new
FileCache
();
$noCacheTable
=
$schema
->
getTableSchema
(
't
bl_t
ype'
,
true
);
$cachedTable
=
$schema
->
getTableSchema
(
't
bl_t
ype'
,
true
);
$noCacheTable
=
$schema
->
getTableSchema
(
'type'
,
true
);
$cachedTable
=
$schema
->
getTableSchema
(
'type'
,
true
);
$this
->
assertEquals
(
$noCacheTable
,
$cachedTable
);
}
...
...
@@ -59,11 +59,11 @@ class SchemaTest extends DatabaseTestCase
/** @var Schema $schema */
$schema
=
$this
->
getConnection
()
->
schema
;
$table
=
$schema
->
getTableSchema
(
'
tbl_
composite_fk'
);
$table
=
$schema
->
getTableSchema
(
'composite_fk'
);
$this
->
assertCount
(
1
,
$table
->
foreignKeys
);
$this
->
assertTrue
(
isset
(
$table
->
foreignKeys
[
0
]));
$this
->
assertEquals
(
'
tbl_
order_item'
,
$table
->
foreignKeys
[
0
][
0
]);
$this
->
assertEquals
(
'order_item'
,
$table
->
foreignKeys
[
0
][
0
]);
$this
->
assertEquals
(
'order_id'
,
$table
->
foreignKeys
[
0
][
'order_id'
]);
$this
->
assertEquals
(
'item_id'
,
$table
->
foreignKeys
[
0
][
'item_id'
]);
}
...
...
tests/unit/framework/db/cubrid/CubridCommandTest.php
View file @
ab799d8e
...
...
@@ -16,7 +16,7 @@ class CubridCommandTest extends CommandTest
$db
=
$this
->
getConnection
();
// bindParam
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, :name, :address)'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)'
;
$command
=
$db
->
createCommand
(
$sql
);
$email
=
'user4@example.com'
;
$name
=
'user4'
;
...
...
@@ -26,12 +26,12 @@ class CubridCommandTest extends CommandTest
$command
->
bindParam
(
':address'
,
$address
);
$command
->
execute
();
$sql
=
'SELECT name FROM
tbl_
customer WHERE email=:email'
;
$sql
=
'SELECT name FROM customer WHERE email=:email'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindParam
(
':email'
,
$email
);
$this
->
assertEquals
(
$name
,
$command
->
queryScalar
());
$sql
=
"INSERT INTO t
bl_t
ype (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col)"
;
$sql
=
"INSERT INTO type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col)"
;
$command
=
$db
->
createCommand
(
$sql
);
$intCol
=
123
;
$charCol
=
'abc'
;
...
...
@@ -49,7 +49,7 @@ class CubridCommandTest extends CommandTest
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT * FROM t
bl_t
ype'
;
$sql
=
'SELECT * FROM type'
;
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
$this
->
assertEquals
(
$intCol
,
$row
[
'int_col'
]);
$this
->
assertEquals
(
$enumCol
,
$row
[
'enum_col'
]);
...
...
@@ -60,12 +60,12 @@ class CubridCommandTest extends CommandTest
$this
->
assertEquals
(
$boolCol
,
$row
[
'bool_col'
]);
// bindValue
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':email'
,
'user5@example.com'
);
$command
->
execute
();
$sql
=
'SELECT email FROM
tbl_
customer WHERE name=:name'
;
$sql
=
'SELECT email FROM customer WHERE name=:name'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':name'
,
'user5'
);
$this
->
assertEquals
(
'user5@example.com'
,
$command
->
queryScalar
());
...
...
@@ -75,8 +75,8 @@ class CubridCommandTest extends CommandTest
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{
tbl_
customer}} t'
;
$sql
=
'SELECT [[id]], [[t.name]] FROM {{customer}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
'SELECT "id", "t"."name" FROM "
tbl_
customer" t'
,
$command
->
sql
);
$this
->
assertEquals
(
'SELECT "id", "t"."name" FROM "customer" t'
,
$command
->
sql
);
}
}
tests/unit/framework/db/mssql/MssqlCommandTest.php
View file @
ab799d8e
...
...
@@ -16,9 +16,9 @@ class MssqlCommandTest extends CommandTest
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{
tbl_
customer}} t'
;
$sql
=
'SELECT [[id]], [[t.name]] FROM {{customer}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
"SELECT [id], [t].[name] FROM [
tbl_
customer] t"
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT [id], [t].[name] FROM [customer] t"
,
$command
->
sql
);
}
public
function
testPrepareCancel
()
...
...
@@ -31,7 +31,7 @@ class MssqlCommandTest extends CommandTest
$db
=
$this
->
getConnection
();
// bindParam
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, :name, :address)'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)'
;
$command
=
$db
->
createCommand
(
$sql
);
$email
=
'user4@example.com'
;
$name
=
'user4'
;
...
...
@@ -41,12 +41,12 @@ class MssqlCommandTest extends CommandTest
$command
->
bindParam
(
':address'
,
$address
);
$command
->
execute
();
$sql
=
'SELECT name FROM
tbl_
customer WHERE email=:email'
;
$sql
=
'SELECT name FROM customer WHERE email=:email'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindParam
(
':email'
,
$email
);
$this
->
assertEquals
(
$name
,
$command
->
queryScalar
());
$sql
=
'INSERT INTO t
bl_t
ype (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)'
;
$sql
=
'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)'
;
$command
=
$db
->
createCommand
(
$sql
);
$intCol
=
123
;
$charCol
=
'abc'
;
...
...
@@ -62,7 +62,7 @@ class MssqlCommandTest extends CommandTest
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM t
bl_t
ype'
;
$sql
=
'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM type'
;
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
$this
->
assertEquals
(
$intCol
,
$row
[
'int_col'
]);
$this
->
assertEquals
(
$charCol
,
trim
(
$row
[
'char_col'
]));
...
...
@@ -71,12 +71,12 @@ class MssqlCommandTest extends CommandTest
$this
->
assertEquals
(
$numericCol
,
$row
[
'numeric_col'
]);
// bindValue
$sql
=
'INSERT INTO
tbl_
customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':email'
,
'user5@example.com'
);
$command
->
execute
();
$sql
=
'SELECT email FROM
tbl_
customer WHERE name=:name'
;
$sql
=
'SELECT email FROM customer WHERE name=:name'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
bindValue
(
':name'
,
'user5'
);
$this
->
assertEquals
(
'user5@example.com'
,
$command
->
queryScalar
());
...
...
tests/unit/framework/db/sqlite/SqliteCommandTest.php
View file @
ab799d8e
...
...
@@ -15,8 +15,8 @@ class SqliteCommandTest extends CommandTest
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{
tbl_
customer}} t'
;
$sql
=
'SELECT [[id]], [[t.name]] FROM {{customer}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
"SELECT `id`, `t`.`name` FROM `
tbl_
customer` t"
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT `id`, `t`.`name` FROM `customer` t"
,
$command
->
sql
);
}
}
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php
View file @
ab799d8e
...
...
@@ -84,7 +84,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public
function
testBatchInsert
()
{
$sql
=
$this
->
getQueryBuilder
()
->
batchInsert
(
'{{
tbl_
customer}} t'
,
[
't.id'
,
't.name'
],
[[
1
,
'a'
],
[
2
,
'b'
]]);
$this
->
assertEquals
(
"INSERT INTO
{
{
tbl_
customer}
}
t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'"
,
$sql
);
$sql
=
$this
->
getQueryBuilder
()
->
batchInsert
(
'{{customer}} t'
,
[
't.id'
,
't.name'
],
[[
1
,
'a'
],
[
2
,
'b'
]]);
$this
->
assertEquals
(
"INSERT INTO
{
{customer}
}
t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'"
,
$sql
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment