From 48c2501f41c51766ade95067f35be2798c6f8d36 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 7 Feb 2012 20:50:25 -0500 Subject: [PATCH] Added delete_table method to database manipulation classes --- src/common/db_pdo.php | 9 +++++++++ src/databases/firebird_manip.php | 11 +++++++++++ src/databases/mysql_manip.php | 21 +++++++++++++++++++++ src/databases/odbc_manip.php | 5 +++++ src/databases/pgsql_manip.php | 5 +++++ src/databases/sqlite_manip.php | 11 +++++++++++ 6 files changed, 62 insertions(+) diff --git a/src/common/db_pdo.php b/src/common/db_pdo.php index e22b440..bfc9423 100644 --- a/src/common/db_pdo.php +++ b/src/common/db_pdo.php @@ -160,5 +160,14 @@ abstract class db_manip { * @return string */ abstract function create_table($name, $columns, $constraints=array(), $indexes=array()); + + /** + * Get database-specific sql to drop a table + * + * @param string $name + * + * @return string + */ + abstract function delete_table($name); } // End of db_pdo.php \ No newline at end of file diff --git a/src/databases/firebird_manip.php b/src/databases/firebird_manip.php index 931786c..cd62546 100644 --- a/src/databases/firebird_manip.php +++ b/src/databases/firebird_manip.php @@ -23,6 +23,17 @@ class firebird_manip extends db_manip{ { $sql = "CREATE TABLE {$name}"; } + + /** + * Drop the selected table + * + * @param string $name + * @return string + */ + function delete_table($name) + { + return "DELETE TABLE {$name}"; + } } //End of firebird_manip.php \ No newline at end of file diff --git a/src/databases/mysql_manip.php b/src/databases/mysql_manip.php index 3820c51..e16472f 100644 --- a/src/databases/mysql_manip.php +++ b/src/databases/mysql_manip.php @@ -17,9 +17,30 @@ */ class MySQL_manip extends db_manip{ + /** + * Convienience function for creating a new MySQL table + * + * @param [type] $name [description] + * @param [type] $columns [description] + * @param array $constraints=array() [description] + * @param array $indexes=array() [description] + * + * @return [type] + */ function create_table($name, $columns, $constraints=array(), $indexes=array()) { //TODO: implement + } + + /** + * Convience function for droping a MySQL table + * + * @param string $name + * @return string + */ + function delete_table($name) + { + return "DROP TABLE `{$name}`"; } } //End of mysql_manip.php \ No newline at end of file diff --git a/src/databases/odbc_manip.php b/src/databases/odbc_manip.php index f6d6f65..720bb3e 100644 --- a/src/databases/odbc_manip.php +++ b/src/databases/odbc_manip.php @@ -24,5 +24,10 @@ class ODBC_manip extends db_manip { //ODBC can't know how to create a table return FALSE; } + + function delete_table($name) + { + return "DROP TABLE {$name}"; + } } // End of odbc_manip.php \ No newline at end of file diff --git a/src/databases/pgsql_manip.php b/src/databases/pgsql_manip.php index 008246a..40e7afd 100644 --- a/src/databases/pgsql_manip.php +++ b/src/databases/pgsql_manip.php @@ -24,5 +24,10 @@ class pgSQL_manip extends db_manip { //TODO: implement } + function delete_table($name) + { + return 'DROP TABLE "'.$name.'"'; + } + } //End of pgsql_manip.php \ No newline at end of file diff --git a/src/databases/sqlite_manip.php b/src/databases/sqlite_manip.php index f1fa01a..c45e471 100644 --- a/src/databases/sqlite_manip.php +++ b/src/databases/sqlite_manip.php @@ -74,6 +74,17 @@ class SQLite_manip extends db_manip { return $sql; } + /** + * SQL to drop the specified table + * + * @param string $name + * @return string + */ + function delete_table($name) + { + return "DROP TABLE IF EXISTS {$table}"; + } + /** * Create an sqlite database file *