From 5d5588c9095c3dee73e7678a2bddf1c7995a88e6 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 18 Apr 2012 16:28:12 -0400 Subject: [PATCH] Various tweaks --- classes/db_pdo.php | 4 ++-- classes/db_util.php | 18 ++++++++++++++++++ drivers/firebird/firebird_util.php | 13 ++++++++----- drivers/mysql/mysql_util.php | 5 ++++- tests/core/db_test.php | 5 +++++ tests/databases/firebird/firebird.php | 1 - tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 3c4f240..6e58163 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -171,9 +171,9 @@ abstract class DB_PDO extends PDO { */ public function get_last_error() { - $info = $this->errorInfo(); + list($i1, $i2, $i3) = $this->errorInfo(); - echo "Error:
{$info[0]}:{$info[1]}\n{$info[2]}
"; + echo "Error:
{$i1}:{$i2}\n{$i3}
"; } // -------------------------------------------------------------------------- diff --git a/classes/db_util.php b/classes/db_util.php index d6503a4..34993ef 100644 --- a/classes/db_util.php +++ b/classes/db_util.php @@ -27,6 +27,24 @@ abstract class DB_Util { $this->conn =& $conn; } + // -------------------------------------------------------------------------- + + /** + * Enable calling driver methods + * + * @param string $method + * @param array $args + */ + public function __call($method, $args) + { + if (method_exists($this->conn, $method)) + { + return call_user_func_array(array($this->conn, $method), $args); + } + + return NULL; + } + // -------------------------------------------------------------------------- // ! Abstract Methods // -------------------------------------------------------------------------- diff --git a/drivers/firebird/firebird_util.php b/drivers/firebird/firebird_util.php index 804e749..a0dc334 100644 --- a/drivers/firebird/firebird_util.php +++ b/drivers/firebird/firebird_util.php @@ -140,9 +140,12 @@ class Firebird_Util extends DB_Util { { $sql = 'SELECT * FROM "'.trim($t).'"'; $res = $this->query($sql); - $obj_res = $this->fetchAll(PDO::FETCH_ASSOC); - - unset($res); + $obj_res = $res->fetchAll(PDO::FETCH_ASSOC); + + // Don't add to the file if the table is empty + if (count($obj_res) < 1) continue; + + $res = NULL; // Nab the column names by getting the keys of the first row $columns = @array_keys($obj_res[0]); @@ -163,12 +166,12 @@ class Firebird_Util extends DB_Util { $row_string = 'INSERT INTO "'.trim($t).'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');'; - unset($row); + $row = NULL; $insert_rows[] = $row_string; } - unset($obj_res); + $obj_res = NULL; $output_sql .= "\n\nSET TRANSACTION;\n".implode("\n", $insert_rows)."\nCOMMIT;"; } diff --git a/drivers/mysql/mysql_util.php b/drivers/mysql/mysql_util.php index 283ae8c..4c197b1 100644 --- a/drivers/mysql/mysql_util.php +++ b/drivers/mysql/mysql_util.php @@ -121,10 +121,13 @@ class MySQL_Util extends DB_Util { /** * Create an SQL backup file for the current database's data * + * @param array $exclude * @return string */ - public function backup_data() + public function backup_data($exclude=array()) { + $tables = $this->get_tables(); + // @todo Implement Backup function return ''; } diff --git a/tests/core/db_test.php b/tests/core/db_test.php index 3e698c2..22b0587 100644 --- a/tests/core/db_test.php +++ b/tests/core/db_test.php @@ -48,5 +48,10 @@ abstract class DBTest extends UnitTestCase { $res = $this->db->beginTransaction(); $this->assertTrue($res); } + + function TestBackupData() + { + $this->assertTrue(is_string($this->db->util->backup_data())); + } } // End of db_test.php \ No newline at end of file diff --git a/tests/databases/firebird/firebird.php b/tests/databases/firebird/firebird.php index abb48f6..9252908 100644 --- a/tests/databases/firebird/firebird.php +++ b/tests/databases/firebird/firebird.php @@ -187,5 +187,4 @@ SQL; { $this->assertTrue(is_array($this->db->get_triggers())); } - } \ 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 a7da6afd7787ab75bf5870d68d651a93c78f2c15..83122eda73c023987676d6b16780adf71c9d6e82 100644 GIT binary patch delta 1197 zcmZ9LO=uHQ5Xa{w*=(9e=_^)HkTh)?QamLHir}H4AV|SgqOK)qYGVl!KTf>|(Y+~% z!XRFY=uH&Ui+J-Qie9{UY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