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

@ -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();
}
// -------------------------------------------------------------------------

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 .= ")";

View File

@ -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", "<"));
}
/**

View File

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

View File

@ -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()

Binary file not shown.

Binary file not shown.