Add test sql files
This commit is contained in:
parent
85b804adaa
commit
b40b085ae5
@ -31,8 +31,15 @@ class SQLiteTest extends DBTest {
|
|||||||
// ! Util Method tests
|
// ! Util Method tests
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function DataCreate()
|
||||||
|
{
|
||||||
|
$this->db->exec(file_get_contents(QTEST_DIR.'/db_files/sqlite.sql'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreateTable()
|
public function testCreateTable()
|
||||||
{
|
{
|
||||||
|
$this->DataCreate();
|
||||||
|
|
||||||
//Attempt to create the table
|
//Attempt to create the table
|
||||||
$sql = $this->db->util->create_table('create_test',
|
$sql = $this->db->util->create_table('create_test',
|
||||||
array(
|
array(
|
||||||
@ -106,6 +113,46 @@ SQL;
|
|||||||
$expected = <<<SQL
|
$expected = <<<SQL
|
||||||
CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
CREATE TABLE "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
||||||
CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
CREATE TABLE "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
||||||
|
CREATE TABLE TEST1 (
|
||||||
|
TEST_NAME TEXT NOT NULL,
|
||||||
|
TEST_ID INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
TEST_DATE TEXT NOT NULL,
|
||||||
|
CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID)
|
||||||
|
);
|
||||||
|
CREATE TABLE TEST2 (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
FIELD1 INTEGER,
|
||||||
|
FIELD2 TEXT,
|
||||||
|
FIELD3 TEXT,
|
||||||
|
FIELD4 INTEGER,
|
||||||
|
FIELD5 INTEGER,
|
||||||
|
ID2 INTEGER NOT NULL,
|
||||||
|
CONSTRAINT PK_TEST2 PRIMARY KEY (ID2),
|
||||||
|
CONSTRAINT TEST2_FIELD1ID_IDX UNIQUE (ID, FIELD1),
|
||||||
|
CONSTRAINT TEST2_FIELD4_IDX UNIQUE (FIELD4)
|
||||||
|
);
|
||||||
|
;
|
||||||
|
;
|
||||||
|
CREATE INDEX TEST2_FIELD5_IDX ON TEST2 (FIELD5);
|
||||||
|
CREATE TABLE NUMBERS (
|
||||||
|
NUMBER INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
EN TEXT NOT NULL,
|
||||||
|
FR TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE NEWTABLE (
|
||||||
|
ID INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
SOMENAME TEXT,
|
||||||
|
SOMEDATE TEXT NOT NULL,
|
||||||
|
CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
|
CREATE VIEW "testview" AS
|
||||||
|
SELECT *
|
||||||
|
FROM TEST1
|
||||||
|
WHERE TEST_NAME LIKE 't%';
|
||||||
|
CREATE VIEW "numbersview" AS
|
||||||
|
SELECT *
|
||||||
|
FROM NUMBERS
|
||||||
|
WHERE NUMBER > 100;
|
||||||
CREATE TABLE "create_delete" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
CREATE TABLE "create_delete" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
|
Binary file not shown.
94
tests/db_files/firebird.sql
Normal file
94
tests/db_files/firebird.sql
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
-- sample data to test Firebird system tables
|
||||||
|
|
||||||
|
-- TABLE TEST
|
||||||
|
CREATE TABLE TEST1 (
|
||||||
|
TEST_NAME CHAR(30) CHARACTER SET NONE NOT NULL COLLATE NONE,
|
||||||
|
TEST_ID INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
TEST_DATE TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE TEST1 ADD CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID);
|
||||||
|
|
||||||
|
-- TABLE TEST2 with some CONSTRAINTs and an INDEX
|
||||||
|
CREATE TABLE TEST2 (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
FIELD1 INTEGER,
|
||||||
|
FIELD2 CHAR(15) CHARACTER SET NONE COLLATE NONE,
|
||||||
|
FIELD3 VARCHAR(50) CHARACTER SET NONE COLLATE NONE,
|
||||||
|
FIELD4 INTEGER,
|
||||||
|
FIELD5 INTEGER,
|
||||||
|
ID2 INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE TEST2 ADD PRIMARY KEY (ID2);
|
||||||
|
CREATE UNIQUE INDEX TEST2_FIELD1ID_IDX ON TEST2(ID, FIELD1);
|
||||||
|
CREATE UNIQUE INDEX TEST2_FIELD4_IDX ON TEST2(FIELD4);
|
||||||
|
CREATE INDEX TEST2_FIELD5_IDX ON TEST2(FIELD5);
|
||||||
|
|
||||||
|
-- TABLE NUMBERS
|
||||||
|
CREATE TABLE NUMBERS (
|
||||||
|
NUMBER INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
EN CHAR(100) CHARACTER SET ISO8859_1 NOT NULL COLLATE ISO8859_1,
|
||||||
|
FR CHAR(100) CHARACTER SET ISO8859_1 NOT NULL COLLATE ISO8859_1
|
||||||
|
);
|
||||||
|
|
||||||
|
-- TABLE NEWTABLE
|
||||||
|
CREATE TABLE NEWTABLE (
|
||||||
|
ID INT DEFAULT 0 NOT NULL,
|
||||||
|
SOMENAME VARCHAR (12),
|
||||||
|
SOMEDESCRIPTION VARCHAR (12)
|
||||||
|
);
|
||||||
|
ALTER TABLE NEWTABLE ADD CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID);
|
||||||
|
CREATE GENERATOR NEWTABLE_SEQ;
|
||||||
|
|
||||||
|
-- VIEW on TEST
|
||||||
|
CREATE VIEW "testview"(
|
||||||
|
TEST_NAME,
|
||||||
|
TEST_ID,
|
||||||
|
TEST_DATE
|
||||||
|
) AS
|
||||||
|
SELECT *
|
||||||
|
FROM TEST1
|
||||||
|
WHERE TEST_NAME LIKE 't%';
|
||||||
|
|
||||||
|
-- VIEW on NUMBERS
|
||||||
|
CREATE VIEW "numbersview"(
|
||||||
|
NUM,
|
||||||
|
EN,
|
||||||
|
FR
|
||||||
|
) AS
|
||||||
|
SELECT *
|
||||||
|
FROM NUMBERS
|
||||||
|
WHERE NUMBER > 100;
|
||||||
|
|
||||||
|
-- TRIGGER on NEWTABLE (emulate autoincrement)
|
||||||
|
SET TERM ^ ;
|
||||||
|
|
||||||
|
CREATE TRIGGER AUTOINCREMENTPK FOR NEWTABLE
|
||||||
|
ACTIVE BEFORE INSERT POSITION 0
|
||||||
|
AS BEGIN
|
||||||
|
IF (NEW.ID IS NULL OR NEW.ID = 0) THEN
|
||||||
|
NEW.ID = GEN_ID(NEWTABLE_SEQ, 1);
|
||||||
|
END^
|
||||||
|
|
||||||
|
SET TERM ; ^
|
||||||
|
|
||||||
|
-- SAMPLE STORED PROCEDURE
|
||||||
|
SET TERM ^ ;
|
||||||
|
|
||||||
|
CREATE PROCEDURE getEnglishNumber(N INTEGER)
|
||||||
|
RETURNS (
|
||||||
|
english_number CHAR(100)
|
||||||
|
)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
FOR
|
||||||
|
SELECT EN
|
||||||
|
FROM NUMBERS
|
||||||
|
WHERE NUMBER = :N
|
||||||
|
INTO :english_number
|
||||||
|
DO
|
||||||
|
BEGIN
|
||||||
|
SUSPEND;
|
||||||
|
END
|
||||||
|
END ^
|
||||||
|
|
||||||
|
SET TERM ; ^
|
1
tests/db_files/mysql.sql
Normal file
1
tests/db_files/mysql.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
105
tests/db_files/pgsql.sql
Normal file
105
tests/db_files/pgsql.sql
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
-- sample data to test PostgreSQL INFORMATION_SCHEMA
|
||||||
|
|
||||||
|
-- TABLE TEST
|
||||||
|
CREATE TABLE IF NOT EXISTS TEST1 (
|
||||||
|
TEST_NAME CHAR(30) NOT NULL,
|
||||||
|
TEST_ID INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
TEST_DATE TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE TEST1 DROP CONSTRAINT IF EXISTS PK_TEST CASCADE;
|
||||||
|
ALTER TABLE TEST1 ADD CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID);
|
||||||
|
|
||||||
|
-- TABLE TEST2 with some CONSTRAINTs and an INDEX
|
||||||
|
CREATE TABLE IF NOT EXISTS TEST2 (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
FIELD1 INTEGER,
|
||||||
|
FIELD2 CHAR(15),
|
||||||
|
FIELD3 VARCHAR(50),
|
||||||
|
FIELD4 INTEGER,
|
||||||
|
FIELD5 INTEGER,
|
||||||
|
ID2 INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE TEST2 DROP CONSTRAINT IF EXISTS PK_TEST2 CASCADE;
|
||||||
|
ALTER TABLE TEST2 DROP CONSTRAINT IF EXISTS TEST2_FIELD1ID_IDX CASCADE;
|
||||||
|
ALTER TABLE TEST2 DROP CONSTRAINT IF EXISTS TEST2_FIELD4_IDX CASCADE;
|
||||||
|
DROP INDEX IF EXISTS TEST2_FIELD5_IDX;
|
||||||
|
|
||||||
|
ALTER TABLE TEST2 ADD CONSTRAINT PK_TEST2 PRIMARY KEY (ID2);
|
||||||
|
ALTER TABLE TEST2 ADD CONSTRAINT TEST2_FIELD1ID_IDX UNIQUE (ID, FIELD1);
|
||||||
|
ALTER TABLE TEST2 ADD CONSTRAINT TEST2_FIELD4_IDX UNIQUE (FIELD4);
|
||||||
|
CREATE INDEX TEST2_FIELD5_IDX ON TEST2(FIELD5);
|
||||||
|
|
||||||
|
-- TABLE NUMBERS
|
||||||
|
CREATE TABLE IF NOT EXISTS NUMBERS (
|
||||||
|
NUMBER INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
EN CHAR(100) NOT NULL,
|
||||||
|
FR CHAR(100) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
-- TABLE NEWTABLE
|
||||||
|
CREATE TABLE IF NOT EXISTS NEWTABLE (
|
||||||
|
ID INT DEFAULT 0 NOT NULL,
|
||||||
|
SOMENAME VARCHAR (12),
|
||||||
|
SOMEDATE TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
|
ALTER TABLE NEWTABLE DROP CONSTRAINT IF EXISTS PKINDEX_IDX CASCADE;
|
||||||
|
ALTER TABLE NEWTABLE ADD CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID);
|
||||||
|
|
||||||
|
DROP SEQUENCE IF EXISTS NEWTABLE_SEQ CASCADE;
|
||||||
|
CREATE SEQUENCE NEWTABLE_SEQ INCREMENT 1 START 1;
|
||||||
|
|
||||||
|
-- VIEW on TEST
|
||||||
|
CREATE OR REPLACE VIEW "testview"(
|
||||||
|
TEST_NAME,
|
||||||
|
TEST_ID,
|
||||||
|
TEST_DATE
|
||||||
|
) AS
|
||||||
|
SELECT *
|
||||||
|
FROM TEST1
|
||||||
|
WHERE TEST_NAME LIKE 't%';
|
||||||
|
|
||||||
|
-- VIEW on NUMBERS
|
||||||
|
CREATE OR REPLACE VIEW "numbersview"(
|
||||||
|
NUMBER,
|
||||||
|
TRANS_EN,
|
||||||
|
TRANS_FR
|
||||||
|
) AS
|
||||||
|
SELECT *
|
||||||
|
FROM NUMBERS
|
||||||
|
WHERE NUMBER > 100;
|
||||||
|
|
||||||
|
-- TRIGGER on NEWTABLE
|
||||||
|
DROP FUNCTION IF EXISTS add_stamp() CASCADE;
|
||||||
|
CREATE OR REPLACE FUNCTION add_stamp() RETURNS OPAQUE AS '
|
||||||
|
BEGIN
|
||||||
|
IF (NEW.somedate IS NULL OR NEW.somedate = 0) THEN
|
||||||
|
NEW.somedate := CURRENT_TIMESTAMP;
|
||||||
|
RETURN NEW;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
' LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS ADDCURRENTDATE ON newtable;
|
||||||
|
|
||||||
|
CREATE TRIGGER ADDCURRENTDATE
|
||||||
|
BEFORE INSERT OR UPDATE
|
||||||
|
ON newtable FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE add_stamp();
|
||||||
|
|
||||||
|
-- TABLEs for testing CONSTRAINTs
|
||||||
|
CREATE TABLE IF NOT EXISTS testconstraints (
|
||||||
|
someid integer NOT NULL,
|
||||||
|
somename character varying(10) NOT NULL,
|
||||||
|
CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid)
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS testconstraints2 (
|
||||||
|
ext_id integer NOT NULL,
|
||||||
|
modified date,
|
||||||
|
uniquefield character varying(10) NOT NULL,
|
||||||
|
usraction integer NOT NULL,
|
||||||
|
CONSTRAINT testconstraints_id_fk FOREIGN KEY (ext_id)
|
||||||
|
REFERENCES testconstraints (someid) MATCH SIMPLE
|
||||||
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction),
|
||||||
|
CONSTRAINT uniquefld_idx UNIQUE (uniquefield)
|
||||||
|
);
|
57
tests/db_files/sqlite.sql
Normal file
57
tests/db_files/sqlite.sql
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
-- sample data to test SQLite
|
||||||
|
|
||||||
|
-- TABLE TEST
|
||||||
|
DROP TABLE IF EXISTS TEST1;
|
||||||
|
CREATE TABLE TEST1 (
|
||||||
|
TEST_NAME TEXT NOT NULL,
|
||||||
|
TEST_ID INTEGER DEFAULT '0' NOT NULL,
|
||||||
|
TEST_DATE TEXT NOT NULL,
|
||||||
|
CONSTRAINT PK_TEST PRIMARY KEY (TEST_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- TABLE TEST2 with some CONSTRAINTs and an INDEX
|
||||||
|
DROP TABLE IF EXISTS TEST2;
|
||||||
|
CREATE TABLE TEST2 (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
FIELD1 INTEGER,
|
||||||
|
FIELD2 TEXT,
|
||||||
|
FIELD3 TEXT,
|
||||||
|
FIELD4 INTEGER,
|
||||||
|
FIELD5 INTEGER,
|
||||||
|
ID2 INTEGER NOT NULL,
|
||||||
|
CONSTRAINT PK_TEST2 PRIMARY KEY (ID2),
|
||||||
|
CONSTRAINT TEST2_FIELD1ID_IDX UNIQUE (ID, FIELD1),
|
||||||
|
CONSTRAINT TEST2_FIELD4_IDX UNIQUE (FIELD4)
|
||||||
|
);
|
||||||
|
CREATE INDEX TEST2_FIELD5_IDX ON TEST2 (FIELD5);
|
||||||
|
|
||||||
|
-- TABLE NUMBERS
|
||||||
|
DROP TABLE IF EXISTS NUMBERS;
|
||||||
|
CREATE TABLE NUMBERS (
|
||||||
|
NUMBER INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
EN TEXT NOT NULL,
|
||||||
|
FR TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
-- TABLE NEWTABLE
|
||||||
|
DROP TABLE IF EXISTS NEWTABLE;
|
||||||
|
CREATE TABLE NEWTABLE (
|
||||||
|
ID INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
SOMENAME TEXT,
|
||||||
|
SOMEDATE TEXT NOT NULL,
|
||||||
|
CONSTRAINT PKINDEX_IDX PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- VIEW on TEST
|
||||||
|
DROP VIEW IF EXISTS "testview";
|
||||||
|
CREATE VIEW "testview" AS
|
||||||
|
SELECT *
|
||||||
|
FROM TEST1
|
||||||
|
WHERE TEST_NAME LIKE 't%';
|
||||||
|
|
||||||
|
-- VIEW on NUMBERS
|
||||||
|
DROP VIEW IF EXISTS "numbersview";
|
||||||
|
CREATE VIEW "numbersview" AS
|
||||||
|
SELECT *
|
||||||
|
FROM NUMBERS
|
||||||
|
WHERE NUMBER > 100;
|
Loading…
Reference in New Issue
Block a user