From 257609168e260864146ae1c166d1055ccb226d65 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 15 May 2012 13:35:59 -0400 Subject: [PATCH] implemented mysql backup methods --- classes/db_pdo.php | 2 +- drivers/mysql/mysql_util.php | 28 ++++++++++++++-------------- tests/databases/mysql/mysql.php | 5 +++++ tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 33f1b12..bbdb2df 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -401,7 +401,7 @@ abstract class DB_PDO extends PDO { * @param bool $filtered_index * @return mixed */ - protected function driver_query($sql, $filtered_index=TRUE) + public function driver_query($sql, $filtered_index=TRUE) { // Return if the query doesn't apply to the driver if ($sql === FALSE) diff --git a/drivers/mysql/mysql_util.php b/drivers/mysql/mysql_util.php index 4b5b0b4..79b818e 100644 --- a/drivers/mysql/mysql_util.php +++ b/drivers/mysql/mysql_util.php @@ -124,30 +124,30 @@ class MySQL_Util extends DB_Util { */ public function backup_structure() { - $sql = ''; + $string = array(); // Get databases - $dbs = $this->conn->get_dbs(); + $dbs = $this->get_dbs(); foreach($dbs as &$d) { - // Get the list of tables - $tables = $this->conn->driver_query("SHOW TABLES FROM `{$database}`"); - - // Get the list of views - $views = $this->conn->driver_query("SHOW VIEWS FROM `{$database}`"); - - $tav = array_merge($tabes,$views); - - foreach($tav as &$table) + // Skip built-in dbs + if ($d == 'mysql') { - $string = $this->conn->driver_query("SHOW CREATE TABLE {$table}"); + continue; } + + // Get the list of tables + $tables = $this->driver_query("SHOW TABLES FROM `{$d}`"); + foreach($tables as &$table) + { + $array = $this->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE); + $string[] = $array[0]['Create Table']; + } } - // TODO Implement Backup function - return ''; + return implode("\n\n", $string); } // -------------------------------------------------------------------------- diff --git a/tests/databases/mysql/mysql.php b/tests/databases/mysql/mysql.php index c9556b7..d119d3e 100644 --- a/tests/databases/mysql/mysql.php +++ b/tests/databases/mysql/mysql.php @@ -192,4 +192,9 @@ SQL; { $this->assertFalse($this->db->get_sequences()); } + + public function TestBackup() + { + $this->assertTrue(is_string($this->db->util->backup_structure())); + } } \ 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 80be6d4603194a5564a16ad5382ca3750e7b1376..fc4aad5723476af99e1a0d1bba47a046fe049502 100644 GIT binary patch delta 1183 zcmZ9LO=uHQ5Xa}`!!~&&`$PlnK}p)g2T*0Ai zZvy^bMwk43<=SQf;1MkVpSt%M;MBnn={@7T!GMqM8BZvBHWSYiGtaDfV;f}~pKbiM z3D_oRn;o_pvCXJ$Ldzx`FluQf7!MalZyh$fSI%d`^CNaPyqwj6r)NqbK3krr)h<|w zq~MD+0WYi+I93LVRveDe%FwqlD*~I*N%%->DVl)=va`_$Oq0z-Q!qyF?ll{Uz>~;6 zyx!F@oLkj#)xYZfur(o=ai-8Zz|2a0avrSEFLr!QO-zw32VZuIwqrw_bs z;LDaip&A%$>nSov+H`gUul95rU$=EqJ;WAy@)9Q;(Sbfkv~cP}oH`cPh*M`y9sjNo zr|xo+_`a*t>OS81N*sw}&e@`9=J-Ig<#NvzF4eYi0BRWP5T}NP4&_tB#~tF-m@~dk zoV%D`CyvB%oeYR(F8D+nFFysKdN>NgRn2j_5uoDB5ch6|g+SDKn>xsb5sQGB>F_(4;GIVz} delta 1182 zcmZ9LO=uHQ5Xa}`YqNQjKCwCUmQRyof(4@lN!n0i8)}qL>&aLMUPM6-r9OH3}*D*fF z_#G2)jOCc1W9&^6@)@yx&5ZWFzLv3hYk4oLldv5~LeNga zb2|n#I}KC82yELCIJ8IyC*Zyvhc8wfURr5r(paK@8Tz+kC1HlX-RoUo0`>!^@Nr*< z@!pP(s1iQe(Tg-}^l6yKY)j7-OO)wHTJ8Zww*k@KfxdNHv^(o&To|s0fu8wP!1pbE zQ5DeN)^jvmX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