From 113d75f8250af80b05d9e72bb6e0c619d9cde0f3 Mon Sep 17 00:00:00 2001 From: Geoff Munn Date: Fri, 30 Apr 2010 04:26:53 +0000 Subject: [PATCH] API CHANGE: dev/tests/cleanupdb functionality now supported --- code/PostgreSQLDatabase.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index b8671d7..82438c3 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -234,6 +234,15 @@ class PostgreSQLDatabase extends SS_Database { $this->query("DROP DATABASE $db_to_drop"); } + /** + * Drop the database that this object is currently connected to. + * Use with caution. + */ + public function dropDatabaseByName($dbName) { + if($dbName!=$this->database) + $this->query("DROP DATABASE \"$dbName\";"); + } + /** * Returns the name of the currently selected database */ @@ -264,6 +273,13 @@ class PostgreSQLDatabase extends SS_Database { return $this->query("SELECT datname FROM pg_database WHERE datname='$SQL_name';")->first() ? true : false; } + /** + * Returns a column + */ + public function allDatabaseNames() { + return $this->query("SELECT datname FROM pg_database WHERE datistemplate=false;")->column(); + } + public function createTable($tableName, $fields = null, $indexes = null, $options = null, $extensions = null) { $fieldSchemas = $indexSchemas = ""; @@ -1641,7 +1657,7 @@ class PostgreSQLDatabase extends SS_Database { $date = "TIMESTAMP '$date'"; } - // ... when being too precise becomes a pain. We need to cut of the fractions. + // ... when being too precise becomes a pain. we need to cut of the fractions. // TIMESTAMP(0) doesn't work because it rounds instead flooring return "CAST(SUBSTRING(CAST($date + INTERVAL '$interval' AS VARCHAR) FROM 1 FOR 19) AS TIMESTAMP)"; }