mirror of
https://github.com/friendica/friendica
synced 2025-04-24 03:10:11 +00:00
Correctly escape identifier names
- Add support for schema, multiple tables in $table parameters - Remove Database->formatTableName method
This commit is contained in:
parent
c290bcb975
commit
0e0fff3324
3 changed files with 129 additions and 106 deletions
|
@ -40,16 +40,19 @@ class DBStructure
|
|||
*/
|
||||
public static function convertToInnoDB()
|
||||
{
|
||||
$r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
|
||||
DBA::escape(DBA::databaseName()));
|
||||
$tables = DBA::selectToArray(
|
||||
['information_schema' => 'tables'],
|
||||
['table_name'],
|
||||
['engine' => 'MyISAM', 'table_schema' => DBA::databaseName()]
|
||||
);
|
||||
|
||||
if (!DBA::isResult($r)) {
|
||||
if (!DBA::isResult($tables)) {
|
||||
echo L10n::t('There are no tables on MyISAM.') . "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r AS $table) {
|
||||
$sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", DBA::escape($table['TABLE_NAME']));
|
||||
foreach ($tables AS $table) {
|
||||
$sql = "ALTER TABLE " . DBA::quoteIdentifier($table['TABLE_NAME']) . " engine=InnoDB;";
|
||||
echo $sql . "\n";
|
||||
|
||||
$result = DBA::e($sql);
|
||||
|
@ -817,7 +820,7 @@ class DBStructure
|
|||
/**
|
||||
* Check if a table exists
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param string|array $table Table name
|
||||
*
|
||||
* @return boolean Does the table exist?
|
||||
* @throws Exception
|
||||
|
@ -828,21 +831,15 @@ class DBStructure
|
|||
return false;
|
||||
}
|
||||
|
||||
$table = DBA::escape($table);
|
||||
|
||||
$sql = "SHOW TABLES LIKE '" . $table . "';";
|
||||
|
||||
$stmt = DBA::p($sql);
|
||||
|
||||
if (is_bool($stmt)) {
|
||||
$retval = $stmt;
|
||||
if (is_array($table)) {
|
||||
$condition = ['table_schema' => key($table), 'table_name' => current($table)];
|
||||
} else {
|
||||
$retval = (DBA::numRows($stmt) > 0);
|
||||
$condition = ['table_schema' => DBA::databaseName(), 'table_name' => $table];
|
||||
}
|
||||
|
||||
DBA::close($stmt);
|
||||
$result = DBA::exists(['information_schema' => 'tables'], $condition);
|
||||
|
||||
return $retval;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue