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. ",
|
"description": "This library extends the builtin PDO object by several useful features. ",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"keywords": ["db", "model", "pdo"],
|
"keywords": ["db", "model", "pdo", "mysql", "sqlite"],
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Igor Mino",
|
"name": "Igor Mino",
|
||||||
|
|||||||
@ -81,10 +81,21 @@ class Maintenance
|
|||||||
|
|
||||||
public function existsTable($table_name)
|
public function existsTable($table_name)
|
||||||
{
|
{
|
||||||
return $this->testDB(
|
$db_type = $this->dbh->getDBtype();
|
||||||
'SHOW TABLES LIKE "' . $table_name . '"',
|
switch ($db_type) {
|
||||||
$table_name
|
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 = '')
|
public function checkDBTable($table_name, $definition, $after_definition = '')
|
||||||
@ -93,9 +104,21 @@ class Maintenance
|
|||||||
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index';
|
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index';
|
||||||
return Maintenance::ABNORMAL;
|
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(
|
$status = $this->checkDB(
|
||||||
// TEST query
|
// TEST query
|
||||||
'SHOW TABLES LIKE "' . $table_name . '"',
|
$check_query,
|
||||||
// TEST output
|
// TEST output
|
||||||
$table_name,
|
$table_name,
|
||||||
// FIX query
|
// FIX query
|
||||||
|
|||||||
Reference in New Issue
Block a user