Skip to content

Commit

Permalink
[fix] Fix query table quotation for TABLE IF EXISTS #1036
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelaon committed May 4, 2022
1 parent 65042af commit 00ea59d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ protected function buildRaw($raw, array &$map): ?string
}

$query = preg_replace_callback(
'/(([`\']).*?)?((FROM|TABLE|INTO|UPDATE|JOIN)\s*)?\<(([\p{L}_][\p{L}\p{N}@$#\-_]*)(\.[\p{L}_][\p{L}\p{N}@$#\-_]*)?)\>([^,]*?\2)?/u',
'/(([`\']).*?)?((FROM|TABLE|INTO|UPDATE|JOIN|TABLE IF EXISTS)\s*)?\<(([\p{L}_][\p{L}\p{N}@$#\-_]*)(\.[\p{L}_][\p{L}\p{N}@$#\-_]*)?)\>([^,]*?\2)?/u',
function ($matches) {
if (!empty($matches[2]) && isset($matches[8])) {
return $matches[0];
Expand Down
24 changes: 24 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ public function testQueryWithPrefix()
);
}

/**
* @covers ::query()
* @covers ::isRaw()
* @covers ::buildRaw()
*/
public function testQueryTableWithPrefix()
{
$database = new Medoo([
'testMode' => true,
'prefix' => 'PREFIX_'
]);

$database->type = "sqlite";

$database->query("DROP TABLE IF EXISTS <account>");

$this->assertQuery(
<<<EOD
DROP TABLE IF EXISTS "PREFIX_account"
EOD,
$database->queryString
);
}

/**
* @covers ::query()
* @covers ::isRaw()
Expand Down

0 comments on commit 00ea59d

Please sign in to comment.