added backup_structure and backup_data methods to db classes

This commit is contained in:
Timothy Warren 2012-02-28 16:02:37 -05:00
parent 12d850e0b8
commit dec1a1714f
12 changed files with 224 additions and 13 deletions

View File

@ -184,6 +184,19 @@ abstract class DB_PDO extends PDO {
*/ */
abstract public function get_system_tables(); 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();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------

View File

@ -36,6 +36,8 @@ class firebird extends DB_PDO {
$this->manip = new $class; $this->manip = new $class;
} }
// --------------------------------------------------------------------------
/** /**
* Close the link to the database * Close the link to the database
*/ */
@ -45,6 +47,8 @@ class firebird extends DB_PDO {
@ibase_free_result($this->statement); @ibase_free_result($this->statement);
} }
// --------------------------------------------------------------------------
/** /**
* Empty a database table * Empty a database table
* *
@ -57,6 +61,8 @@ class firebird extends DB_PDO {
$this->query($sql); $this->query($sql);
} }
// --------------------------------------------------------------------------
/** /**
* Wrapper public function to better match PDO * Wrapper public function to better match PDO
* *
@ -71,6 +77,8 @@ class firebird extends DB_PDO {
return $this->statement; return $this->statement;
} }
// --------------------------------------------------------------------------
/** /**
* Emulate PDO fetch public function * Emulate PDO fetch public function
* *
@ -95,6 +103,8 @@ class firebird extends DB_PDO {
} }
} }
// --------------------------------------------------------------------------
/** /**
* Emulate PDO fetchAll public function * Emulate PDO fetchAll public function
* *
@ -115,6 +125,8 @@ class firebird extends DB_PDO {
return $all; return $all;
} }
// --------------------------------------------------------------------------
/** /**
* Emulate PDO prepare * Emulate PDO prepare
* *
@ -127,6 +139,8 @@ class firebird extends DB_PDO {
return $this->statement; return $this->statement;
} }
// --------------------------------------------------------------------------
/** /**
* List tables for the current database * List tables for the current database
* *
@ -152,6 +166,8 @@ SQL;
return $tables; return $tables;
} }
// --------------------------------------------------------------------------
/** /**
* List system tables for the current database * List system tables for the current database
* *
@ -177,6 +193,8 @@ SQL;
return $tables; return $tables;
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows affected by the previous query * Return the number of rows affected by the previous query
* *
@ -187,6 +205,8 @@ SQL;
return ibase_affected_rows($this->conn); return ibase_affected_rows($this->conn);
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows returned for a SELECT query * Return the number of rows returned for a SELECT query
* *
@ -206,6 +226,8 @@ SQL;
return count($this->result); return count($this->result);
} }
// --------------------------------------------------------------------------
/** /**
* Start a database transaction * Start a database transaction
* *
@ -221,6 +243,8 @@ SQL;
return FALSE; return FALSE;
} }
// --------------------------------------------------------------------------
/** /**
* Commit a database transaction * Commit a database transaction
* *
@ -231,6 +255,8 @@ SQL;
return ibase_commit($this->trans); return ibase_commit($this->trans);
} }
// --------------------------------------------------------------------------
/** /**
* Rollback a transaction * Rollback a transaction
* *
@ -241,6 +267,8 @@ SQL;
return ibase_rollback($this->trans); return ibase_rollback($this->trans);
} }
// --------------------------------------------------------------------------
/** /**
* Run a prepared statement query * Run a prepared statement query
* *
@ -257,6 +285,8 @@ SQL;
return call_user_func_array('ibase_execute', $args); return call_user_func_array('ibase_execute', $args);
} }
// --------------------------------------------------------------------------
/** /**
* Prepare and execute a query * Prepare and execute a query
* *
@ -274,6 +304,8 @@ SQL;
return $this->execute($args); return $this->execute($args);
} }
// --------------------------------------------------------------------------
/** /**
* Bind a prepared query with arguments for executing * Bind a prepared query with arguments for executing
* *
@ -287,5 +319,31 @@ SQL;
// the firebird database // the firebird database
return FALSE; 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 // End of firebird.php

View File

@ -40,6 +40,8 @@ class MySQL extends DB_PDO {
$this->manip = new $class; $this->manip = new $class;
} }
// --------------------------------------------------------------------------
/** /**
* Empty a table * Empty a table
* *
@ -50,6 +52,8 @@ class MySQL extends DB_PDO {
$this->query("TRUNCATE `{$table}`"); $this->query("TRUNCATE `{$table}`");
} }
// --------------------------------------------------------------------------
/** /**
* Get databases for the current connection * Get databases for the current connection
* *
@ -61,6 +65,8 @@ class MySQL extends DB_PDO {
return $this->fetchAll(PDO::FETCH_ASSOC); return $this->fetchAll(PDO::FETCH_ASSOC);
} }
// --------------------------------------------------------------------------
/** /**
* Returns the tables available in the current database * Returns the tables available in the current database
* *
@ -72,6 +78,8 @@ class MySQL extends DB_PDO {
return $res->fetchAll(PDO::FETCH_ASSOC); return $res->fetchAll(PDO::FETCH_ASSOC);
} }
// --------------------------------------------------------------------------
/** /**
* Returns system tables for the current database * Returns system tables for the current database
* *
@ -83,6 +91,8 @@ class MySQL extends DB_PDO {
return array(); return array();
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows returned for a SELECT query * 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; 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 //End of mysql.php

View File

@ -29,6 +29,8 @@ class ODBC extends DB_PDO {
$this->manip = new $class; $this->manip = new $class;
} }
// --------------------------------------------------------------------------
/** /**
* List tables for the current database * List tables for the current database
* *
@ -40,6 +42,8 @@ class ODBC extends DB_PDO {
return FALSE; return FALSE;
} }
// --------------------------------------------------------------------------
/** /**
* List system tables for the current database/connection * List system tables for the current database/connection
* *
@ -51,6 +55,8 @@ class ODBC extends DB_PDO {
return array(); return array();
} }
// --------------------------------------------------------------------------
/** /**
* Empty the current database * Empty the current database
* *
@ -62,6 +68,8 @@ class ODBC extends DB_PDO {
$this->query($sql); $this->query($sql);
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows returned for a SELECT query * Return the number of rows returned for a SELECT query
* *
@ -71,5 +79,31 @@ class ODBC extends DB_PDO {
{ {
// TODO: Implement // 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 // End of odbc.php

View File

@ -36,6 +36,8 @@ class pgSQL extends DB_PDO {
$this->manip = new $class; $this->manip = new $class;
} }
// --------------------------------------------------------------------------
/** /**
* Empty a table * Empty a table
* *
@ -47,6 +49,8 @@ class pgSQL extends DB_PDO {
$this->query($sql); $this->query($sql);
} }
// --------------------------------------------------------------------------
/** /**
* Get list of databases for the current connection * Get list of databases for the current connection
* *
@ -67,6 +71,8 @@ SQL;
return $dbs; return $dbs;
} }
// --------------------------------------------------------------------------
/** /**
* Get the list of tables for the current db * Get the list of tables for the current db
* *
@ -87,6 +93,8 @@ SQL;
return $tables; return $tables;
} }
// --------------------------------------------------------------------------
/** /**
* Get the list of system tables * Get the list of system tables
* *
@ -108,6 +116,8 @@ SQL;
} }
// --------------------------------------------------------------------------
/** /**
* Get a list of schemas, either for the current connection, or * Get a list of schemas, either for the current connection, or
* for the current datbase, if specified. * for the current datbase, if specified.
@ -137,6 +147,8 @@ SQL;
return $schemas; return $schemas;
} }
// --------------------------------------------------------------------------
/** /**
* Get a list of views for the current db * Get a list of views for the current db
* *
@ -156,6 +168,8 @@ SQL;
return $views; return $views;
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows returned for a SELECT query * Return the number of rows returned for a SELECT query
* *
@ -165,5 +179,31 @@ SQL;
{ {
return (isset($this->statement)) ? $this->statement->rowCount : FALSE; 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 //End of pgsql.php

View File

@ -35,6 +35,8 @@ class SQLite extends DB_PDO {
$this->manip = new $class; $this->manip = new $class;
} }
// --------------------------------------------------------------------------
/** /**
* Empty a table * Empty a table
* *
@ -53,6 +55,8 @@ class SQLite extends DB_PDO {
$this->statement->execute(); $this->statement->execute();
} }
// --------------------------------------------------------------------------
/** /**
* List tables for the current database * List tables for the current database
* *
@ -78,6 +82,8 @@ SQL;
return $tables; return $tables;
} }
// --------------------------------------------------------------------------
/** /**
* List system tables for the current database * List system tables for the current database
* *
@ -90,6 +96,8 @@ SQL;
return array('sqlite_master'); return array('sqlite_master');
} }
// --------------------------------------------------------------------------
/** /**
* Load a database for the current connection * Load a database for the current connection
* *
@ -102,6 +110,8 @@ SQL;
$this->query($sql); $this->query($sql);
} }
// --------------------------------------------------------------------------
/** /**
* Unload a database from the current connection * Unload a database from the current connection
* *
@ -118,6 +128,8 @@ SQL;
$this->statement->execute(); $this->statement->execute();
} }
// --------------------------------------------------------------------------
/** /**
* Return the number of rows returned for a SELECT query * Return the number of rows returned for a SELECT query
* *
@ -127,5 +139,31 @@ SQL;
{ {
return (isset($this->statement)) ? $this->statement->rowCount : FALSE; 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 //End of sqlite.php

View File

@ -67,7 +67,7 @@ class SQLite_manip extends db_manip {
} }
// Generate the sql for the creation of the table // Generate the sql for the creation of the table
$sql = "CREATE TABLE \"{$name}\" ("; $sql = "CREATE TABLE IF NOT EXISTS \"{$name}\" (";
$sql .= implode(", ", $columns); $sql .= implode(", ", $columns);
$sql .= ")"; $sql .= ")";

View File

@ -38,7 +38,6 @@ class CoreTest extends UnitTestCase {
function TestPHPVersion() function TestPHPVersion()
{ {
$this->assertTrue(version_compare(PHP_VERSION, "5.2", "ge")); $this->assertTrue(version_compare(PHP_VERSION, "5.2", "ge"));
$this->assertTrue(version_compare(PHP_VERSION, "5.4", "<"));
} }
/** /**

View File

@ -30,7 +30,6 @@ class MySQLTest extends UnitTestCase {
{ {
parent::__construct(); parent::__construct();
//$this->db = new MySQL();
} }
} }

View File

@ -19,12 +19,6 @@
*/ */
class SQLiteTest extends UnitTestCase { class SQLiteTest extends UnitTestCase {
/**
* __construct function.
*
* @access public
* @return void
*/
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
@ -40,7 +34,7 @@ class SQLiteTest extends UnitTestCase {
function TestGetTables() function TestGetTables()
{ {
$tables = $this->db->get_tables(); $tables = $this->db->get_tables();
$this->assertTrue( ! empty($tables)); $this->assertTrue(is_array($tables));
} }
function TestGetSystemTables() function TestGetSystemTables()

Binary file not shown.

Binary file not shown.