diff --git a/core/interfaces/sql_interface.php b/core/interfaces/sql_interface.php index 1ff40dc..b8a3aa6 100644 --- a/core/interfaces/sql_interface.php +++ b/core/interfaces/sql_interface.php @@ -126,7 +126,7 @@ interface SQL_Interface { * Get the list of foreign keys for the current * table * - * @parma string $table + * @param string $table * @return array */ public function fk_list($table); diff --git a/drivers/firebird/firebird_sql.php b/drivers/firebird/firebird_sql.php index ae7e553..05c8c66 100644 --- a/drivers/firebird/firebird_sql.php +++ b/drivers/firebird/firebird_sql.php @@ -276,20 +276,16 @@ SQL; * Get the list of foreign keys for the current * table * - * @parma string $table + * @param string $table * @return string */ public function fk_list($table) { return << $row['from'], + 'parent_table' => $row['table'], + 'parent_column' => $row['to'] + ); + } + + return $return_rows; + } + + // -------------------------------------------------------------------------- + /** * Create sql for batch insert * diff --git a/tests/core/db_test.php b/tests/core/db_test.php index a39dfbf..dd8e6d7 100644 --- a/tests/core/db_test.php +++ b/tests/core/db_test.php @@ -74,8 +74,14 @@ abstract class DBTest extends Query_TestCase { public function testGetFKs() { - $keys = $this->db->get_fks('test'); - $this->assertTrue(is_array($keys)); + $expected = array(array( + 'child_column' => 'ext_id', + 'parent_table' => 'testconstraints', + 'parent_column' => 'someid' + )); + + $keys = $this->db->get_fks('testconstraints2'); + $this->assertEqual($expected, $keys); } // -------------------------------------------------------------------------- diff --git a/tests/databases/pgsql/PgSQLTest.php b/tests/databases/pgsql/PgSQLTest.php index 039f5e9..9193d4a 100644 --- a/tests/databases/pgsql/PgSQLTest.php +++ b/tests/databases/pgsql/PgSQLTest.php @@ -229,7 +229,7 @@ SQL; // -------------------------------------------------------------------------- - public function testGetsProcedures() + public function testGetProcedures() { $this->assertTrue(is_array($this->db->get_procedures())); } diff --git a/tests/databases/sqlite/SqliteTest.php b/tests/databases/sqlite/SqliteTest.php index 81523da..dfecbe3 100644 --- a/tests/databases/sqlite/SqliteTest.php +++ b/tests/databases/sqlite/SqliteTest.php @@ -116,6 +116,25 @@ CREATE VIEW "numbersview" AS SELECT * FROM NUMBERS WHERE NUMBER > 100; +CREATE TABLE "testconstraints" ( + someid integer NOT NULL, + somename TEXT NOT NULL, + CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid) +); +CREATE TABLE "testconstraints2" ( + ext_id integer NOT NULL, + modified text, + uniquefield text NOT NULL, + usraction integer NOT NULL, + CONSTRAINT testconstraints_id_fk FOREIGN KEY (ext_id) + REFERENCES testconstraints (someid) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction), + CONSTRAINT uniquefld_idx UNIQUE (uniquefield) +); +; +; SQL; $expected_array = explode("\n", $expected); diff --git a/tests/db_files/firebird.sql b/tests/db_files/firebird.sql index 598f9c3..11e2d0b 100644 --- a/tests/db_files/firebird.sql +++ b/tests/db_files/firebird.sql @@ -92,3 +92,22 @@ BEGIN END ^ SET TERM ; ^ + +-- TABLEs for testing CONSTRAINTs +CREATE TABLE "testconstraints" ( + "someid" integer NOT NULL, + "somename" char(10) NOT NULL, + CONSTRAINT "testconstraints_id_pk" PRIMARY KEY ("someid") +); +CREATE TABLE "testconstraints2" ( + "ext_id" integer NOT NULL, + "modified" date, + "uniquefield" char(10) NOT NULL, + "usraction" integer NOT NULL, + CONSTRAINT "testconstraints_id_fk" FOREIGN KEY ("ext_id") + REFERENCES "testconstraints" ("someid") + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT "unique_2_fields_idx" UNIQUE ("modified", "usraction"), + CONSTRAINT "uniquefld_idx" UNIQUE ("uniquefield") +); diff --git a/tests/db_files/mysql.sql b/tests/db_files/mysql.sql index febbdfc..0ad646f 100644 --- a/tests/db_files/mysql.sql +++ b/tests/db_files/mysql.sql @@ -27,7 +27,8 @@ 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 ( +DROP TABLE IF EXISTS NUMBERS; +CREATE TABLE NUMBERS ( NUMBER INTEGER DEFAULT '0' NOT NULL, EN CHAR(100) NOT NULL, FR CHAR(100) NOT NULL @@ -66,19 +67,22 @@ FROM NUMBERS WHERE NUMBER > 100; -- TABLEs for testing CONSTRAINTs -CREATE TABLE IF NOT EXISTS testconstraints ( +DROP TABLE IF EXISTS testconstraints; +CREATE TABLE testconstraints ( someid integer NOT NULL, somename varchar(10) NOT NULL, CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid) ); -CREATE TABLE IF NOT EXISTS testconstraints2 ( +DROP TABLE IF EXISTS testconstraints2; +CREATE TABLE testconstraints2 ( ext_id integer NOT NULL, modified date, uniquefield varchar(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, + REFERENCES testconstraints (someid) + ON UPDATE CASCADE + ON DELETE CASCADE, CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction), CONSTRAINT uniquefld_idx UNIQUE (uniquefield) ); diff --git a/tests/db_files/sqlite.sql b/tests/db_files/sqlite.sql index f4f733a..babf32c 100644 --- a/tests/db_files/sqlite.sql +++ b/tests/db_files/sqlite.sql @@ -57,4 +57,26 @@ DROP VIEW IF EXISTS "numbersview"; CREATE VIEW "numbersview" AS SELECT * FROM NUMBERS -WHERE NUMBER > 100; \ No newline at end of file +WHERE NUMBER > 100; + +-- TABLEs for testing CONSTRAINTs +DROP TABLE IF EXISTS "testconstraints"; +CREATE TABLE "testconstraints" ( + someid integer NOT NULL, + somename TEXT NOT NULL, + CONSTRAINT testconstraints_id_pk PRIMARY KEY (someid) +); + +DROP TABLE IF EXISTS "testconstraints2"; +CREATE TABLE "testconstraints2" ( + ext_id integer NOT NULL, + modified text, + uniquefield text NOT NULL, + usraction integer NOT NULL, + CONSTRAINT testconstraints_id_fk FOREIGN KEY (ext_id) + REFERENCES testconstraints (someid) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT unique_2_fields_idx UNIQUE (modified, usraction), + CONSTRAINT uniquefld_idx UNIQUE (uniquefield) +); \ No newline at end of file