diff --git a/composer.json b/composer.json index 4c5a78b..a0a8359 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "This library extends the builtin PDO object by several useful features. ", "type": "library", "readme": "README.md", - "keywords": ["db", "model", "pdo"], + "keywords": ["db", "model", "pdo", "mysql", "sqlite"], "authors": [ { "name": "Igor Mino", diff --git a/src/Maintenance.php b/src/Maintenance.php index cf034d6..3990f0a 100644 --- a/src/Maintenance.php +++ b/src/Maintenance.php @@ -81,10 +81,21 @@ class Maintenance public function existsTable($table_name) { - return $this->testDB( - 'SHOW TABLES LIKE "' . $table_name . '"', - $table_name - ); + $db_type = $this->dbh->getDBtype(); + switch ($db_type) { + case 'mysql': + return $this->testDB( + 'SHOW TABLES LIKE "' . $table_name . '"', + $table_name + ); + case 'sqlite': + return $this->testDB( + 'SELECT name FROM sqlite_master WHERE TYPE = "table" AND name LIKE "' . $table_name . '"', + $table_name + ); + default: + new \Exception('Unknown DB type: ' . $db_type); + } } public function checkDBTable($table_name, $definition, $after_definition = '') @@ -93,9 +104,21 @@ class Maintenance $this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index'; return Maintenance::ABNORMAL; } + $check_query = ''; + $db_type = $this->dbh->getDBtype(); + switch ($db_type) { + case 'mysql': + $check_query = 'SHOW TABLES LIKE "' . $table_name . '"'; + break; + case 'sqlite': + $check_query = 'SELECT name FROM sqlite_master WHERE TYPE = "table" AND name LIKE "' . $table_name . '"'; + break; + default: + new \Exception('Unknown DB type: ' . $db_type); + } $status = $this->checkDB( // TEST query - 'SHOW TABLES LIKE "' . $table_name . '"', + $check_query, // TEST output $table_name, // FIX query