Skip to content

Commit 3834b23

Browse files
author
Marc Vachette
committed
solve#368 add CURRENT_TIMESTAMP to the list of SQL functions
1 parent d23f70d commit 3834b23

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/PHPSQLParser/utils/PHPSQLParserConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class PHPSQLParserConstants {
149149
'TAN', 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF',
150150
'TIME_FORMAT', 'TIME_TO_SEC', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE', 'UNCOMPRESS',
151151
'UNCOMPRESSED_LENGTH', 'UNHEX', 'UNIX_TIMESTAMP', 'UPPER', 'USER', 'UTC_DATE',
152-
'UTC_TIME', 'UTC_TIMESTAMP', 'UUID', 'VAR_POP', 'VAR_SAMP', 'VARIANCE', 'VERSION',
152+
'UTC_TIME', 'CURRENT_TIMESTAMP', 'UTC_TIMESTAMP', 'UUID', 'VAR_POP', 'VAR_SAMP', 'VARIANCE', 'VERSION',
153153
'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR', 'YEARWEEK');
154154

155155
protected $aggregateFunctions = array('AVG', 'SUM', 'COUNT', 'MIN', 'MAX', 'STD', 'STDDEV', 'STDDEV_SAMP',

tests/cases/creator/issue368Test.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* issue368.php
4+
*
5+
* Test case for PHPSQLCreator.
6+
*/
7+
8+
namespace PHPSQLParser\Test\Creator;
9+
10+
use PHPSQLParser\PHPSQLParser;
11+
use PHPSQLParser\PHPSQLCreator;
12+
13+
class Issue368Test extends \PHPUnit\Framework\TestCase
14+
{
15+
/*
16+
* https://github.com/greenlion/PHP-SQL-Parser/issues/368
17+
* CURRENT_TIMESTAMP is detected as a reserved word an generate errors when used in JOIN clause
18+
*/
19+
public function testIssue368()
20+
{
21+
$sql = "SELECT foo FROM barTable LEFT JOIN bazTable ON barTable.a = bazTable.a AND bazTable.d <= CURRENT_TIMESTAMP"; // KO
22+
23+
$parser = new PHPSQLParser();
24+
$creator = new PHPSQLCreator();
25+
26+
$parser->parse($sql);
27+
28+
$this->assertEquals($sql, $creator->create($parser->parsed));
29+
}
30+
}

0 commit comments

Comments
 (0)