mirror of
https://github.com/friendica/friendica
synced 2024-11-18 17:03:41 +00:00
Ensure that a view is a view and not a table
This commit is contained in:
parent
ea2923be67
commit
7e6a9bd893
1 changed files with 41 additions and 1 deletions
|
@ -111,7 +111,11 @@ class View
|
|||
}
|
||||
}
|
||||
|
||||
$sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name));
|
||||
if (self::isView($name)) {
|
||||
$sql = sprintf("DROP VIEW `%s`", DBA::escape($name));
|
||||
} elseif (self::isTable($name)) {
|
||||
$sql = sprintf("DROP TABLE `%s`", DBA::escape($name));
|
||||
}
|
||||
|
||||
if ($verbose) {
|
||||
echo $sql . ";\n";
|
||||
|
@ -134,4 +138,40 @@ class View
|
|||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given table/view is a view
|
||||
*
|
||||
* @param string $view
|
||||
* @return boolean "true" if it's a view
|
||||
*/
|
||||
private static function isView(string $view)
|
||||
{
|
||||
$status = DBA::selectFirst(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_TYPE'],
|
||||
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_NAME' => $view]);
|
||||
|
||||
if (empty($status['TABLE_TYPE'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $status['TABLE_TYPE'] == 'VIEW';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given table/view is a view
|
||||
*
|
||||
* @param string $table
|
||||
* @return boolean "true" if it's a table
|
||||
*/
|
||||
private static function isTable(string $table)
|
||||
{
|
||||
$status = DBA::selectFirst(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_TYPE'],
|
||||
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_NAME' => $table]);
|
||||
|
||||
if (empty($status['TABLE_TYPE'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $status['TABLE_TYPE'] == 'BASE TABLE';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue