diff --git a/common.php b/common.php index 39f6829..efd930b 100644 --- a/common.php +++ b/common.php @@ -152,8 +152,6 @@ function Query($params = '') $p->$k = $v; } - //$params = new ArrayObject($params, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); - // Otherwise, return a new connection return $cmanager->connect($p); } diff --git a/core/abstract/abstract_driver.php b/core/abstract/abstract_driver.php index d06380c..3f9c54e 100644 --- a/core/abstract/abstract_driver.php +++ b/core/abstract/abstract_driver.php @@ -113,7 +113,6 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { $this->sql = new $sql_class(); $this->util = new $util_class($this); - $this->table = new Table_Builder('', array(), $this); } // -------------------------------------------------------------------------- diff --git a/core/abstract/abstract_table.php b/core/abstract/abstract_table.php deleted file mode 100644 index 9efdd92..0000000 --- a/core/abstract/abstract_table.php +++ /dev/null @@ -1,99 +0,0 @@ - $value) - { - if ( ! in_array($option, $this->valid_options)) - { - throw new \InvalidArgumentException("{$option} is not a valid {$type}"); - } - - $func = "set_{$option}"; - - (method_exists($this, "set_{$option}")) - ? $this->$func($value) - : $this->__set($option, $value); - } - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Getters - * @param mixed $name - * @return mixed - */ - public function __get($name) - { - if ( ! isset($this->$name)) return NULL; - - return $this->$name; - } - - // -------------------------------------------------------------------------- - - /** - * Setters - * @param mixed $name - * @param mixed $val - * @return Abstract_Table - */ - public function __set($name, $val) - { - $this->$name = $val; - return $this; - } - -} -// End of abstract_table.php \ No newline at end of file diff --git a/core/abstract/abstract_util.php b/core/abstract/abstract_util.php index d478e56..ed2ff9d 100644 --- a/core/abstract/abstract_util.php +++ b/core/abstract/abstract_util.php @@ -60,7 +60,6 @@ abstract class Abstract_Util { /** * Convenience public function to generate sql for creating a db table * - * @deprecated Use the table builder class instead * @param string $name * @param array $fields * @param array $constraints diff --git a/core/table_builder.php b/core/table_builder.php deleted file mode 100644 index 0aeb613..0000000 --- a/core/table_builder.php +++ /dev/null @@ -1,447 +0,0 @@ -table_options = array_merge($this->table_options, $options); - - $this->set_driver($driver); - - if ($name !== '') - { - $this->name = (isset($this->driver)) ? $this->driver->prefix_table($name) : $name; - } - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Alias to constructor - * - * @param string $name - * @param array $options - * @param Driver_Interface $driver - * @return Table_Builder - */ - public function __invoke($name = '', $options = array(), Driver_Interface $driver = NULL) - { - return $this->__construct($name, $options, $driver); - } - - // -------------------------------------------------------------------------- - - /** - * Set the reference to the current database driver - * - * @param Driver_Interface $driver - * @return Table_Builder - */ - public function set_driver(Driver_Interface $driver = NULL) - { - if ( ! is_null($driver)) - { - $this->driver = $driver; - } - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Get the current DB Driver - * - * @return Driver_Interface - */ - public function get_driver() - { - return $this->driver; - } - - // -------------------------------------------------------------------------- - // ! Column Methods - // -------------------------------------------------------------------------- - - /** - * Add a column to the current table - * - * @param string $column_name - * @param string $type - * @param array $options - * @return Table_Builder - */ - public function add_column($column_name, $type = NULL, $options = array()) - { - $col = new Table_Column($column_name, $type, $options); - $this->columns[] = $col; - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Remove the specified column name from the current table - * - * @param string $column_name - * @return \Query\Table\Table_Builder - */ - public function remove_column($column_name) - { - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Rename the specified column on the current table - * - * @param string $old_name - * @param string $new_name - * @return \Query\Table\Table_Builder - */ - public function rename_column($old_name, $new_name) - { - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Change the specified column on the current table - * - * @param string $column_name - * @param string $new_column_type - * @param array $options - * @return \Query\Table\Table_Builder - */ - public function change_column($column_name, $new_column_type, $options = array()) - { - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Determine whether the column currently exists on the current table - * - * @param string $column_name - * @param array $options - * @return bool - */ - public function has_column($column_name, $options = array()) - { - // @TODO: implement - } - - // -------------------------------------------------------------------------- - // ! Index Methods - // -------------------------------------------------------------------------- - - /** - * Add an index to the current table - * - * @param array $columns - * @param array $options - * @return \Query\Table\Table_Builder - */ - public function add_index($columns, $options = array()) - { - $col = new Table_Index($columns, $options); - $this->indexes[] = $col; - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Remove an index from the current table - * @param array $columns - * @param array $options - * @return \Query\Table\Table_Builder - */ - public function remove_index($columns, $options = array()) - { - // @TODO: implement - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Remove an index by its name from the current table - * - * @param string $name - * @return \Query\Table\Table_Builder - */ - public function remove_index_by_name($name) - { - // @TODO: implement - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Check if the current table has an index on the specified columns - * - * @param array $columns - * @param array $options - * @return bool - */ - public function has_index($columns, $options = array()) - { - // @TODO: implement - } - - // -------------------------------------------------------------------------- - // ! Foreign Key Methods - // -------------------------------------------------------------------------- - - /** - * Add a foreign key to the current table - * - * @param array $columns - * @param string $referenced_table - * @param array $referenced_columns - * @param array $options - * @return \Query\Table\Table_Builder - */ - public function add_foreign_key($columns, $referenced_table, $referenced_columns = array('id'), $options = array()) - { - $key = new Table_Foreign_Key($columns, $referenced_table, $referenced_columns, $options); - $this->foreign_keys[] = $key; - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Drop the foreign key from the current table - * - * @param array $columns - * @param string $constraint - * @return \Query\Table\Table_Builder - */ - public function drop_foreign_key($columns, $constraint = NULL) - { - // @TODO: implement - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Determine whether the current table has the specified foreign key - * - * @param array $columns - * @param string $constraint - * @return bool - */ - public function has_foreign_key($columns, $constraint = NULL) - { - // @TODO: implement - $keys = $this->get_driver()->get_fks($this->name); - - - foreach($keys as $key) - { - - } - - return FALSE; - } - - // -------------------------------------------------------------------------- - // ! Table-wide methods - // -------------------------------------------------------------------------- - - /** - * Check whether the current table exists - * - * @return bool - */ - public function exists() - { - $tables = $this->driver->get_tables(); - return in_array($this->name, $tables); - } - - // -------------------------------------------------------------------------- - - /** - * Drop the current table - * - * @return void - */ - public function drop() - { - // @TODO: implement - } - - // -------------------------------------------------------------------------- - - /** - * Rename the current table - * - * @param string $new_table_name - * @return void - */ - public function rename($new_table_name) - { - // @TODO: implement - } - - // -------------------------------------------------------------------------- - - /** - * Get the list of columns for the current table - * - * @return array - */ - public function get_columns() - { - return $this->driver->get_columns($this->name); - } - - - // -------------------------------------------------------------------------- - // ! Action methods - // -------------------------------------------------------------------------- - - /** - * Create the table from the previously set options - * - * @return void - */ - public function create() - { - // @TODO: implement - $this->reset(); - } - - // -------------------------------------------------------------------------- - - /** - * Update the current table with the changes made - * - * @return void - */ - public function update() - { - // @TODO: implement - $this->reset(); - } - - // -------------------------------------------------------------------------- - - /** - * Save the changes made to the table - * - * @return void - */ - public function save() - { - ($this->exists()) - ? $this->update() - : $this->create(); - } - - // -------------------------------------------------------------------------- - - /** - * Reset the state of the table builder - * - * @return void - */ - public function reset() - { - $skip = array( - 'driver' => 'driver' - ); - - foreach($this as $key => $val) - { - if ( ! isset($skip[$key])) - { - $this->$key = NULL; - } - } - } - -} -// End of table_builder.php diff --git a/core/table_column.php b/core/table_column.php deleted file mode 100644 index a6e6248..0000000 --- a/core/table_column.php +++ /dev/null @@ -1,83 +0,0 @@ -name = $name; - $this->type = $type; - $this->options = ( ! empty($options)) - ? $this->validate_options($options) - : array(); - } - - // -------------------------------------------------------------------------- - - /** - * Return the string to create the column - * - * @return string - */ - public function __toString() - { - // @TODO: implement - $num_args = func_num_args(); - } - -} -// End of table_column.php diff --git a/core/table_foreign_key.php b/core/table_foreign_key.php deleted file mode 100644 index 3be4b1c..0000000 --- a/core/table_foreign_key.php +++ /dev/null @@ -1,41 +0,0 @@ -assertTrue($this->db->table('test')->exists()); - } - - public function testGetDriver() - { - $this->assertEqual($this->db, $this->db->table()->get_driver()); - } - -} -// End of table_builder.php \ No newline at end of file diff --git a/tests/databases/firebird/FirebirdTableTest.php b/tests/databases/firebird/FirebirdTableTest.php deleted file mode 100644 index 6f26093..0000000 --- a/tests/databases/firebird/FirebirdTableTest.php +++ /dev/null @@ -1,37 +0,0 @@ -markTestSkipped('Firebird extension does not exist'); - } - - // test the db driver directly - $this->db = new \Query\Driver\Firebird('localhost:'.$dbpath); - $this->db->table_prefix = 'create_'; - $this->tables = $this->db->get_tables(); - } - -} -// End of FirebirdTableTest.php \ No newline at end of file diff --git a/tests/databases/mysql/MySQLTableTest.php b/tests/databases/mysql/MySQLTableTest.php deleted file mode 100644 index 0138592..0000000 --- a/tests/databases/mysql/MySQLTableTest.php +++ /dev/null @@ -1,48 +0,0 @@ -markTestSkipped("MySQL extension for PDO not loaded"); - } - - // Attempt to connect, if there is a test config file - if (is_file(QTEST_DIR . "/settings.json")) - { - $params = json_decode(file_get_contents(QTEST_DIR . "/settings.json")); - $params = $params->mysql; - - $this->db = new \Query\Driver\MySQL("mysql:host={$params->host};dbname={$params->database}", $params->user, $params->pass, array( - PDO::ATTR_PERSISTENT => TRUE - )); - } - elseif (($var = getenv('CI'))) - { - $this->db = new \Query\Driver\MySQL('host=127.0.0.1;port=3306;dbname=test', 'root'); - } - - $this->db->table_prefix = 'create_'; - } - -} -// End of MySQLTableTest.php \ No newline at end of file diff --git a/tests/databases/pgsql/PgSQLTableTest.php b/tests/databases/pgsql/PgSQLTableTest.php deleted file mode 100644 index 51053bb..0000000 --- a/tests/databases/pgsql/PgSQLTableTest.php +++ /dev/null @@ -1,48 +0,0 @@ -markTestSkipped("Postgres extension for PDO not loaded"); - } - - // Attempt to connect, if there is a test config file - if (is_file(QTEST_DIR . "/settings.json")) - { - $params = json_decode(file_get_contents(QTEST_DIR . "/settings.json")); - $params = $params->pgsql; - - $this->db = new $class("pgsql:dbname={$params->database}", $params->user, $params->pass); - } - elseif (($var = getenv('CI'))) - { - $this->db = new $class('host=127.0.0.1;port=5432;dbname=test', 'postgres'); - } - - $this->db->table_prefix = 'create_'; - } - -} -// End of PgSQLTableTest.php \ No newline at end of file diff --git a/tests/databases/sqlite/SQLiteTableTest.php b/tests/databases/sqlite/SQLiteTableTest.php deleted file mode 100644 index f3d1233..0000000 --- a/tests/databases/sqlite/SQLiteTableTest.php +++ /dev/null @@ -1,30 +0,0 @@ -db = Query('test_sqlite'); - $this->db->table_prefix = 'create_'; - } - -} -// End of SQLiteTableTest.php \ No newline at end of file diff --git a/tests/databases/sqlite/SqliteQBTest.php b/tests/databases/sqlite/SqliteQBTest.php deleted file mode 100644 index 7da121d..0000000 --- a/tests/databases/sqlite/SqliteQBTest.php +++ /dev/null @@ -1,106 +0,0 @@ -db = Query('test_sqlite'); - } - - // -------------------------------------------------------------------------- - - public function testQueryFunctionAlias() - { - $db = Query('test_sqlite'); - - $this->assertTrue($this->db === $db); - } - - // -------------------------------------------------------------------------- - - public function testQueryExplain() - { - $query = $this->db->select('id, key as k, val') - ->explain() - ->where('id >', 1) - ->where('id <', 900) - ->get('create_test', 2, 1); - - $res = $query->fetchAll(PDO::FETCH_ASSOC); - - $expected_possibilities = array(); - - $expected_possibilities[] = array( - array( - 'order' => '0', - 'from' => '0', - 'detail' => 'TABLE create_test USING PRIMARY KEY', - ) - ); - - $expected_possibilities[] = array ( - array ( - 'selectid' => '0', - 'order' => '0', - 'from' => '0', - 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid '0', - 'order' => '0', - 'from' => '0', - 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowid '0', - 'order' => '0', - 'from' => '0', - 'detail' => 'SEARCH TABLE create_test USING INTEGER PRIMARY KEY (rowid>? AND rowidassertTrue(TRUE); - $passed = TRUE; - } - } - - // Well, apparently not an expected possibility - if ( ! $passed) - { - var_export($res); - $this->assertTrue(FALSE); - } - } -} \ No newline at end of file diff --git a/tests/databases/sqlite/SqliteTest.php b/tests/databases/sqlite/SqliteTest.php deleted file mode 100644 index c27db30..0000000 --- a/tests/databases/sqlite/SqliteTest.php +++ /dev/null @@ -1,292 +0,0 @@ -db = Query('test_sqlite'); - $this->db->table_prefix = 'create_'; - } - - // -------------------------------------------------------------------------- - // ! Util Method tests - // -------------------------------------------------------------------------- - - public function testCreateTable() - { - $this->db->exec(file_get_contents(QTEST_DIR.'/db_files/sqlite.sql')); - - //Check - $dbs = $this->db->get_tables(); - - $this->assertTrue(in_array('TEST1', $dbs)); - $this->assertTrue(in_array('TEST2', $dbs)); - $this->assertTrue(in_array('NUMBERS', $dbs)); - $this->assertTrue(in_array('NEWTABLE', $dbs)); - $this->assertTrue(in_array('create_test', $dbs)); - $this->assertTrue(in_array('create_join', $dbs)); - $this->assertTrue(in_array('create_delete', $dbs)); - } - - // -------------------------------------------------------------------------- - - /*public function testBackupData() - { - $sql = mb_trim($this->db->util->backup_data(array('create_join', 'create_test'))); - - $sql_array = explode("\n", $sql); - - $expected = <<assertEqual($expected_array, $sql_array); - }*/ - - // -------------------------------------------------------------------------- - - public function testBackupStructure() - { - $sql = mb_trim($this->db->util->backup_structure()); - $expected = << 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); - $result_array = explode("\n", $sql); - - $this->assertEqual($expected_array, $result_array); - } - - // -------------------------------------------------------------------------- - - public function testDeleteTable() - { - $sql = $this->db->util->delete_table('create_delete'); - - $this->db->query($sql); - - //Check - $dbs = $this->db->get_tables(); - $this->assertFalse(in_array('create_delete', $dbs)); - } - - // -------------------------------------------------------------------------- - // ! General tests - // -------------------------------------------------------------------------- - - public function testConnection() - { - $db = new \Query\Driver\SQLite(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'); - - $this->assertIsA($db, '\\Query\\Driver\\SQLite'); - $this->assertIsA($this->db->db, '\\Query\\Driver\\SQLite'); - - unset($db); - } - - // -------------------------------------------------------------------------- - - public function testTruncate() - { - $this->db->truncate('create_test'); - } - - // -------------------------------------------------------------------------- - - public function testPreparedStatements() - { - $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); - - $statement->execute(); - - } - - // -------------------------------------------------------------------------- - - public function testPrepareExecute() - { - $sql = <<db->prepare_execute($sql, array( - 2, "works", 'also?' - )); - - } - - // -------------------------------------------------------------------------- - - public function testCommitTransaction() - { - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; - $this->db->query($sql); - - $res = $this->db->commit(); - $this->assertTrue($res); - } - - // -------------------------------------------------------------------------- - - public function testRollbackTransaction() - { - $res = $this->db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; - $this->db->query($sql); - - $res = $this->db->rollback(); - $this->assertTrue($res); - } - - // -------------------------------------------------------------------------- - - public function testGetDBs() - { - $this->assertTrue(is_array($this->db->get_dbs())); - } - - // -------------------------------------------------------------------------- - - public function testGetSchemas() - { - $this->assertNull($this->db->get_schemas()); - } - - // -------------------------------------------------------------------------- - // ! SQL tests - // -------------------------------------------------------------------------- - - public function testNullMethods() - { - $sql = $this->db->sql->function_list(); - $this->assertEqual(NULL, $sql); - - $sql = $this->db->sql->procedure_list(); - $this->assertEqual(NULL, $sql); - - $sql = $this->db->sql->sequence_list(); - $this->assertEqual(NULL, $sql); - } - - // -------------------------------------------------------------------------- - - public function testGetSystemTables() - { - $sql = $this->db->get_system_tables(); - $this->assertTrue(is_array($sql)); - } - - // -------------------------------------------------------------------------- - - public function testGetSequences() - { - $this->assertNull($this->db->get_sequences()); - } - - // -------------------------------------------------------------------------- - - public function testGetFunctions() - { - $this->assertNull($this->db->get_functions()); - } - - // -------------------------------------------------------------------------- - - public function testGetProcedures() - { - $this->assertNull($this->db->get_procedures()); - } -} \ No newline at end of file diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index f2f0482..1c303f0 100755 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ diff --git a/tests/index.php b/tests/index.php index afdbbb7..176fb01 100644 --- a/tests/index.php +++ b/tests/index.php @@ -32,12 +32,12 @@ if ( ! defined('IS_QUERCUS')) // Include simpletest // it has to be in the tests folder -require_once('simpletest/autorun.php'); +require_once('/htdocs/__lib/simpletest/autorun.php'); /** * Base class for TestCases */ -class Query_TestCase extends UnitTestCase { +abstract class Query_TestCase extends UnitTestCase { /** * Define assertInstanceOf for simpletest @@ -110,12 +110,28 @@ require_once(QTEST_DIR . '/core/core.php'); require_once(QTEST_DIR . '/core/db_test.php'); require_once(QTEST_DIR . '/core/db_qb_test.php'); -require_once("{$test_path}sqlite/SQLiteTest.php"); -//require_once("{$test_path}mysql/MySQLTest.php"); -//require_once("{$test_path}mysql/MySQLQBTest.php"); -require_once("{$test_path}pgsql/PgSQLTest.php"); -require_once("{$test_path}pgsql/PgSQLQBTest.php"); -require_once("{$test_path}sqlite/SQLiteQBTest.php"); +$drivers = PDO::getAvailableDrivers(); +if (function_exists('fbird_connect')) +{ + $drivers[] = 'interbase'; +} +$driver_test_map = array( + 'Firebird' => in_array('interbase', $drivers), + 'SQLite' => in_array('sqlite', $drivers), + 'PgSQL' => in_array('pgsql', $drivers), +); + +// Determine which testcases to load +foreach($driver_test_map as $name => $do_load) +{ + $path = $test_path . strtolower($name) . '/'; + + if ($do_load && ($name != 'SQLite' && ! IS_QUERCUS)) + { + require_once("{$path}{$name}Test.php"); + require_once("{$path}{$name}QBTest.php"); + } +} // End of index.php \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 34a30ce..9916d02 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -18,22 +18,18 @@ databases/firebird/FirebirdTest.php - databases/firebird/FirebirdTableTest.php databases/firebird/FirebirdQBTest.php databases/mysql/MySQLTest.php - databases/mysql/MySQLTableTest.php databases/mysql/MySQLQBTest.php databases/pgsql/PgSQLTest.php - databases/pgsql/PgSQLTableTest.php databases/pgsql/PgSQLQBTest.php databases/sqlite/SQLiteTest.php - databases/sqlite/SQLiteQBTest.php