Qiang Xue
13 years ago
12 changed files with 817 additions and 1514 deletions
@ -0,0 +1,21 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* ActiveQueryBuilder class file. |
||||||
|
* |
||||||
|
* @link http://www.yiiframework.com/ |
||||||
|
* @copyright Copyright © 2008-2012 Yii Software LLC |
||||||
|
* @license http://www.yiiframework.com/license/ |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace yii\db\ar; |
||||||
|
|
||||||
|
/** |
||||||
|
* ActiveQueryBuilder is ... |
||||||
|
* |
||||||
|
* @author Qiang Xue <qiang.xue@gmail.com> |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
class ActiveQueryBuilder extends \yii\base\Object |
||||||
|
{ |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -1,160 +1,96 @@ |
|||||||
/** |
/** |
||||||
* This is the database schema for testing MySQL support of yii Active Record. |
* This is the database schema for testing MySQL support of Yii DAO and Active Record. |
||||||
* To test this feature, you need to create a database named 'yii' on 'localhost' |
* The following database setup is required to perform then relevant tests: |
||||||
* and create an account 'test/test' which owns this test database. |
* Database name: yiitest |
||||||
|
* username: test |
||||||
|
* password: test |
||||||
|
* charset: utf8 |
||||||
*/ |
*/ |
||||||
|
|
||||||
DROP TABLE IF EXISTS yii_type CASCADE; |
DROP TABLE IF EXISTS tbl_order_item CASCADE; |
||||||
DROP TABLE IF EXISTS yii_item CASCADE; |
DROP TABLE IF EXISTS tbl_item CASCADE; |
||||||
DROP TABLE IF EXISTS yii_order CASCADE; |
DROP TABLE IF EXISTS tbl_order CASCADE; |
||||||
DROP TABLE IF EXISTS yii_post_category CASCADE; |
DROP TABLE IF EXISTS tbl_category CASCADE; |
||||||
DROP TABLE IF EXISTS yii_category CASCADE; |
DROP TABLE IF EXISTS tbl_customer CASCADE; |
||||||
DROP TABLE IF EXISTS yii_comment CASCADE; |
DROP TABLE IF EXISTS tbl_type CASCADE; |
||||||
DROP TABLE IF EXISTS yii_post CASCADE; |
|
||||||
DROP TABLE IF EXISTS yii_profile CASCADE; |
CREATE TABLE `tbl_customer` ( |
||||||
DROP TABLE IF EXISTS yii_user CASCADE; |
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||||
|
`email` varchar(128) NOT NULL, |
||||||
CREATE TABLE yii_user |
`name` varchar(128) NOT NULL, |
||||||
( |
`address` text, |
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
PRIMARY KEY (`id`) |
||||||
username VARCHAR(128) NOT NULL, |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
password VARCHAR(128) NOT NULL, |
|
||||||
email VARCHAR(128) NOT NULL |
CREATE TABLE `tbl_category` ( |
||||||
) TYPE=INNODB; |
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||||
|
`name` varchar(128) NOT NULL, |
||||||
INSERT INTO yii_user (username, password, email) VALUES ('user1','pass1','email1'); |
PRIMARY KEY (`id`) |
||||||
INSERT INTO yii_user (username, password, email) VALUES ('user2','pass2','email2'); |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
INSERT INTO yii_user (username, password, email) VALUES ('user3','pass3','email3'); |
|
||||||
|
CREATE TABLE `tbl_item` ( |
||||||
CREATE TABLE yii_profile |
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||||
( |
`name` varchar(128) NOT NULL, |
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
`category_id` int(11) NOT NULL, |
||||||
first_name VARCHAR(128) NOT NULL, |
PRIMARY KEY (`id`), |
||||||
last_name VARCHAR(128) NOT NULL, |
KEY `FK_item_category_id` (`category_id`), |
||||||
user_id INTEGER NOT NULL, |
CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `tbl_category` (`id`) ON DELETE CASCADE |
||||||
CONSTRAINT FK_profile_user FOREIGN KEY (user_id) |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
REFERENCES yii_user (id) ON DELETE CASCADE ON UPDATE RESTRICT |
|
||||||
) TYPE=INNODB; |
CREATE TABLE `tbl_order` ( |
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||||
INSERT INTO yii_profile (first_name, last_name, user_id) VALUES ('first 1','last 1',1); |
`customer_id` int(11) NOT NULL, |
||||||
INSERT INTO yii_profile (first_name, last_name, user_id) VALUES ('first 2','last 2',2); |
`create_time` int(11) NOT NULL, |
||||||
|
`total` decimal(10,0) NOT NULL, |
||||||
CREATE TABLE yii_post |
PRIMARY KEY (`id`) |
||||||
( |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|
||||||
title VARCHAR(128) NOT NULL, |
CREATE TABLE `tbl_order_item` ( |
||||||
create_time INTEGER NOT NULL, |
`order_id` int(11) NOT NULL, |
||||||
author_id INTEGER NOT NULL, |
`item_id` int(11) NOT NULL, |
||||||
content TEXT, |
`quantity` int(11) NOT NULL, |
||||||
CONSTRAINT FK_post_author FOREIGN KEY (author_id) |
`subtotal` decimal(10,0) NOT NULL, |
||||||
REFERENCES yii_user (id) ON DELETE CASCADE ON UPDATE RESTRICT |
PRIMARY KEY (`order_id`,`item_id`), |
||||||
) TYPE=INNODB; |
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, |
||||||
INSERT INTO yii_post (title, create_time, author_id, content) VALUES ('post 1','1324854194',1,'content 1'); |
CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `tbl_item` (`id`) ON DELETE CASCADE |
||||||
INSERT INTO yii_post (title, create_time, author_id, content) VALUES ('post 2','1324855194',2,'content 2'); |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
INSERT INTO yii_post (title, create_time, author_id, content) VALUES ('post 3','1324856194',2,'content 3'); |
|
||||||
INSERT INTO yii_post (title, create_time, author_id, content) VALUES ('post 4','1324857194',2,'content 4'); |
CREATE TABLE `tbl_type` ( |
||||||
INSERT INTO yii_post (title, create_time, author_id, content) VALUES ('post 5','1324858194',3,'content 5'); |
`int_col` int(11) NOT NULL, |
||||||
|
`int_col2` int(11) DEFAULT '1', |
||||||
CREATE TABLE yii_comment |
`char_col` char(100) NOT NULL, |
||||||
( |
`char_col2` varchar(100) DEFAULT 'something', |
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
`char_col3` text, |
||||||
content TEXT NOT NULL, |
`float_col` double(4,3) NOT NULL, |
||||||
post_id INTEGER NOT NULL, |
`float_col2` double DEFAULT '1.23', |
||||||
author_id INTEGER NOT NULL, |
`blob_col` blob, |
||||||
CONSTRAINT FK_post_comment FOREIGN KEY (post_id) |
`numeric_col` decimal(5,2) DEFAULT '33.22', |
||||||
REFERENCES yii_post (id) ON DELETE CASCADE ON UPDATE RESTRICT, |
`time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00', |
||||||
CONSTRAINT FK_user_comment FOREIGN KEY (author_id) |
`bool_col` tinyint(1) NOT NULL, |
||||||
REFERENCES yii_user (id) ON DELETE CASCADE ON UPDATE RESTRICT |
`bool_col2` tinyint(1) DEFAULT '1' |
||||||
) TYPE=INNODB; |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
||||||
|
|
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 1',1, 2); |
INSERT INTO tbl_customer (email, name, address) VALUES ('user1@example.com', 'user1', 'address1'); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 2',1, 2); |
INSERT INTO tbl_customer (email, name, address) VALUES ('user2@example.com', 'user2', 'address2'); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 3',1, 2); |
INSERT INTO tbl_customer (email, name, address) VALUES ('user3@example.com', 'user3', 'address3'); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 4',2, 2); |
|
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 5',2, 2); |
INSERT INTO tbl_category (name) VALUES ('Books'); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 6',3, 2); |
INSERT INTO tbl_category (name) VALUES ('Movies'); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 7',3, 2); |
|
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 8',3, 2); |
INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 9',3, 2); |
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1); |
||||||
INSERT INTO yii_comment (content, post_id, author_id) VALUES ('comment 10',5, 3); |
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2); |
||||||
|
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2); |
||||||
CREATE TABLE yii_category |
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2); |
||||||
( |
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
INSERT INTO tbl_order (customer_id, create_time, total) VALUES (1, 1325282384, 110.0); |
||||||
name VARCHAR(128) NOT NULL, |
INSERT INTO tbl_order (customer_id, create_time, total) VALUES (2, 1325334482, 33.0); |
||||||
parent_id INTEGER, |
INSERT INTO tbl_order (customer_id, create_time, total) VALUES (3, 1325502201, 40.0); |
||||||
CONSTRAINT FK_category_category FOREIGN KEY (parent_id) |
|
||||||
REFERENCES yii_category (id) ON DELETE CASCADE ON UPDATE RESTRICT |
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0); |
||||||
) TYPE=INNODB; |
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 yii_category (name, parent_id) VALUES ('cat 1',NULL); |
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0); |
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 2',NULL); |
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0); |
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 3',NULL); |
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); |
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 4',1); |
|
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 5',1); |
|
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 6',5); |
|
||||||
INSERT INTO yii_category (name, parent_id) VALUES ('cat 7',5); |
|
||||||
|
|
||||||
CREATE TABLE yii_post_category |
|
||||||
( |
|
||||||
category_id INTEGER NOT NULL, |
|
||||||
post_id INTEGER NOT NULL, |
|
||||||
PRIMARY KEY (category_id, post_id), |
|
||||||
CONSTRAINT FK_yii_post_category_post FOREIGN KEY (post_id) |
|
||||||
REFERENCES yii_post (id) ON DELETE CASCADE ON UPDATE RESTRICT, |
|
||||||
CONSTRAINT FK_yii_post_category_category FOREIGN KEY (category_id) |
|
||||||
REFERENCES yii_category (id) ON DELETE CASCADE ON UPDATE RESTRICT |
|
||||||
) TYPE=INNODB; |
|
||||||
|
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (1,1); |
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (2,1); |
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (3,1); |
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (4,2); |
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (1,2); |
|
||||||
INSERT INTO yii_post_category (category_id, post_id) VALUES (1,3); |
|
||||||
|
|
||||||
CREATE TABLE yii_order |
|
||||||
( |
|
||||||
key1 INTEGER NOT NULL, |
|
||||||
key2 INTEGER NOT NULL, |
|
||||||
name VARCHAR(128), |
|
||||||
PRIMARY KEY (key1, key2) |
|
||||||
) TYPE=INNODB; |
|
||||||
|
|
||||||
INSERT INTO yii_order (key1,key2,name) VALUES (1,2,'order 12'); |
|
||||||
INSERT INTO yii_order (key1,key2,name) VALUES (1,3,'order 13'); |
|
||||||
INSERT INTO yii_order (key1,key2,name) VALUES (2,1,'order 21'); |
|
||||||
INSERT INTO yii_order (key1,key2,name) VALUES (2,2,'order 22'); |
|
||||||
|
|
||||||
CREATE TABLE yii_item |
|
||||||
( |
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
|
||||||
name VARCHAR(128), |
|
||||||
col1 INTEGER NOT NULL, |
|
||||||
col2 INTEGER NOT NULL, |
|
||||||
CONSTRAINT FK_order_item FOREIGN KEY (col1,col2) |
|
||||||
REFERENCES yii_order (key1,key2) ON DELETE CASCADE ON UPDATE RESTRICT |
|
||||||
) TYPE=INNODB; |
|
||||||
|
|
||||||
INSERT INTO yii_item (name,col1,col2) VALUES ('item 1',1,2); |
|
||||||
INSERT INTO yii_item (name,col1,col2) VALUES ('item 2',1,2); |
|
||||||
INSERT INTO yii_item (name,col1,col2) VALUES ('item 3',1,3); |
|
||||||
INSERT INTO yii_item (name,col1,col2) VALUES ('item 4',2,2); |
|
||||||
INSERT INTO yii_item (name,col1,col2) VALUES ('item 5',2,2); |
|
||||||
|
|
||||||
CREATE TABLE yii_type |
|
||||||
( |
|
||||||
int_col INT NOT NULL, |
|
||||||
int_col2 INTEGER DEFAULT 1, |
|
||||||
char_col CHAR(100) NOT NULL, |
|
||||||
char_col2 VARCHAR(100) DEFAULT 'something', |
|
||||||
char_col3 TEXT, |
|
||||||
float_col REAL(4,3) NOT NULL, |
|
||||||
float_col2 DOUBLE DEFAULT 1.23, |
|
||||||
blob_col BLOB, |
|
||||||
numeric_col NUMERIC(5,2) DEFAULT 33.22, |
|
||||||
time TIMESTAMP DEFAULT '2002-01-01', |
|
||||||
bool_col BOOL NOT NULL, |
|
||||||
bool_col2 BOOLEAN DEFAULT 1 |
|
||||||
) TYPE=INNODB; |
|
||||||
|
Loading…
Reference in new issue