diff --git a/core/database.class.php b/core/database.class.php index ecd617fd..9b254f31 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -412,12 +412,34 @@ class Database { } } - /** * Create a table from pseudo-SQL */ public function create_table($name, $data) { $this->execute($this->engine->create_table_sql($name, $data)); } + + /** + * Returns the number of tables present in the current database. + */ + public function count_tables() { + if($this->engine->name === "mysql") { + return count( + $this->get_all("SHOW TABLES") + ); + } else if ($this->engine->name === "pgsql") { + return count( + $this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'") + ); + } else if ($this->engine->name === "sqlite") { + return count( + $this->get_all(".tables") + ); + } else { + // Hard to find a universal way to do this... + return NULL; + } + } + } ?> diff --git a/install.php b/install.php index 104a5776..b177fd5d 100644 --- a/install.php +++ b/install.php @@ -300,7 +300,7 @@ function create_tables() { // {{{ try { $db = new Database(); - if ( count($db->get_all("SHOW TABLES")) > 0 ) { + if ( $db->count_tables() > 0 ) { echo "
Warning: The Database schema is not empty!
Please ensure that the database you are installing Shimmie with is empty before continuing.