Skip to content

Commit df680bc

Browse files
authoredJun 26, 2023
Merge pull request #69 from kmtbase/bugfix/escape-db-name
escape database name to avoid syntax error
2 parents 4a3349b + 8805a2d commit df680bc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
 

‎src/Oxrun/Command/Database/DumpCommand.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
129129
$dbName = Registry::getConfig()->getConfigParam('dbName');
130130

131131
if($input->getOption('ignoreViews')) {
132-
$viewsResultArray = \oxDb::getDb()->getAll("SHOW FULL TABLES IN {$dbName} WHERE TABLE_TYPE LIKE 'VIEW'");
132+
$viewsResultArray = \oxDb::getDb()->getAll("SHOW FULL TABLES IN `{$dbName}` WHERE TABLE_TYPE LIKE 'VIEW'");
133133
if (is_array($viewsResultArray)) {
134134
foreach ($viewsResultArray as $sqlRow) {
135135
$ignoreTables[] = $sqlRow[0];
@@ -303,17 +303,17 @@ protected function filterValidTables($tables)
303303
}
304304

305305
$whereIN = implode("', '", $whereIN);
306-
$conditionsIN = "Tables_in_{$dbName} IN ('{$whereIN}')";
306+
$conditionsIN = "`Tables_in_{$dbName}` IN ('{$whereIN}')";
307307

308308
$conditionsLIKE = '';
309309
if (!empty($whereLIKE)) {
310-
$template = " OR Tables_in_{$dbName} LIKE ('%s')";
310+
$template = " OR `Tables_in_{$dbName}` LIKE ('%s')";
311311
foreach ($whereLIKE as $tablename) {
312312
$conditionsLIKE .= sprintf($template, $tablename);
313313
}
314314
}
315315

316-
$sqlstament = "SHOW FULL TABLES IN {$dbName} WHERE $conditionsIN $conditionsLIKE";
316+
$sqlstament = "SHOW FULL TABLES IN `{$dbName}` WHERE $conditionsIN $conditionsLIKE";
317317

318318
$result = \oxDb::getDb()->getAll($sqlstament);
319319

‎src/Oxrun/Command/Database/ListCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ protected function filterValidTables($tables)
9999
}
100100

101101
$whereIN = implode("', '", $whereIN);
102-
$conditionsIN = "Tables_in_{$dbName} IN ('{$whereIN}')";
102+
$conditionsIN = "`Tables_in_{$dbName}` IN ('{$whereIN}')";
103103

104104
$conditionsLIKE = '';
105105
if (!empty($whereLIKE)) {
106-
$template = " OR Tables_in_{$dbName} LIKE ('%s')";
106+
$template = " OR `Tables_in_{$dbName}` LIKE ('%s')";
107107
foreach ($whereLIKE as $tablename) {
108108
$conditionsLIKE .= sprintf($template, $tablename);
109109
}
110110
}
111111

112-
$sqlstament = "SHOW FULL TABLES IN {$dbName} WHERE $conditionsIN $conditionsLIKE";
112+
$sqlstament = "SHOW FULL TABLES IN `{$dbName}` WHERE $conditionsIN $conditionsLIKE";
113113

114114
$existsTable = DatabaseProvider::getDb()->getAll($sqlstament);
115115

0 commit comments

Comments
 (0)
Please sign in to comment.