improved Maintenance for MySQL and SQLite DB type
This commit is contained in:
@ -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",
|
||||
|
||||
@ -81,10 +81,21 @@ class Maintenance
|
||||
|
||||
public function existsTable($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
|
||||
|
||||
Reference in New Issue
Block a user