Skip to content

Commit

Permalink
Merge pull request #69 from kmtbase/bugfix/escape-db-name
Browse files Browse the repository at this point in the history
escape database name to avoid syntax error
  • Loading branch information
smxsm authored Jun 26, 2023
2 parents 4a3349b + 8805a2d commit df680bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Oxrun/Command/Database/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dbName = Registry::getConfig()->getConfigParam('dbName');

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

$whereIN = implode("', '", $whereIN);
$conditionsIN = "Tables_in_{$dbName} IN ('{$whereIN}')";
$conditionsIN = "`Tables_in_{$dbName}` IN ('{$whereIN}')";

$conditionsLIKE = '';
if (!empty($whereLIKE)) {
$template = " OR Tables_in_{$dbName} LIKE ('%s')";
$template = " OR `Tables_in_{$dbName}` LIKE ('%s')";
foreach ($whereLIKE as $tablename) {
$conditionsLIKE .= sprintf($template, $tablename);
}
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/Oxrun/Command/Database/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ protected function filterValidTables($tables)
}

$whereIN = implode("', '", $whereIN);
$conditionsIN = "Tables_in_{$dbName} IN ('{$whereIN}')";
$conditionsIN = "`Tables_in_{$dbName}` IN ('{$whereIN}')";

$conditionsLIKE = '';
if (!empty($whereLIKE)) {
$template = " OR Tables_in_{$dbName} LIKE ('%s')";
$template = " OR `Tables_in_{$dbName}` LIKE ('%s')";
foreach ($whereLIKE as $tablename) {
$conditionsLIKE .= sprintf($template, $tablename);
}
}

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

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

Expand Down

0 comments on commit df680bc

Please sign in to comment.