diff --git a/common/db_pdo.php b/common/db_pdo.php index ea6c102..168eb1a 100644 --- a/common/db_pdo.php +++ b/common/db_pdo.php @@ -183,7 +183,20 @@ abstract class DB_PDO extends PDO { * @return array */ abstract public function get_system_tables(); - + + /** + * Return an SQL file with the database table structure + * + * @return string + */ + abstract public function backup_structure(); + + /** + * Return an SQL file with the database data as insert statements + * + * @return string + */ + abstract public function backup_data(); } // ------------------------------------------------------------------------- diff --git a/databases/firebird.php b/databases/firebird.php index 0a46cae..250bb2a 100644 --- a/databases/firebird.php +++ b/databases/firebird.php @@ -35,6 +35,8 @@ class firebird extends DB_PDO { $class = __CLASS__."_manip"; $this->manip = new $class; } + + // -------------------------------------------------------------------------- /** * Close the link to the database @@ -44,6 +46,8 @@ class firebird extends DB_PDO { @ibase_close($this->conn); @ibase_free_result($this->statement); } + + // -------------------------------------------------------------------------- /** * Empty a database table @@ -57,6 +61,8 @@ class firebird extends DB_PDO { $this->query($sql); } + // -------------------------------------------------------------------------- + /** * Wrapper public function to better match PDO * @@ -70,6 +76,8 @@ class firebird extends DB_PDO { $this->statement = ibase_query($this->conn, $sql); return $this->statement; } + + // -------------------------------------------------------------------------- /** * Emulate PDO fetch public function @@ -94,6 +102,8 @@ class firebird extends DB_PDO { break; } } + + // -------------------------------------------------------------------------- /** * Emulate PDO fetchAll public function @@ -114,6 +124,8 @@ class firebird extends DB_PDO { return $all; } + + // -------------------------------------------------------------------------- /** * Emulate PDO prepare @@ -126,6 +138,8 @@ class firebird extends DB_PDO { $this->statement = ibase_prepare($this->conn, $query); return $this->statement; } + + // -------------------------------------------------------------------------- /** * List tables for the current database @@ -151,6 +165,8 @@ SQL; return $tables; } + + // -------------------------------------------------------------------------- /** * List system tables for the current database @@ -176,6 +192,8 @@ SQL; return $tables; } + + // -------------------------------------------------------------------------- /** * Return the number of rows affected by the previous query @@ -186,6 +204,8 @@ SQL; { return ibase_affected_rows($this->conn); } + + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query @@ -206,6 +226,8 @@ SQL; return count($this->result); } + // -------------------------------------------------------------------------- + /** * Start a database transaction * @@ -221,6 +243,8 @@ SQL; return FALSE; } + // -------------------------------------------------------------------------- + /** * Commit a database transaction * @@ -231,6 +255,8 @@ SQL; return ibase_commit($this->trans); } + // -------------------------------------------------------------------------- + /** * Rollback a transaction * @@ -241,6 +267,8 @@ SQL; return ibase_rollback($this->trans); } + // -------------------------------------------------------------------------- + /** * Run a prepared statement query * @@ -257,6 +285,8 @@ SQL; return call_user_func_array('ibase_execute', $args); } + // -------------------------------------------------------------------------- + /** * Prepare and execute a query * @@ -274,6 +304,8 @@ SQL; return $this->execute($args); } + // -------------------------------------------------------------------------- + /** * Bind a prepared query with arguments for executing * @@ -287,5 +319,31 @@ SQL; // the firebird database return FALSE; } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's structure + * + * @return string + */ + public function backup_structure() + { + // @todo Implement Backup function + return ''; + } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's data + * + * @return string + */ + public function backup_data() + { + // @todo Implement Backup function + return ''; + } } // End of firebird.php \ No newline at end of file diff --git a/databases/mysql.php b/databases/mysql.php index 6b84570..6ce88e7 100644 --- a/databases/mysql.php +++ b/databases/mysql.php @@ -39,6 +39,8 @@ class MySQL extends DB_PDO { $class = __CLASS__.'_manip'; $this->manip = new $class; } + + // -------------------------------------------------------------------------- /** * Empty a table @@ -50,6 +52,8 @@ class MySQL extends DB_PDO { $this->query("TRUNCATE `{$table}`"); } + // -------------------------------------------------------------------------- + /** * Get databases for the current connection * @@ -60,6 +64,8 @@ class MySQL extends DB_PDO { $res = $this->query("SHOW DATABASES"); return $this->fetchAll(PDO::FETCH_ASSOC); } + + // -------------------------------------------------------------------------- /** * Returns the tables available in the current database @@ -71,6 +77,8 @@ class MySQL extends DB_PDO { $res = $this->query("SHOW TABLES"); return $res->fetchAll(PDO::FETCH_ASSOC); } + + // -------------------------------------------------------------------------- /** * Returns system tables for the current database @@ -82,6 +90,8 @@ class MySQL extends DB_PDO { //MySQL doesn't have system tables return array(); } + + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query @@ -92,5 +102,31 @@ class MySQL extends DB_PDO { { return isset($this->statement) ? $this->statement->rowCount() : FALSE; } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's structure + * + * @return string + */ + public function backup_structure() + { + // @todo Implement Backup function + return ''; + } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's data + * + * @return string + */ + public function backup_data() + { + // @todo Implement Backup function + return ''; + } } //End of mysql.php \ No newline at end of file diff --git a/databases/odbc.php b/databases/odbc.php index 0a635f0..2bf58e0 100644 --- a/databases/odbc.php +++ b/databases/odbc.php @@ -28,6 +28,8 @@ class ODBC extends DB_PDO { $class = __CLASS__.'_manip'; $this->manip = new $class; } + + // -------------------------------------------------------------------------- /** * List tables for the current database @@ -39,6 +41,8 @@ class ODBC extends DB_PDO { //Not possible reliably with this driver return FALSE; } + + // -------------------------------------------------------------------------- /** * List system tables for the current database/connection @@ -50,6 +54,8 @@ class ODBC extends DB_PDO { //No way of determining for ODBC return array(); } + + // -------------------------------------------------------------------------- /** * Empty the current database @@ -61,6 +67,8 @@ class ODBC extends DB_PDO { $sql = "DELETE FROM {$table}"; $this->query($sql); } + + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query @@ -71,5 +79,31 @@ class ODBC extends DB_PDO { { // TODO: Implement } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's structure + * + * @return string + */ + public function backup_structure() + { + // Not applicable to ODBC + return ''; + } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's data + * + * @return string + */ + public function backup_data() + { + // Not applicable to ODBC + return ''; + } } // End of odbc.php \ No newline at end of file diff --git a/databases/pgsql.php b/databases/pgsql.php index ec2b96f..ba5eacc 100644 --- a/databases/pgsql.php +++ b/databases/pgsql.php @@ -35,6 +35,8 @@ class pgSQL extends DB_PDO { $class = __CLASS__.'_manip'; $this->manip = new $class; } + + // -------------------------------------------------------------------------- /** * Empty a table @@ -46,6 +48,8 @@ class pgSQL extends DB_PDO { $sql = 'TRUNCATE "' . $table . '"'; $this->query($sql); } + + // -------------------------------------------------------------------------- /** * Get list of databases for the current connection @@ -66,6 +70,8 @@ SQL; return $dbs; } + + // -------------------------------------------------------------------------- /** * Get the list of tables for the current db @@ -86,6 +92,8 @@ SQL; return $tables; } + + // -------------------------------------------------------------------------- /** * Get the list of system tables @@ -107,6 +115,8 @@ SQL; return $tables; } + + // -------------------------------------------------------------------------- /** * Get a list of schemas, either for the current connection, or @@ -136,6 +146,8 @@ SQL; return $schemas; } + + // -------------------------------------------------------------------------- /** * Get a list of views for the current db @@ -155,6 +167,8 @@ SQL; return $views; } + + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query @@ -165,5 +179,31 @@ SQL; { return (isset($this->statement)) ? $this->statement->rowCount : FALSE; } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's structure + * + * @return string + */ + public function backup_structure() + { + // @todo Implement Backup function + return ''; + } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's data + * + * @return string + */ + public function backup_data() + { + // @todo Implement Backup function + return ''; + } } //End of pgsql.php \ No newline at end of file diff --git a/databases/sqlite.php b/databases/sqlite.php index 49cb114..3762e0f 100644 --- a/databases/sqlite.php +++ b/databases/sqlite.php @@ -34,6 +34,8 @@ class SQLite extends DB_PDO { $class = __CLASS__."_manip"; $this->manip = new $class; } + + // -------------------------------------------------------------------------- /** * Empty a table @@ -52,6 +54,8 @@ class SQLite extends DB_PDO { $this->statement->execute(); } + + // -------------------------------------------------------------------------- /** * List tables for the current database @@ -77,6 +81,8 @@ SQL; return $tables; } + + // -------------------------------------------------------------------------- /** * List system tables for the current database @@ -89,6 +95,8 @@ SQL; // that is of any importance. return array('sqlite_master'); } + + // -------------------------------------------------------------------------- /** * Load a database for the current connection @@ -101,6 +109,8 @@ SQL; $sql = "ATTACH DATABASE '{$db}' AS \"{$name}\""; $this->query($sql); } + + // -------------------------------------------------------------------------- /** * Unload a database from the current connection @@ -117,6 +127,8 @@ SQL; $this->statement->execute(); } + + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query @@ -127,5 +139,31 @@ SQL; { return (isset($this->statement)) ? $this->statement->rowCount : FALSE; } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's structure + * + * @return string + */ + public function backup_structure() + { + // @todo Implement Backup function + return ''; + } + + // -------------------------------------------------------------------------- + + /** + * Create an SQL backup file for the current database's data + * + * @return string + */ + public function backup_data() + { + // @todo Implement Backup function + return ''; + } } //End of sqlite.php \ No newline at end of file diff --git a/databases/sqlite_manip.php b/databases/sqlite_manip.php index b3cedd3..d8f622f 100644 --- a/databases/sqlite_manip.php +++ b/databases/sqlite_manip.php @@ -67,7 +67,7 @@ class SQLite_manip extends db_manip { } // Generate the sql for the creation of the table - $sql = "CREATE TABLE \"{$name}\" ("; + $sql = "CREATE TABLE IF NOT EXISTS \"{$name}\" ("; $sql .= implode(", ", $columns); $sql .= ")"; diff --git a/tests/core.php b/tests/core.php index 146278b..af31b1d 100644 --- a/tests/core.php +++ b/tests/core.php @@ -38,7 +38,6 @@ class CoreTest extends UnitTestCase { function TestPHPVersion() { $this->assertTrue(version_compare(PHP_VERSION, "5.2", "ge")); - $this->assertTrue(version_compare(PHP_VERSION, "5.4", "<")); } /** diff --git a/tests/databases/mysql.php b/tests/databases/mysql.php index c88e564..28e592c 100644 --- a/tests/databases/mysql.php +++ b/tests/databases/mysql.php @@ -29,8 +29,7 @@ class MySQLTest extends UnitTestCase { function __construct() { parent::__construct(); - - //$this->db = new MySQL(); + } } diff --git a/tests/databases/sqlite.php b/tests/databases/sqlite.php index 4c417d6..f683e04 100644 --- a/tests/databases/sqlite.php +++ b/tests/databases/sqlite.php @@ -19,12 +19,6 @@ */ class SQLiteTest extends UnitTestCase { - /** - * __construct function. - * - * @access public - * @return void - */ function __construct() { parent::__construct(); @@ -36,11 +30,11 @@ class SQLiteTest extends UnitTestCase { { $this->assertIsA($this->db, 'SQLite'); } - + function TestGetTables() { $tables = $this->db->get_tables(); - $this->assertTrue( ! empty($tables)); + $this->assertTrue(is_array($tables)); } function TestGetSystemTables() diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index 111bfce..f7adb98 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index af74dbc..460d01c 100755 Binary files a/tests/test_dbs/test_sqlite.db and b/tests/test_dbs/test_sqlite.db differ