Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMESTAMPDIFF: Do not escape unit param (test case) #84

Draft
wants to merge 1 commit into
base: 1.5
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
TIMESTAMPDIFF: Do not escape unit param (test case)
This may also affect TIMESTAMPADD and such functions.
homersimpsons committed Oct 11, 2021
commit aea2a767ed8f0d8fa26a9e369064ace5d0de1715
17 changes: 15 additions & 2 deletions tests/Mouf/Database/MagicQueryTest.php
Original file line number Diff line number Diff line change
@@ -411,11 +411,13 @@ public function testTwig()
/**
* Removes all artifacts.
*/
private static function simplifySql($sql)
private static function simplifySql($sql, bool $stripBacktick = true)
{
$sql = str_replace("\n", ' ', $sql);
$sql = str_replace("\t", ' ', $sql);
$sql = str_replace('`', '', $sql);
if ($stripBacktick) {
$sql = str_replace('`', '', $sql);
}
$sql = str_replace(' ', ' ', $sql);
$sql = str_replace(' ', ' ', $sql);
$sql = str_replace(' ', ' ', $sql);
@@ -478,4 +480,15 @@ public function testPrepareStatementCache(): void
$this->assertEquals('SELECT * FROM users WHERE 0 <> 0', self::simplifySql($magicQuery->buildPreparedStatement('SELECT * FROM users WHERE id IN :users', ['users' => []])));
$this->assertEquals('SELECT * FROM users WHERE id IN (:users)', self::simplifySql($magicQuery->buildPreparedStatement('SELECT * FROM users WHERE id IN :users', ['users' => [1]])));
}

public function testBacktick(): void
{
$magicQuery = new MagicQuery(null, new ArrayCache());

$sql = "SELECT TIMESTAMPDIFF(SQL_TSI_SECOND, created_at, ended_at) FROM dual";
$this->assertEquals("SELECT TIMESTAMPDIFF(SQL_TSI_SECOND , `created_at`, `ended_at`) FROM `dual`", self::simplifySql($magicQuery->build($sql), false));

$sql = "SELECT TIMESTAMPDIFF(SECOND, created_at, ended_at) FROM dual";
$this->assertEquals("SELECT TIMESTAMPDIFF(SECOND , `created_at`, `ended_at`) FROM `dual`", self::simplifySql($magicQuery->build($sql), false));
}
}