├── LICENSE ├── README.md ├── composer.json ├── config ├── mysql.yml ├── oracle.yml ├── postgres.yml └── sqlite.yml └── src ├── Query ├── Mysql │ ├── Acos.php │ ├── AddTime.php │ ├── AesDecrypt.php │ ├── AesEncrypt.php │ ├── AnyValue.php │ ├── Ascii.php │ ├── Asin.php │ ├── Atan.php │ ├── Atan2.php │ ├── Binary.php │ ├── BitCount.php │ ├── BitXor.php │ ├── Cast.php │ ├── Ceil.php │ ├── CharLength.php │ ├── Collate.php │ ├── ConcatWs.php │ ├── ConvertTz.php │ ├── Cos.php │ ├── Cot.php │ ├── CountIf.php │ ├── Crc32.php │ ├── Date.php │ ├── DateAdd.php │ ├── DateDiff.php │ ├── DateFormat.php │ ├── DateSub.php │ ├── Day.php │ ├── DayName.php │ ├── DayOfWeek.php │ ├── DayOfYear.php │ ├── Degrees.php │ ├── Div.php │ ├── Exp.php │ ├── Extract.php │ ├── Field.php │ ├── FindInSet.php │ ├── Floor.php │ ├── Format.php │ ├── FromBase64.php │ ├── FromUnixtime.php │ ├── Greatest.php │ ├── GroupConcat.php │ ├── Hex.php │ ├── Hour.php │ ├── IfElse.php │ ├── IfNull.php │ ├── Inet6Aton.php │ ├── Inet6Ntoa.php │ ├── InetAton.php │ ├── InetNtoa.php │ ├── Instr.php │ ├── IsIpv4.php │ ├── IsIpv4Compat.php │ ├── IsIpv4Mapped.php │ ├── IsIpv6.php │ ├── JsonContains.php │ ├── JsonDepth.php │ ├── JsonLength.php │ ├── Lag.php │ ├── LastDay.php │ ├── Lead.php │ ├── Least.php │ ├── Log.php │ ├── Log10.php │ ├── Log2.php │ ├── Lpad.php │ ├── MakeDate.php │ ├── MatchAgainst.php │ ├── Md5.php │ ├── Minute.php │ ├── Month.php │ ├── MonthName.php │ ├── Now.php │ ├── NullIf.php │ ├── Over.php │ ├── PeriodDiff.php │ ├── Pi.php │ ├── Power.php │ ├── Quarter.php │ ├── Radians.php │ ├── Rand.php │ ├── Regexp.php │ ├── Replace.php │ ├── Round.php │ ├── Rpad.php │ ├── SecToTime.php │ ├── Second.php │ ├── Sha1.php │ ├── Sha2.php │ ├── Sin.php │ ├── Soundex.php │ ├── Std.php │ ├── StdDev.php │ ├── StrToDate.php │ ├── SubstringIndex.php │ ├── Tan.php │ ├── Time.php │ ├── TimeDiff.php │ ├── TimeToSec.php │ ├── TimestampAdd.php │ ├── TimestampDiff.php │ ├── Truncate.php │ ├── Unhex.php │ ├── UnixTimestamp.php │ ├── UtcTimestamp.php │ ├── UuidShort.php │ ├── Variance.php │ ├── Week.php │ ├── WeekDay.php │ ├── WeekOfYear.php │ ├── Year.php │ ├── YearMonth.php │ └── YearWeek.php ├── MysqlWalker.php ├── Oracle │ ├── Ceil.php │ ├── Day.php │ ├── Floor.php │ ├── Hour.php │ ├── Listagg.php │ ├── Minute.php │ ├── Month.php │ ├── Nvl.php │ ├── Second.php │ ├── ToChar.php │ ├── ToDate.php │ ├── Trunc.php │ └── Year.php ├── Postgresql │ ├── AtTimeZoneFunction.php │ ├── CountFilterFunction.php │ ├── Date.php │ ├── DateFormat.php │ ├── DatePart.php │ ├── DateTrunc.php │ ├── Day.php │ ├── ExtractFunction.php │ ├── Greatest.php │ ├── Hour.php │ ├── Least.php │ ├── Minute.php │ ├── Month.php │ ├── RegexpReplace.php │ ├── Second.php │ ├── StrToDate.php │ ├── StringAgg.php │ └── Year.php ├── SortableNullsWalker.php └── Sqlite │ ├── AbstractStrfTime.php │ ├── ConcatWs.php │ ├── Date.php │ ├── DateFormat.php │ ├── Day.php │ ├── Greatest.php │ ├── Hour.php │ ├── IfElse.php │ ├── IfNull.php │ ├── JulianDay.php │ ├── Least.php │ ├── Minute.php │ ├── Month.php │ ├── NumberFromStrfTime.php │ ├── Random.php │ ├── Replace.php │ ├── Round.php │ ├── Second.php │ ├── StrfTime.php │ ├── Week.php │ ├── WeekDay.php │ └── Year.php └── Types ├── CarbonDateTimeType.php ├── CarbonDateTimeTzType.php ├── CarbonDateType.php ├── CarbonImmutableDateTimeType.php ├── CarbonImmutableDateTimeTzType.php ├── CarbonImmutableDateType.php ├── CarbonImmutableTimeType.php ├── CarbonImmutableTypeImplementation.php ├── CarbonTimeType.php ├── CarbonTypeImplementation.php ├── PolygonType.php └── ZendDateType.php /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2020, Benjamin Eberlei and individual 2 | contributors. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of DoctrineExtensions nor the names of its contributors may be used 16 | to endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "beberlei/doctrineextensions", 3 | "type": "library", 4 | "description": "A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL, Oracle, PostgreSQL and SQLite.", 5 | "keywords": ["doctrine", "orm", "database"], 6 | "license": "BSD-3-Clause", 7 | "authors": [ 8 | {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"}, 9 | {"name": "Steve Lacey", "email": "steve@steve.ly"} 10 | ], 11 | "require": { 12 | "php": "^7.2 || ^8.0", 13 | "doctrine/orm": "^2.19 || ^3.0" 14 | }, 15 | "require-dev": { 16 | "doctrine/annotations": "^1.14 || ^2", 17 | "doctrine/coding-standard": "^9.0.2 || ^12.0", 18 | "nesbot/carbon": "^2.72 || ^3", 19 | "phpstan/phpstan": "^1.10", 20 | "phpunit/phpunit": "^8.5 || ^9.6", 21 | "squizlabs/php_codesniffer": "^3.8", 22 | "symfony/cache": "^5.4 || ^6.4 || ^7.0", 23 | "symfony/yaml": "^5.4 || ^6.4 || ^7.0", 24 | "vimeo/psalm": "^3.18 || ^5.22", 25 | "zf1/zend-date": "^1.12", 26 | "zf1/zend-registry": "^1.12" 27 | }, 28 | "autoload": { 29 | "psr-4": {"DoctrineExtensions\\" : "src/"} 30 | }, 31 | "autoload-dev": { 32 | "psr-4": {"DoctrineExtensions\\Tests\\": "tests/"} 33 | }, 34 | "config": { 35 | "sort-packages": true, 36 | "allow-plugins": { 37 | "dealerdirect/phpcodesniffer-composer-installer": true 38 | } 39 | }, 40 | "scripts": { 41 | "test": "phpunit --colors=always" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /config/oracle.yml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | orm: 3 | dql: 4 | datetime_functions: 5 | second: DoctrineExtensions\Query\Oracle\Second 6 | minute: DoctrineExtensions\Query\Oracle\Minute 7 | hour: DoctrineExtensions\Query\Oracle\Hour 8 | day: DoctrineExtensions\Query\Oracle\Day 9 | month: DoctrineExtensions\Query\Oracle\Month 10 | year: DoctrineExtensions\Query\Oracle\Year 11 | to_char: DoctrineExtensions\Query\Oracle\ToChar 12 | trunc: DoctrineExtensions\Query\Oracle\Trunc 13 | 14 | string_functions: 15 | nvl: DoctrineExtensions\Query\Oracle\Nvl 16 | listagg: DoctrineExtensions\Query\Oracle\Listagg 17 | to_date: DoctrineExtensions\Query\Oracle\ToDate 18 | 19 | numeric_functions: 20 | ceil: DoctrineExtensions\Query\Oracle\Ceil 21 | floor: DoctrineExtensions\Query\Oracle\Floor 22 | -------------------------------------------------------------------------------- /config/postgres.yml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | orm: 3 | dql: 4 | datetime_functions: 5 | second: DoctrineExtensions\Query\Postgresql\Second 6 | minute: DoctrineExtensions\Query\Postgresql\Minute 7 | hour: DoctrineExtensions\Query\Postgresql\Hour 8 | day: DoctrineExtensions\Query\Postgresql\Day 9 | month: DoctrineExtensions\Query\Postgresql\Month 10 | year: DoctrineExtensions\Query\Postgresql\Year 11 | date_format: DoctrineExtensions\Query\Postgresql\DateFormat 12 | at_time_zone: DoctrineExtensions\Query\Postgresql\AtTimeZoneFunction 13 | date_part: DoctrineExtensions\Query\Postgresql\DatePart 14 | extract: DoctrineExtensions\Query\Postgresql\ExtractFunction 15 | date_trunc: DoctrineExtensions\Query\Postgresql\DateTrunc 16 | date: DoctrineExtensions\Query\Postgresql\Date 17 | 18 | string_functions: 19 | str_to_date: DoctrineExtensions\Query\Postgresql\StrToDate 20 | count_filter: DoctrineExtensions\Query\Postgresql\CountFilterFunction 21 | string_agg: DoctrineExtensions\Query\Postgresql\StringAgg 22 | greatest: DoctrineExtensions\Query\Postgresql\Greatest 23 | least: DoctrineExtensions\Query\Postgresql\Least 24 | regexp_replace: DoctrineExtensions\Query\Postgresql\RegexpReplace 25 | -------------------------------------------------------------------------------- /config/sqlite.yml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | orm: 3 | dql: 4 | datetime_functions: 5 | second: DoctrineExtensions\Query\Sqlite\Second 6 | minute: DoctrineExtensions\Query\Sqlite\Minute 7 | hour: DoctrineExtensions\Query\Sqlite\Hour 8 | day: DoctrineExtensions\Query\Sqlite\Day 9 | dayname: DoctrineExtensions\Query\Sqlite\DayName 10 | #monthname: DoctrineExtensions\Query\Sqlite\MonthName 11 | month: DoctrineExtensions\Query\Sqlite\Month 12 | week: DoctrineExtensions\Query\Sqlite\Week 13 | weekday: DoctrineExtensions\Query\Sqlite\WeekDay 14 | year: DoctrineExtensions\Query\Sqlite\Year 15 | date: DoctrineExtensions\Query\Sqlite\Date 16 | date_format: DoctrineExtensions\Query\Sqlite\DateFormat 17 | #dateadd: DoctrineExtensions\Query\Sqlite\DateAdd 18 | #datediff: DoctrineExtensions\Query\Sqlite\DateDiff 19 | julianday: DoctrineExtensions\Query\Sqlite\JulianDay 20 | strftime: DoctrineExtensions\Query\Sqlite\StrfTime 21 | #strtodate: DoctrineExtensions\Query\Sqlite\StrToDate 22 | #time: DoctrineExtensions\Query\Sqlite\Time 23 | #timestampadd: DoctrineExtensions\Query\Sqlite\TimestampAdd 24 | #timestampdiff: DoctrineExtensions\Query\Sqlite\TimestampDiff 25 | 26 | string_functions: 27 | # binary: DoctrineExtensions\Query\Sqlite\Binary 28 | # char_length: DoctrineExtensions\Query\Sqlite\CharLength 29 | concat_ws: DoctrineExtensions\Query\Sqlite\ConcatWs 30 | # countif: DoctrineExtensions\Query\Sqlite\CountIf 31 | # crc32: DoctrineExtensions\Query\Sqlite\Crc32 32 | # degrees: DoctrineExtensions\Query\Sqlite\Degrees 33 | # field: DoctrineExtensions\Query\Sqlite\Field 34 | # find_in_set: DoctrineExtensions\Query\Sqlite\FindInSet 35 | # group_concat: DoctrineExtensions\Query\Sqlite\GroupConcat 36 | greatest: DoctrineExtensions\Query\Sqlite\Greatest 37 | ifelse: DoctrineExtensions\Query\Sqlite\IfElse 38 | ifnull: DoctrineExtensions\Query\Sqlite\IfNull 39 | least: DoctrineExtensions\Query\Sqlite\Least 40 | # match: DoctrineExtensions\Query\Sqlite\MatchAgainst 41 | # md5: DoctrineExtensions\Query\Sqlite\Md5 42 | # nullif: DoctrineExtensions\Query\Sqlite\NullIf 43 | # radians: DoctrineExtensions\Query\Sqlite\Radians 44 | random: DoctrineExtensions\Query\Sqlite\Random 45 | # regexp: DoctrineExtensions\Query\Sqlite\Regexp 46 | replace: DoctrineExtensions\Query\Sqlite\Replace 47 | # sha1: DoctrineExtensions\Query\Sqlite\Sha1 48 | # sha2: DoctrineExtensions\Query\Sqlite\Sha2 49 | # soundex: DoctrineExtensions\Query\Sqlite\Soundex 50 | # uuid_short: DoctrineExtensions\Query\Sqlite\UuidShort 51 | 52 | numeric_functions: 53 | round: DoctrineExtensions\Query\Sqlite\Round 54 | -------------------------------------------------------------------------------- /src/Query/Mysql/Acos.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/AddTime.php: -------------------------------------------------------------------------------- 1 | */ 11 | class AddTime extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public $time; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return 'ADDTIME(' . $sqlWalker->walkArithmeticPrimary($this->date) . ', ' . $sqlWalker->walkArithmeticPrimary($this->time) . ')'; 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->date = $parser->ArithmeticPrimary(); 28 | 29 | $parser->match(TokenType::T_COMMA); 30 | 31 | $this->time = $parser->ArithmeticPrimary(); 32 | 33 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/AesDecrypt.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->field = $parser->StringExpression(); 23 | $parser->match(TokenType::T_COMMA); 24 | $this->key = $parser->StringExpression(); 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf( 31 | 'AES_DECRYPT(%s, %s)', 32 | $this->field->dispatch($sqlWalker), 33 | $this->key->dispatch($sqlWalker) 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Query/Mysql/AesEncrypt.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->field = $parser->StringExpression(); 23 | $parser->match(TokenType::T_COMMA); 24 | $this->key = $parser->StringExpression(); 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf( 31 | 'AES_ENCRYPT(%s, %s)', 32 | $this->field->dispatch($sqlWalker), 33 | $this->key->dispatch($sqlWalker) 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Query/Mysql/AnyValue.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->value = $parser->StringPrimary(); 21 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 22 | } 23 | 24 | public function getSql(SqlWalker $sqlWalker): string 25 | { 26 | return sprintf( 27 | 'ANY_VALUE(%s)', 28 | $this->value->dispatch($sqlWalker) 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/Ascii.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->string) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->string = $parser->ArithmeticExpression(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Asin.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Atan.php: -------------------------------------------------------------------------------- 1 | optionalSecondExpression) { 22 | $secondArgument = $sqlWalker->walkSimpleArithmeticExpression( 23 | $this->optionalSecondExpression 24 | ); 25 | } 26 | 27 | return 'ATAN(' . $sqlWalker->walkSimpleArithmeticExpression( 28 | $this->arithmeticExpression 29 | ) . ($secondArgument ? ', ' . $secondArgument : '') 30 | . ')'; 31 | } 32 | 33 | public function parse(Parser $parser): void 34 | { 35 | $parser->match(TokenType::T_IDENTIFIER); 36 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 37 | 38 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 39 | 40 | try { 41 | $parser->match(TokenType::T_COMMA); 42 | 43 | $this->optionalSecondExpression = $parser->SimpleArithmeticExpression(); 44 | 45 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 46 | } catch (QueryException $e) { 47 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Query/Mysql/Atan2.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 19 | $this->firstExpression 20 | ); 21 | 22 | $secondArgument = $sqlWalker->walkSimpleArithmeticExpression( 23 | $this->secondExpression 24 | ); 25 | 26 | return 'ATAN2(' . $firstArgument . ', ' . $secondArgument . ')'; 27 | } 28 | 29 | public function parse(Parser $parser): void 30 | { 31 | $parser->match(TokenType::T_IDENTIFIER); 32 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 33 | 34 | $this->firstExpression = $parser->SimpleArithmeticExpression(); 35 | 36 | $parser->match(TokenType::T_COMMA); 37 | 38 | $this->secondExpression = $parser->SimpleArithmeticExpression(); 39 | 40 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Query/Mysql/Binary.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Binary extends FunctionNode 12 | { 13 | private $stringPrimary; 14 | 15 | public function parse(Parser $parser): void 16 | { 17 | $parser->match(TokenType::T_IDENTIFIER); 18 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 19 | 20 | $this->stringPrimary = $parser->StringPrimary(); 21 | 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'BINARY(' . $sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary) . ')'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/BitCount.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) 19 | . ')'; 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/BitXor.php: -------------------------------------------------------------------------------- 1 | firstArithmetic->dispatch($sqlWalker) 22 | . ' ^ ' 23 | . $this->secondArithmetic->dispatch($sqlWalker); 24 | } 25 | 26 | public function parse(Parser $parser): void 27 | { 28 | $parser->match(TokenType::T_IDENTIFIER); 29 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 30 | 31 | $this->firstArithmetic = $parser->ArithmeticPrimary(); 32 | $parser->match(TokenType::T_COMMA); 33 | $this->secondArithmetic = $parser->ArithmeticPrimary(); 34 | 35 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Mysql/Cast.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 36 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 37 | 38 | $this->fieldIdentifierExpression = $parser->SimpleArithmeticExpression(); 39 | 40 | $parser->match(TokenType::T_AS); 41 | $parser->match(TokenType::T_IDENTIFIER); 42 | 43 | $type = $parser->getLexer()->token->value; 44 | 45 | if ($parser->getLexer()->isNextToken(TokenType::T_OPEN_PARENTHESIS)) { 46 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 47 | $parameter = $parser->Literal(); 48 | assert($parameter instanceof Literal); 49 | $parameters = [$parameter->value]; 50 | 51 | if ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { 52 | while ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { 53 | $parser->match(TokenType::T_COMMA); 54 | $parameter = $parser->Literal(); 55 | $parameters[] = $parameter->value; 56 | } 57 | } 58 | 59 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 60 | $type .= '(' . implode(', ', $parameters) . ')'; 61 | } 62 | 63 | $this->castingTypeExpression = $type; 64 | 65 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 66 | } 67 | 68 | public function getSql(SqlWalker $sqlWalker): string 69 | { 70 | return sprintf( 71 | 'CAST(%s AS %s)', 72 | $sqlWalker->walkSimpleArithmeticExpression($this->fieldIdentifierExpression), 73 | $this->castingTypeExpression 74 | ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Query/Mysql/Ceil.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression($this->arithmeticExpression) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/CharLength.php: -------------------------------------------------------------------------------- 1 | */ 11 | class CharLength extends FunctionNode 12 | { 13 | private $expr1; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'CHAR_LENGTH(' . $sqlWalker->walkArithmeticPrimary($this->expr1) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->expr1 = $parser->ArithmeticExpression(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Collate.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | class Collate extends FunctionNode 19 | { 20 | /** @var Node|null */ 21 | public $stringPrimary = null; 22 | 23 | /** @var string|null */ 24 | public $collation = null; 25 | 26 | public function parse(Parser $parser): void 27 | { 28 | $parser->match(TokenType::T_IDENTIFIER); 29 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 30 | 31 | $this->stringPrimary = $parser->StringPrimary(); 32 | 33 | $parser->match(TokenType::T_COMMA); 34 | $parser->match(TokenType::T_IDENTIFIER); 35 | 36 | $lexer = $parser->getLexer(); 37 | 38 | $this->collation = $lexer->token->value; 39 | 40 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 41 | } 42 | 43 | public function getSql(SqlWalker $sqlWalker): string 44 | { 45 | return sprintf('%s COLLATE %s', $sqlWalker->walkStringPrimary($this->stringPrimary), $this->collation); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Query/Mysql/ConcatWs.php: -------------------------------------------------------------------------------- 1 | */ 16 | class ConcatWs extends FunctionNode 17 | { 18 | private $values = []; 19 | 20 | private $notEmpty = false; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | // Add the concat separator to the values array. 28 | $this->values[] = $parser->ArithmeticExpression(); 29 | 30 | // Add the rest of the strings to the values array. CONCAT_WS must 31 | // be used with at least 2 strings not including the separator. 32 | 33 | $lexer = $parser->getLexer(); 34 | 35 | while (count($this->values) < 3 || $lexer->lookahead->type === TokenType::T_COMMA) { 36 | $parser->match(TokenType::T_COMMA); 37 | $peek = $lexer->glimpse(); 38 | 39 | $this->values[] = $peek->value === '(' 40 | ? $parser->FunctionDeclaration() 41 | : $parser->ArithmeticExpression(); 42 | } 43 | 44 | while ($lexer->lookahead->type === TokenType::T_IDENTIFIER) { 45 | switch (strtolower($lexer->lookahead->value)) { 46 | case 'notempty': 47 | $parser->match(TokenType::T_IDENTIFIER); 48 | $this->notEmpty = true; 49 | 50 | break; 51 | default: // Identifier not recognized (causes exception). 52 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 53 | 54 | break; 55 | } 56 | } 57 | 58 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 59 | } 60 | 61 | public function getSql(SqlWalker $sqlWalker): string 62 | { 63 | // Create an array to hold the query elements. 64 | $queryBuilder = ['CONCAT_WS(']; 65 | 66 | // Iterate over the captured expressions and add them to the query. 67 | for ($i = 0; $i < count($this->values); $i++) { 68 | if ($i > 0) { 69 | $queryBuilder[] = ', '; 70 | } 71 | 72 | // Dispatch the walker on the current node. 73 | $nodeSql = $sqlWalker->walkArithmeticPrimary($this->values[$i]); 74 | 75 | if ($this->notEmpty) { 76 | // Exclude empty strings from the concatenation. 77 | $nodeSql = sprintf("NULLIF(%s, '')", $nodeSql); 78 | } 79 | 80 | $queryBuilder[] = $nodeSql; 81 | } 82 | 83 | // Close the query. 84 | $queryBuilder[] = ')'; 85 | 86 | // Return the joined query. 87 | return implode('', $queryBuilder); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Query/Mysql/ConvertTz.php: -------------------------------------------------------------------------------- 1 | walkArithmeticExpression($this->dateExpression), 26 | $sqlWalker->walkStringPrimary($this->fromTz), 27 | $sqlWalker->walkStringPrimary($this->toTz) 28 | ); 29 | } 30 | 31 | public function parse(Parser $parser): void 32 | { 33 | $parser->match(TokenType::T_IDENTIFIER); 34 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 35 | 36 | $this->dateExpression = $parser->ArithmeticExpression(); 37 | $parser->match(TokenType::T_COMMA); 38 | 39 | $this->fromTz = $parser->StringPrimary(); 40 | $parser->match(TokenType::T_COMMA); 41 | 42 | $this->toTz = $parser->StringPrimary(); 43 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Query/Mysql/Cos.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Cot.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/CountIf.php: -------------------------------------------------------------------------------- 1 | */ 14 | class CountIf extends FunctionNode 15 | { 16 | private $expr1; 17 | 18 | private $expr2; 19 | 20 | private $inverse = false; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | $this->expr1 = $parser->ArithmeticExpression(); 27 | $parser->match(TokenType::T_COMMA); 28 | $this->expr2 = $parser->ArithmeticExpression(); 29 | 30 | $lexer = $parser->getLexer(); 31 | 32 | while ($lexer->lookahead->type === TokenType::T_IDENTIFIER) { 33 | switch (strtolower($lexer->lookahead->value)) { 34 | case 'inverse': 35 | $parser->match(TokenType::T_IDENTIFIER); 36 | $this->inverse = true; 37 | 38 | break; 39 | default: // Identifier not recognized (causes exception). 40 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 41 | 42 | break; 43 | } 44 | } 45 | 46 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 47 | } 48 | 49 | public function getSql(SqlWalker $sqlWalker): string 50 | { 51 | return sprintf( 52 | 'COUNT(CASE %s WHEN %s THEN %s END)', 53 | $sqlWalker->walkArithmeticPrimary($this->expr1), 54 | $sqlWalker->walkArithmeticPrimary($this->expr2), 55 | ! $this->inverse ? '1 ELSE NULL' : 'NULL ELSE 1' 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Query/Mysql/Crc32.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Crc32 extends FunctionNode 12 | { 13 | public $stringPrimary; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'CRC32(' . 18 | $sqlWalker->walkStringPrimary($this->stringPrimary) . 19 | ')'; 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->stringPrimary = $parser->StringPrimary(); 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/Date.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Date extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'DATE(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/DateAdd.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 49 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 50 | 51 | $this->firstDateExpression = $parser->ArithmeticFactor(); 52 | 53 | $parser->match(TokenType::T_COMMA); 54 | $this->intervalExpression = $parser->ArithmeticFactor(); 55 | 56 | $parser->match(TokenType::T_COMMA); 57 | $this->unit = $parser->StringPrimary(); 58 | 59 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 60 | } 61 | 62 | public function getSql(SqlWalker $sqlWalker): string 63 | { 64 | $unit = strtoupper(is_string($this->unit) ? $this->unit : $this->unit->value); 65 | 66 | if (! in_array($unit, self::$allowedUnits)) { 67 | throw QueryException::semanticalError('DATE_ADD() does not support unit "' . $unit . '".'); 68 | } 69 | 70 | return 'DATE_ADD(' . 71 | $sqlWalker->walkArithmeticTerm($this->firstDateExpression) . ', INTERVAL ' . 72 | $sqlWalker->walkArithmeticTerm($this->intervalExpression) . ' ' . $unit . 73 | ')'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Query/Mysql/DateDiff.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->firstDateExpression = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->secondDateExpression = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'DATEDIFF(' . 29 | $sqlWalker->walkArithmeticTerm($this->firstDateExpression) . ', ' . 30 | $sqlWalker->walkArithmeticTerm($this->secondDateExpression) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/DateFormat.php: -------------------------------------------------------------------------------- 1 | */ 11 | class DateFormat extends FunctionNode 12 | { 13 | public $dateExpression = null; 14 | 15 | public $patternExpression = null; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->dateExpression = $parser->ArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->patternExpression = $parser->StringPrimary(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'DATE_FORMAT(' . 30 | $this->dateExpression->dispatch($sqlWalker) . ', ' . 31 | $this->patternExpression->dispatch($sqlWalker) . 32 | ')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Mysql/DateSub.php: -------------------------------------------------------------------------------- 1 | */ 13 | class DateSub extends DateAdd 14 | { 15 | /** @throws QueryException */ 16 | public function getSql(SqlWalker $sqlWalker): string 17 | { 18 | $unit = strtoupper(is_string($this->unit) ? $this->unit : $this->unit->value); 19 | 20 | if (! in_array($unit, self::$allowedUnits)) { 21 | throw QueryException::semanticalError('DATE_SUB() does not support unit "' . $unit . '".'); 22 | } 23 | 24 | return 'DATE_SUB(' . 25 | $this->firstDateExpression->dispatch($sqlWalker) . ', INTERVAL ' . 26 | $this->intervalExpression->dispatch($sqlWalker) . ' ' . $unit . 27 | ')'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Day.php: -------------------------------------------------------------------------------- 1 | 12 | * @author Sarjono Mukti Aji 13 | */ 14 | class Day extends FunctionNode 15 | { 16 | public $date; 17 | 18 | public function getSql(SqlWalker $sqlWalker): string 19 | { 20 | return 'DAY(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->date = $parser->ArithmeticPrimary(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/DayName.php: -------------------------------------------------------------------------------- 1 | */ 11 | class DayName extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'DAYNAME(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/DayOfWeek.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->date = $parser->ArithmeticPrimary(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/DayOfYear.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->date = $parser->ArithmeticPrimary(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Degrees.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 18 | $this->arithmeticExpression 19 | ) . 20 | ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/Div.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->dividend) . ' DIV ' . 23 | $sqlWalker->walkArithmeticPrimary($this->divisor); 24 | } 25 | 26 | public function parse(Parser $parser): void 27 | { 28 | $parser->match(TokenType::T_IDENTIFIER); 29 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 30 | 31 | $this->dividend = $parser->ArithmeticPrimary(); 32 | 33 | $parser->match(TokenType::T_COMMA); 34 | 35 | $this->divisor = $parser->ArithmeticPrimary(); 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Mysql/Exp.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Extract.php: -------------------------------------------------------------------------------- 1 | */ 14 | class Extract extends DateAdd 15 | { 16 | public $date = null; 17 | 18 | public $unit = null; 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $lexer = $parser->getLexer(); 27 | $this->unit = $lexer->token->value; 28 | 29 | $parser->match(TokenType::T_IDENTIFIER); 30 | $this->date = $parser->ArithmeticPrimary(); 31 | 32 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 33 | } 34 | 35 | public function getSql(SqlWalker $sqlWalker): string 36 | { 37 | $unit = strtoupper($this->unit); 38 | if (! in_array($unit, self::$allowedUnits)) { 39 | throw QueryException::semanticalError('EXTRACT() does not support unit "' . $unit . '".'); 40 | } 41 | 42 | return 'EXTRACT(' . $unit . ' FROM ' . $this->date->dispatch($sqlWalker) . ')'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Query/Mysql/Field.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Field extends FunctionNode 14 | { 15 | private $field = null; 16 | 17 | private $values = []; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | // Do the field. 25 | $this->field = $parser->ArithmeticPrimary(); 26 | 27 | // Add the strings to the values array. FIELD must 28 | // be used with at least 1 string not including the field. 29 | 30 | $lexer = $parser->getLexer(); 31 | 32 | while ( 33 | count($this->values) < 1 || 34 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 35 | ) { 36 | $parser->match(TokenType::T_COMMA); 37 | $this->values[] = $parser->ArithmeticPrimary(); 38 | } 39 | 40 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 41 | } 42 | 43 | public function getSql(SqlWalker $sqlWalker): string 44 | { 45 | $query = 'FIELD('; 46 | 47 | $query .= $this->field->dispatch($sqlWalker); 48 | 49 | $query .= ', '; 50 | 51 | for ($i = 0; $i < count($this->values); $i++) { 52 | if ($i > 0) { 53 | $query .= ', '; 54 | } 55 | 56 | $query .= $this->values[$i]->dispatch($sqlWalker); 57 | } 58 | 59 | $query .= ')'; 60 | 61 | return $query; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Query/Mysql/FindInSet.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->needle = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->haystack = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'FIND_IN_SET(' . 29 | $this->needle->dispatch($sqlWalker) . ', ' . 30 | $this->haystack->dispatch($sqlWalker) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/Floor.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression($this->arithmeticExpression) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Format.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Format extends FunctionNode 12 | { 13 | public $numberExpression = null; 14 | 15 | public $patternExpression = null; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->numberExpression = $parser->SimpleArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->patternExpression = $parser->SimpleArithmeticExpression(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'FORMAT(' . 30 | $this->numberExpression->dispatch($sqlWalker) . ', ' . 31 | $this->patternExpression->dispatch($sqlWalker) . 32 | ')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Mysql/FromBase64.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->field = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | 29 | public function getSql(SqlWalker $sqlWalker): string 30 | { 31 | return 'FROM_BASE64(' . $this->field->dispatch($sqlWalker) . ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/FromUnixtime.php: -------------------------------------------------------------------------------- 1 | */ 11 | class FromUnixtime extends FunctionNode 12 | { 13 | public $firstExpression = null; 14 | 15 | public $secondExpression = null; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | if ($this->secondExpression !== null) { 20 | return 'FROM_UNIXTIME(' 21 | . $this->firstExpression->dispatch($sqlWalker) 22 | . ',' 23 | . $this->secondExpression->dispatch($sqlWalker) 24 | . ')'; 25 | } 26 | 27 | return 'FROM_UNIXTIME(' . $this->firstExpression->dispatch($sqlWalker) . ')'; 28 | } 29 | 30 | public function parse(Parser $parser): void 31 | { 32 | $lexer = $parser->getLexer(); 33 | 34 | $parser->match(TokenType::T_IDENTIFIER); 35 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 36 | 37 | $this->firstExpression = $parser->ArithmeticPrimary(); 38 | 39 | // parse second parameter if available 40 | if ($lexer->lookahead->type === TokenType::T_COMMA) { 41 | $parser->match(TokenType::T_COMMA); 42 | $this->secondExpression = $parser->ArithmeticPrimary(); 43 | } 44 | 45 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Query/Mysql/Greatest.php: -------------------------------------------------------------------------------- 1 | 14 | * @author Guven Atbakan 15 | */ 16 | class Greatest extends FunctionNode 17 | { 18 | private $field = null; 19 | 20 | private $values = []; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | $this->field = $parser->ArithmeticExpression(); 27 | $lexer = $parser->getLexer(); 28 | 29 | while ( 30 | count($this->values) < 1 || 31 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 32 | ) { 33 | $parser->match(TokenType::T_COMMA); 34 | $this->values[] = $parser->ArithmeticExpression(); 35 | } 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | 40 | public function getSql(SqlWalker $sqlWalker): string 41 | { 42 | $query = 'GREATEST('; 43 | 44 | $query .= $this->field->dispatch($sqlWalker); 45 | 46 | $query .= ', '; 47 | 48 | for ($i = 0; $i < count($this->values); $i++) { 49 | if ($i > 0) { 50 | $query .= ', '; 51 | } 52 | 53 | $query .= $this->values[$i]->dispatch($sqlWalker); 54 | } 55 | 56 | $query .= ')'; 57 | 58 | return $query; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Query/Mysql/GroupConcat.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | 29 | $lexer = $parser->getLexer(); 30 | if ($lexer->isNextToken(TokenType::T_DISTINCT)) { 31 | $parser->match(TokenType::T_DISTINCT); 32 | 33 | $this->isDistinct = true; 34 | } 35 | 36 | // first Path Expression is mandatory 37 | $this->pathExp = []; 38 | if ($lexer->isNextToken(TokenType::T_IDENTIFIER)) { 39 | $this->pathExp[] = $parser->StringExpression(); 40 | } else { 41 | $this->pathExp[] = $parser->SingleValuedPathExpression(); 42 | } 43 | 44 | while ($lexer->isNextToken(TokenType::T_COMMA)) { 45 | $parser->match(TokenType::T_COMMA); 46 | $this->pathExp[] = $parser->StringPrimary(); 47 | } 48 | 49 | if ($lexer->isNextToken(TokenType::T_ORDER)) { 50 | $this->orderBy = $parser->OrderByClause(); 51 | } 52 | 53 | if ($lexer->isNextToken(TokenType::T_IDENTIFIER)) { 54 | if (strtolower($lexer->lookahead->value) !== 'separator') { 55 | $parser->syntaxError('separator'); 56 | } 57 | 58 | $parser->match(TokenType::T_IDENTIFIER); 59 | 60 | $this->separator = $parser->StringPrimary(); 61 | } 62 | 63 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 64 | } 65 | 66 | public function getSql(SqlWalker $sqlWalker): string 67 | { 68 | $result = 'GROUP_CONCAT(' . ($this->isDistinct ? 'DISTINCT ' : ''); 69 | 70 | $fields = []; 71 | foreach ($this->pathExp as $pathExp) { 72 | $fields[] = $pathExp->dispatch($sqlWalker); 73 | } 74 | 75 | $result .= sprintf('%s', implode(', ', $fields)); 76 | 77 | if ($this->orderBy) { 78 | $result .= ' ' . $sqlWalker->walkOrderByClause($this->orderBy); 79 | } 80 | 81 | if ($this->separator) { 82 | $result .= ' SEPARATOR ' . $sqlWalker->walkStringPrimary($this->separator); 83 | } 84 | 85 | $result .= ')'; 86 | 87 | return $result; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Query/Mysql/Hex.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression($this->arithmeticExpression) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Hour.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Hour extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'HOUR(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/IfElse.php: -------------------------------------------------------------------------------- 1 | */ 13 | class IfElse extends FunctionNode 14 | { 15 | private $expr = []; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->expr[] = $parser->ConditionalExpression(); 22 | 23 | $parser->match(TokenType::T_COMMA); 24 | if ($parser->getLexer()->isNextToken(TokenType::T_NULL)) { 25 | $parser->match(TokenType::T_NULL); 26 | $this->expr[] = null; 27 | } else { 28 | $this->expr[] = $parser->ArithmeticExpression(); 29 | } 30 | 31 | $parser->match(TokenType::T_COMMA); 32 | if ($parser->getLexer()->isNextToken(TokenType::T_NULL)) { 33 | $parser->match(TokenType::T_NULL); 34 | $this->expr[] = null; 35 | } else { 36 | $this->expr[] = $parser->ArithmeticExpression(); 37 | } 38 | 39 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 40 | } 41 | 42 | public function getSql(SqlWalker $sqlWalker): string 43 | { 44 | return sprintf( 45 | 'IF(%s, %s, %s)', 46 | $sqlWalker->walkConditionalExpression($this->expr[0]), 47 | $this->expr[1] !== null ? $sqlWalker->walkArithmeticPrimary($this->expr[1]) : 'NULL', 48 | $this->expr[2] !== null ? $sqlWalker->walkArithmeticPrimary($this->expr[2]) : 'NULL' 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Query/Mysql/IfNull.php: -------------------------------------------------------------------------------- 1 | */ 11 | class IfNull extends FunctionNode 12 | { 13 | private $expr1; 14 | 15 | private $expr2; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->expr1 = $parser->ArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->expr2 = $parser->ArithmeticExpression(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'IFNULL(' 30 | . $sqlWalker->walkArithmeticPrimary($this->expr1) . ', ' 31 | . $sqlWalker->walkArithmeticPrimary($this->expr2) . ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/Inet6Aton.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'INET6_ATON(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/Inet6Ntoa.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'INET6_NTOA(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/InetAton.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'INET_ATON(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/InetNtoa.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'INET_NTOA(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/Instr.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->originalString = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_COMMA); 24 | $this->subString = $parser->ArithmeticPrimary(); 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf( 31 | 'INSTR(%s, %s)', 32 | $this->originalString->dispatch($sqlWalker), 33 | $this->subString->dispatch($sqlWalker) 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Query/Mysql/IsIpv4.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'IS_IPV4(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/IsIpv4Compat.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'IS_IPV4_COMPAT(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/IsIpv4Mapped.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'IS_IPV4_MAPPED(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/IsIpv6.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->valueExpression = $parser->StringPrimary(); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | 25 | public function getSql(SqlWalker $sqlWalker): string 26 | { 27 | return 'IS_IPV6(' 28 | . ( 29 | $this->valueExpression instanceof Node 30 | ? $this->valueExpression->dispatch($sqlWalker) 31 | : "'" . $this->valueExpression . "'" 32 | ) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Mysql/JsonContains.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->target = $parser->StringPrimary(); 26 | 27 | $parser->match(TokenType::T_COMMA); 28 | 29 | $this->candidate = $parser->StringPrimary(); 30 | 31 | if ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { 32 | $parser->match(TokenType::T_COMMA); 33 | 34 | $this->path = $parser->StringPrimary(); 35 | } 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | 40 | public function getSql(SqlWalker $sqlWalker): string 41 | { 42 | $target = $sqlWalker->walkStringPrimary($this->target); 43 | $candidate = $sqlWalker->walkStringPrimary($this->candidate); 44 | 45 | if ($this->path !== null) { 46 | $path = $sqlWalker->walkStringPrimary($this->path); 47 | 48 | return sprintf('JSON_CONTAINS(%s, %s, %s)', $target, $candidate, $path); 49 | } 50 | 51 | return sprintf('JSON_CONTAINS(%s, %s)', $target, $candidate); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Query/Mysql/JsonDepth.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | 21 | $this->target = $parser->StringPrimary(); 22 | 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return sprintf('JSON_DEPTH(%s)', $sqlWalker->walkStringPrimary($this->target)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/JsonLength.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | 23 | $this->target = $parser->StringPrimary(); 24 | 25 | if ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { 26 | $parser->match(TokenType::T_COMMA); 27 | 28 | $this->path = $parser->StringPrimary(); 29 | } 30 | 31 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 32 | } 33 | 34 | public function getSql(SqlWalker $sqlWalker): string 35 | { 36 | $target = $sqlWalker->walkStringPrimary($this->target); 37 | 38 | if ($this->path !== null) { 39 | $path = $sqlWalker->walkStringPrimary($this->path); 40 | 41 | return sprintf('JSON_LENGTH(%s, %s)', $target, $path); 42 | } 43 | 44 | return sprintf('JSON_LENGTH(%s)', $target); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Query/Mysql/Lag.php: -------------------------------------------------------------------------------- 1 | offset, $this->defaultValue)) { 27 | return 'LAG(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ', ' . $sqlWalker->walkArithmeticPrimary($this->offset) . ', ' . $sqlWalker->walkSimpleArithmeticExpression($this->defaultValue) . ')'; 28 | } 29 | 30 | if (isset($this->offset)) { 31 | return 'LAG(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ', ' . $sqlWalker->walkArithmeticPrimary($this->offset) . ')'; 32 | } 33 | 34 | return 'LAG(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ')'; 35 | } 36 | 37 | public function parse(Parser $parser): void 38 | { 39 | $lexer = $parser->getLexer(); 40 | 41 | $parser->match(TokenType::T_IDENTIFIER); 42 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 43 | $this->aggregateExpression = $parser->StringExpression(); 44 | if (! $lexer->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 45 | $parser->match(TokenType::T_COMMA); 46 | $this->offset = $parser->ArithmeticPrimary(); 47 | } 48 | 49 | if (! $lexer->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 50 | $parser->match(TokenType::T_COMMA); 51 | $this->defaultValue = $parser->SimpleArithmeticExpression(); 52 | } 53 | 54 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Query/Mysql/LastDay.php: -------------------------------------------------------------------------------- 1 | 12 | * @author Sarjono Mukti Aji 13 | */ 14 | class LastDay extends FunctionNode 15 | { 16 | public $date; 17 | 18 | public function getSql(SqlWalker $sqlWalker): string 19 | { 20 | return 'LAST_DAY(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->date = $parser->ArithmeticPrimary(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/Lead.php: -------------------------------------------------------------------------------- 1 | offset, $this->defaultValue)) { 27 | return 'LEAD(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ', ' . $sqlWalker->walkArithmeticPrimary($this->offset) . ', ' . $sqlWalker->walkSimpleArithmeticExpression($this->defaultValue) . ')'; 28 | } 29 | 30 | if (isset($this->offset)) { 31 | return 'LEAD(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ', ' . $sqlWalker->walkArithmeticPrimary($this->offset) . ')'; 32 | } 33 | 34 | return 'LEAD(' . $sqlWalker->walkAggregateExpression($this->aggregateExpression) . ')'; 35 | } 36 | 37 | public function parse(Parser $parser): void 38 | { 39 | $lexer = $parser->getLexer(); 40 | 41 | $parser->match(TokenType::T_IDENTIFIER); 42 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 43 | $this->aggregateExpression = $parser->StringExpression(); 44 | if (! $lexer->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 45 | $parser->match(TokenType::T_COMMA); 46 | $this->offset = $parser->ArithmeticPrimary(); 47 | } 48 | 49 | if (! $lexer->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 50 | $parser->match(TokenType::T_COMMA); 51 | $this->defaultValue = $parser->SimpleArithmeticExpression(); 52 | } 53 | 54 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Query/Mysql/Least.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Least extends FunctionNode 14 | { 15 | private $field = null; 16 | 17 | private $values = []; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->field = $parser->ArithmeticExpression(); 24 | $lexer = $parser->getLexer(); 25 | 26 | while ( 27 | count($this->values) < 1 || 28 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 29 | ) { 30 | $parser->match(TokenType::T_COMMA); 31 | $this->values[] = $parser->ArithmeticExpression(); 32 | } 33 | 34 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 35 | } 36 | 37 | public function getSql(SqlWalker $sqlWalker): string 38 | { 39 | $query = 'LEAST('; 40 | 41 | $query .= $this->field->dispatch($sqlWalker); 42 | 43 | $query .= ', '; 44 | 45 | for ($i = 0; $i < count($this->values); $i++) { 46 | if ($i > 0) { 47 | $query .= ', '; 48 | } 49 | 50 | $query .= $this->values[$i]->dispatch($sqlWalker); 51 | } 52 | 53 | $query .= ')'; 54 | 55 | return $query; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Query/Mysql/Log.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Log10.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Log2.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Lpad.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Lpad extends FunctionNode 12 | { 13 | public $string = null; 14 | 15 | public $length = null; 16 | 17 | public $padstring = null; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->string = $parser->ArithmeticPrimary(); 24 | $parser->match(TokenType::T_COMMA); 25 | $this->length = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->padstring = $parser->ArithmeticPrimary(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return 'LPAD(' . 34 | $this->string->dispatch($sqlWalker) . ', ' . 35 | $this->length->dispatch($sqlWalker) . ', ' . 36 | $this->padstring->dispatch($sqlWalker) . 37 | ')'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Mysql/MakeDate.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->year = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->dayOfYear = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'MAKEDATE(' . 29 | $sqlWalker->walkArithmeticPrimary($this->year) . ', ' . 30 | $sqlWalker->walkArithmeticPrimary($this->dayOfYear) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/Md5.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Md5 extends FunctionNode 12 | { 13 | public $stringPrimary; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'MD5(' . $sqlWalker->walkStringPrimary($this->stringPrimary) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->stringPrimary = $parser->StringPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Minute.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Minute extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'MINUTE(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Month.php: -------------------------------------------------------------------------------- 1 | 12 | * @author Sarjono Mukti Aji 13 | */ 14 | class Month extends FunctionNode 15 | { 16 | public $date; 17 | 18 | public function getSql(SqlWalker $sqlWalker): string 19 | { 20 | return 'MONTH(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->date = $parser->ArithmeticPrimary(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/MonthName.php: -------------------------------------------------------------------------------- 1 | */ 11 | class MonthName extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'MONTHNAME(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Now.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Query/Mysql/NullIf.php: -------------------------------------------------------------------------------- 1 | */ 13 | class NullIf extends FunctionNode 14 | { 15 | private $expr1; 16 | 17 | private $expr2; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->expr1 = $parser->ArithmeticExpression(); 24 | $parser->match(TokenType::T_COMMA); 25 | $this->expr2 = $parser->ArithmeticExpression(); 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | 29 | public function getSql(SqlWalker $sqlWalker): string 30 | { 31 | return sprintf( 32 | 'NULLIF(%s, %s)', 33 | $sqlWalker->walkArithmeticPrimary($this->expr1), 34 | $sqlWalker->walkArithmeticPrimary($this->expr2) 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Mysql/Over.php: -------------------------------------------------------------------------------- 1 | orderByClause) && count($this->orderByClause->orderByItems) > 0 26 | ? $sqlWalker->walkArithmeticExpression($this->arithmeticExpression) . ' OVER (' . trim($sqlWalker->walkOrderByClause($this->orderByClause)) . ')' 27 | : $sqlWalker->walkArithmeticExpression($this->arithmeticExpression) . ' OVER ()'; 28 | } 29 | 30 | public function parse(Parser $parser): void 31 | { 32 | $lexer = $parser->getLexer(); 33 | 34 | $parser->match(TokenType::T_IDENTIFIER); 35 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 36 | $this->arithmeticExpression = $parser->ArithmeticExpression(); 37 | if (! $lexer->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 38 | $parser->match(TokenType::T_COMMA); 39 | $this->orderByClause = $parser->OrderByClause(); 40 | } 41 | 42 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Query/Mysql/PeriodDiff.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->firstDateExpression = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->secondDateExpression = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'PERIOD_DIFF(' . 29 | $sqlWalker->walkArithmeticTerm($this->firstDateExpression) . ', ' . 30 | $sqlWalker->walkArithmeticTerm($this->secondDateExpression) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/Pi.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Query/Mysql/Power.php: -------------------------------------------------------------------------------- 1 | arithmeticExpression->dispatch($sqlWalker) . ', ' 19 | . $this->power->dispatch($sqlWalker) . ')'; 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 28 | $parser->match(TokenType::T_COMMA); 29 | $this->power = $parser->ArithmeticExpression(); 30 | 31 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/Quarter.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Quarter extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'QUARTER(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Radians.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 18 | $this->arithmeticExpression 19 | ) . 20 | ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/Rand.php: -------------------------------------------------------------------------------- 1 | expression) { 19 | return 'RAND(' . $this->expression->dispatch($sqlWalker) . ')'; 20 | } 21 | 22 | return 'RAND()'; 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $lexer = $parser->getLexer(); 28 | $parser->match(TokenType::T_IDENTIFIER); 29 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 30 | 31 | if ($lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS) { 32 | $this->expression = $parser->SimpleArithmeticExpression(); 33 | } 34 | 35 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Mysql/Regexp.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->value = $parser->StringPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->regexp = $parser->StringExpression(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return '(' . $this->value->dispatch($sqlWalker) . ' REGEXP ' . $this->regexp->dispatch($sqlWalker) . ')'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Replace.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Replace extends FunctionNode 12 | { 13 | public $search = null; 14 | 15 | public $replace = null; 16 | 17 | public $subject = null; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->subject = $parser->ArithmeticPrimary(); 24 | $parser->match(TokenType::T_COMMA); 25 | $this->search = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->replace = $parser->ArithmeticPrimary(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return 'REPLACE(' . 34 | $this->subject->dispatch($sqlWalker) . ', ' . 35 | $this->search->dispatch($sqlWalker) . ', ' . 36 | $this->replace->dispatch($sqlWalker) . 37 | ')'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Mysql/Round.php: -------------------------------------------------------------------------------- 1 | getLexer(); 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->firstExpression = $parser->SimpleArithmeticExpression(); 22 | 23 | // parse second parameter if available 24 | if ($lexer->lookahead->type === TokenType::T_COMMA) { 25 | $parser->match(TokenType::T_COMMA); 26 | $this->secondExpression = $parser->ArithmeticPrimary(); 27 | } 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | 32 | public function getSql(SqlWalker $sqlWalker): string 33 | { 34 | // use second parameter if parsed 35 | if ($this->secondExpression !== null) { 36 | return 'ROUND(' 37 | . $this->firstExpression->dispatch($sqlWalker) 38 | . ', ' 39 | . $this->secondExpression->dispatch($sqlWalker) 40 | . ')'; 41 | } 42 | 43 | return 'ROUND(' . $this->firstExpression->dispatch($sqlWalker) . ')'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Query/Mysql/Rpad.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Rpad extends FunctionNode 12 | { 13 | public $string = null; 14 | 15 | public $length = null; 16 | 17 | public $padstring = null; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->string = $parser->ArithmeticPrimary(); 24 | $parser->match(TokenType::T_COMMA); 25 | $this->length = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->padstring = $parser->ArithmeticPrimary(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return 'RPAD(' . 34 | $this->string->dispatch($sqlWalker) . ', ' . 35 | $this->length->dispatch($sqlWalker) . ', ' . 36 | $this->padstring->dispatch($sqlWalker) . 37 | ')'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Mysql/SecToTime.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class SecToTime extends FunctionNode 17 | { 18 | public $time; 19 | 20 | public function getSql(SqlWalker $sqlWalker): string 21 | { 22 | return 'SEC_TO_TIME(' . $sqlWalker->walkArithmeticPrimary($this->time) . ')'; 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | 30 | $this->time = $parser->ArithmeticPrimary(); 31 | 32 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Mysql/Second.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Second extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'SECOND(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Sha1.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Sha1 extends FunctionNode 12 | { 13 | public $stringPrimary; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'SHA1(' . 18 | $sqlWalker->walkStringPrimary($this->stringPrimary) . 19 | ')'; 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->stringPrimary = $parser->StringPrimary(); 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/Sha2.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Sha2 extends FunctionNode 12 | { 13 | public $stringPrimary; 14 | 15 | public $simpleArithmeticExpression; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return 'SHA2(' . 20 | $sqlWalker->walkStringPrimary($this->stringPrimary) . 21 | ',' . 22 | $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) . 23 | ')'; 24 | } 25 | 26 | public function parse(Parser $parser): void 27 | { 28 | $parser->match(TokenType::T_IDENTIFIER); 29 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 30 | 31 | $this->stringPrimary = $parser->StringPrimary(); 32 | $parser->match(TokenType::T_COMMA); 33 | $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); 34 | 35 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Mysql/Sin.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Soundex.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Soundex extends FunctionNode 12 | { 13 | public $stringPrimary; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'SOUNDEX(' . $sqlWalker->walkStringPrimary($this->stringPrimary) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->stringPrimary = $parser->StringPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/Std.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Std extends FunctionNode 14 | { 15 | public $arithmeticExpression; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf('STD(%s)', $sqlWalker->walkSimpleArithmeticExpression($this->arithmeticExpression)); 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/StdDev.php: -------------------------------------------------------------------------------- 1 | */ 13 | class StdDev extends FunctionNode 14 | { 15 | public $arithmeticExpression; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf('STDDEV(%s)', $sqlWalker->walkSimpleArithmeticExpression($this->arithmeticExpression)); 20 | } 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 28 | 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/StrToDate.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->dateString = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->dateFormat = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'STR_TO_DATE(' . 29 | $this->dateString->dispatch($sqlWalker) . ', ' . 30 | $this->dateFormat->dispatch($sqlWalker) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Mysql/SubstringIndex.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | $this->string = $parser->ArithmeticPrimary(); 25 | $parser->match(TokenType::T_COMMA); 26 | $this->delimiter = $parser->ArithmeticPrimary(); 27 | $parser->match(TokenType::T_COMMA); 28 | $this->count = $parser->ArithmeticFactor(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | 32 | public function getSql(SqlWalker $sqlWalker): string 33 | { 34 | return sprintf( 35 | 'SUBSTRING_INDEX(%s, %s, %s)', 36 | $this->string->dispatch($sqlWalker), 37 | $this->delimiter->dispatch($sqlWalker), 38 | $this->count->dispatch($sqlWalker) 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Query/Mysql/Tan.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression( 17 | $this->arithmeticExpression 18 | ) . ')'; 19 | } 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | 26 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Query/Mysql/Time.php: -------------------------------------------------------------------------------- 1 | 12 | * @author James Rohacik 13 | */ 14 | class Time extends FunctionNode 15 | { 16 | public $time; 17 | 18 | public function getSql(SqlWalker $sqlWalker): string 19 | { 20 | return 'TIME(' . $sqlWalker->walkArithmeticPrimary($this->time) . ')'; 21 | } 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | 28 | $this->time = $parser->ArithmeticPrimary(); 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/TimeDiff.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->firstDateExpression = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_COMMA); 24 | $this->secondDateExpression = $parser->ArithmeticPrimary(); 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf( 31 | 'TIMEDIFF(%s, %s)', 32 | $this->firstDateExpression->dispatch($sqlWalker), 33 | $this->secondDateExpression->dispatch($sqlWalker) 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Query/Mysql/TimeToSec.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | class TimeToSec extends FunctionNode 17 | { 18 | public $time; 19 | 20 | public function getSql(SqlWalker $sqlWalker): string 21 | { 22 | return 'TIME_TO_SEC(' . $sqlWalker->walkArithmeticPrimary($this->time) . ')'; 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | 30 | $this->time = $parser->ArithmeticPrimary(); 31 | 32 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Mysql/TimestampAdd.php: -------------------------------------------------------------------------------- 1 | */ 13 | class TimestampAdd extends FunctionNode 14 | { 15 | public $firstDatetimeExpression = null; 16 | 17 | public $secondDatetimeExpression = null; 18 | 19 | public $unit = null; 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $lexer = $parser->getLexer(); 27 | $this->unit = $lexer->token->value; 28 | $parser->match(TokenType::T_COMMA); 29 | $this->firstDatetimeExpression = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_COMMA); 31 | $this->secondDatetimeExpression = $parser->ArithmeticPrimary(); 32 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 33 | } 34 | 35 | public function getSql(SqlWalker $sqlWalker): string 36 | { 37 | return sprintf( 38 | 'TIMESTAMPADD(%s, %s, %s)', 39 | $this->unit, 40 | $this->firstDatetimeExpression->dispatch($sqlWalker), 41 | $this->secondDatetimeExpression->dispatch($sqlWalker) 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Query/Mysql/TimestampDiff.php: -------------------------------------------------------------------------------- 1 | */ 13 | class TimestampDiff extends FunctionNode 14 | { 15 | public $firstDatetimeExpression = null; 16 | 17 | public $secondDatetimeExpression = null; 18 | 19 | public $unit = null; 20 | 21 | public function parse(Parser $parser): void 22 | { 23 | $parser->match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $lexer = $parser->getLexer(); 27 | $this->unit = $lexer->token->value; 28 | $parser->match(TokenType::T_COMMA); 29 | $this->firstDatetimeExpression = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_COMMA); 31 | $this->secondDatetimeExpression = $parser->ArithmeticPrimary(); 32 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 33 | } 34 | 35 | public function getSql(SqlWalker $sqlWalker): string 36 | { 37 | return sprintf( 38 | 'TIMESTAMPDIFF(%s, %s, %s)', 39 | $this->unit, 40 | $this->firstDatetimeExpression->dispatch($sqlWalker), 41 | $this->secondDatetimeExpression->dispatch($sqlWalker) 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Query/Mysql/Truncate.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Truncate extends FunctionNode 12 | { 13 | public $numberExpression = null; 14 | 15 | public $patternExpression = null; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->numberExpression = $parser->SimpleArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->patternExpression = $parser->SimpleArithmeticExpression(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'TRUNCATE(' . 30 | $this->numberExpression->dispatch($sqlWalker) . ', ' . 31 | $this->patternExpression->dispatch($sqlWalker) . 32 | ')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Mysql/Unhex.php: -------------------------------------------------------------------------------- 1 | walkSimpleArithmeticExpression($this->arithmeticExpression) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/UnixTimestamp.php: -------------------------------------------------------------------------------- 1 | 14 | * @author Oleg Khussainov 15 | */ 16 | class UnixTimestamp extends FunctionNode 17 | { 18 | public $date; 19 | 20 | public function getSql(SqlWalker $sqlWalker): string 21 | { 22 | return sprintf( 23 | 'UNIX_TIMESTAMP(%s)', 24 | $this->date ? $sqlWalker->walkArithmeticPrimary($this->date) : '' 25 | ); 26 | } 27 | 28 | public function parse(Parser $parser): void 29 | { 30 | $parser->match(TokenType::T_IDENTIFIER); 31 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 32 | 33 | if (! $parser->getLexer()->isNextToken(TokenType::T_CLOSE_PARENTHESIS)) { 34 | $this->date = $parser->ArithmeticPrimary(); 35 | } 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Mysql/UtcTimestamp.php: -------------------------------------------------------------------------------- 1 | */ 11 | class UtcTimestamp extends FunctionNode 12 | { 13 | public function getSql(SqlWalker $sqlWalker): string 14 | { 15 | return 'UTC_TIMESTAMP()'; 16 | } 17 | 18 | public function parse(Parser $parser): void 19 | { 20 | $parser->match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Query/Mysql/UuidShort.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Query/Mysql/Variance.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | 23 | $this->arithmeticExpression = $parser->SimpleArithmeticExpression(); 24 | 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf('VARIANCE(%s)', $sqlWalker->walkSimpleArithmeticExpression($this->arithmeticExpression)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Mysql/Week.php: -------------------------------------------------------------------------------- 1 | 12 | * @author Sarjono Mukti Aji 13 | * @author Łukasz Nowicki 14 | */ 15 | class Week extends FunctionNode 16 | { 17 | public $date; 18 | 19 | public $mode; 20 | 21 | public function getSql(SqlWalker $sqlWalker): string 22 | { 23 | $sql = 'WEEK(' . $sqlWalker->walkArithmeticPrimary($this->date); 24 | if ($this->mode !== null) { 25 | $sql .= ', ' . $sqlWalker->walkLiteral($this->mode); 26 | } 27 | 28 | $sql .= ')'; 29 | 30 | return $sql; 31 | } 32 | 33 | public function parse(Parser $parser): void 34 | { 35 | $parser->match(TokenType::T_IDENTIFIER); 36 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 37 | 38 | $this->date = $parser->ArithmeticPrimary(); 39 | 40 | if ($parser->getLexer()->lookahead->type === TokenType::T_COMMA) { 41 | $parser->match(TokenType::T_COMMA); 42 | $this->mode = $parser->Literal(); 43 | } 44 | 45 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Query/Mysql/WeekDay.php: -------------------------------------------------------------------------------- 1 | */ 11 | class WeekDay extends FunctionNode 12 | { 13 | private $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'WEEKDAY(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/WeekOfYear.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->date = $parser->ArithmeticPrimary(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Mysql/Year.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Year extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return 'YEAR(' . $sqlWalker->walkArithmeticPrimary($this->date) . ')'; 18 | } 19 | 20 | public function parse(Parser $parser): void 21 | { 22 | $parser->match(TokenType::T_IDENTIFIER); 23 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 24 | 25 | $this->date = $parser->ArithmeticPrimary(); 26 | 27 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Query/Mysql/YearMonth.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Mysql/YearWeek.php: -------------------------------------------------------------------------------- 1 | */ 11 | class YearWeek extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public $mode; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | $sql = 'YEARWEEK(' . $sqlWalker->walkArithmeticPrimary($this->date); 20 | if ($this->mode !== null) { 21 | $sql .= ', ' . $sqlWalker->walkLiteral($this->mode); 22 | } 23 | 24 | $sql .= ')'; 25 | 26 | return $sql; 27 | } 28 | 29 | public function parse(Parser $parser): void 30 | { 31 | $parser->match(TokenType::T_IDENTIFIER); 32 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 33 | 34 | $this->date = $parser->ArithmeticPrimary(); 35 | 36 | if ($parser->getLexer()->lookahead->type === TokenType::T_COMMA) { 37 | $parser->match(TokenType::T_COMMA); 38 | $this->mode = $parser->Literal(); 39 | } 40 | 41 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Query/MysqlWalker.php: -------------------------------------------------------------------------------- 1 | getQuery(); 17 | 18 | if ($query->getHint('mysqlWalker.sqlCalcFoundRows') === true) { 19 | $sql = str_replace('SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $sql); 20 | } 21 | 22 | if ($query->getHint('mysqlWalker.sqlNoCache') === true) { 23 | $sql = str_replace('SELECT', 'SELECT SQL_NO_CACHE', $sql); 24 | } 25 | 26 | return $sql; 27 | } 28 | 29 | /** @inheritdoc */ 30 | public function walkGroupByClause($groupByClause): string 31 | { 32 | $sql = parent::walkGroupByClause($groupByClause); 33 | 34 | $query = $this->getQuery(); 35 | 36 | if ($query->getHint('mysqlWalker.withRollup') === true) { 37 | $sql .= ' WITH ROLLUP'; 38 | } 39 | 40 | return $sql; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Query/Oracle/Ceil.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Ceil extends FunctionNode 14 | { 15 | private $number; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'CEIL(%s)', 21 | $sqlWalker->walkArithmeticPrimary($this->number) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->number = $parser->ArithmeticExpression(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Day.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Day extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'EXTRACT(DAY FROM %s)', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Floor.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Floor extends FunctionNode 14 | { 15 | private $number; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'FLOOR(%s)', 21 | $sqlWalker->walkArithmeticPrimary($this->number) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->number = $parser->ArithmeticExpression(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Hour.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Hour extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'EXTRACT(HOUR FROM %s)', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Minute.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Minute extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'EXTRACT(MINUTE FROM %s)', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Month.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Month extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'EXTRACT(MONTH FROM %s)', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/Nvl.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Nvl extends FunctionNode 14 | { 15 | private $expr1; 16 | 17 | private $expr2; 18 | 19 | public function getSql(SqlWalker $sqlWalker): string 20 | { 21 | return sprintf( 22 | 'NVL(%s, %s)', 23 | $sqlWalker->walkArithmeticPrimary($this->expr1), 24 | $sqlWalker->walkArithmeticPrimary($this->expr2) 25 | ); 26 | } 27 | 28 | public function parse(Parser $parser): void 29 | { 30 | $parser->match(TokenType::T_IDENTIFIER); 31 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 32 | $this->expr1 = $parser->ArithmeticExpression(); 33 | $parser->match(TokenType::T_COMMA); 34 | $this->expr2 = $parser->ArithmeticExpression(); 35 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Oracle/Second.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Second extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'FLOOR(EXTRACT(SECOND FROM %s))', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Oracle/ToChar.php: -------------------------------------------------------------------------------- 1 | */ 13 | class ToChar extends FunctionNode 14 | { 15 | private $datetime; 16 | 17 | private $fmt; 18 | 19 | private $nls = null; 20 | 21 | public function getSql(SqlWalker $sqlWalker): string 22 | { 23 | if ($this->nls) { 24 | return sprintf( 25 | 'TO_CHAR(%s, %s, %s)', 26 | $sqlWalker->walkArithmeticPrimary($this->datetime), 27 | $sqlWalker->walkArithmeticPrimary($this->fmt), 28 | $sqlWalker->walkArithmeticPrimary($this->nls) 29 | ); 30 | } 31 | 32 | return sprintf( 33 | 'TO_CHAR(%s, %s)', 34 | $sqlWalker->walkArithmeticPrimary($this->datetime), 35 | $sqlWalker->walkArithmeticPrimary($this->fmt) 36 | ); 37 | } 38 | 39 | public function parse(Parser $parser): void 40 | { 41 | $lexer = $parser->getLexer(); 42 | 43 | $parser->match(TokenType::T_IDENTIFIER); 44 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 45 | $this->datetime = $parser->ArithmeticExpression(); 46 | $parser->match(TokenType::T_COMMA); 47 | $this->fmt = $parser->StringExpression(); 48 | 49 | if ($lexer->isNextToken(TokenType::T_COMMA)) { 50 | $parser->match(TokenType::T_COMMA); 51 | $this->nls = $parser->StringExpression(); 52 | } 53 | 54 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Query/Oracle/ToDate.php: -------------------------------------------------------------------------------- 1 | */ 13 | class ToDate extends FunctionNode 14 | { 15 | private $date; 16 | 17 | private $fmt; 18 | 19 | public function getSql(SqlWalker $sqlWalker): string 20 | { 21 | return sprintf( 22 | 'TO_DATE(%s, %s)', 23 | $sqlWalker->walkArithmeticPrimary($this->date), 24 | $sqlWalker->walkArithmeticPrimary($this->fmt) 25 | ); 26 | } 27 | 28 | public function parse(Parser $parser): void 29 | { 30 | $parser->match(TokenType::T_IDENTIFIER); 31 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 32 | $this->date = $parser->ArithmeticExpression(); 33 | $parser->match(TokenType::T_COMMA); 34 | $this->fmt = $parser->StringExpression(); 35 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Query/Oracle/Trunc.php: -------------------------------------------------------------------------------- 1 | */ 14 | class Trunc extends FunctionNode 15 | { 16 | /** @var Node */ 17 | private $date; 18 | 19 | /** @var Node */ 20 | private $fmt; 21 | 22 | public function getSql(SqlWalker $sqlWalker): string 23 | { 24 | if ($this->fmt) { 25 | return sprintf( 26 | 'TRUNC(%s, %s)', 27 | $sqlWalker->walkArithmeticPrimary($this->date), 28 | $sqlWalker->walkArithmeticPrimary($this->fmt) 29 | ); 30 | } 31 | 32 | return sprintf( 33 | 'TRUNC(%s)', 34 | $sqlWalker->walkArithmeticPrimary($this->date) 35 | ); 36 | } 37 | 38 | public function parse(Parser $parser): void 39 | { 40 | $lexer = $parser->getLexer(); 41 | 42 | $parser->match(TokenType::T_IDENTIFIER); 43 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 44 | $this->date = $parser->ArithmeticExpression(); 45 | 46 | if ($lexer->isNextToken(TokenType::T_COMMA)) { 47 | $parser->match(TokenType::T_COMMA); 48 | $this->fmt = $parser->StringExpression(); 49 | } 50 | 51 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Query/Oracle/Year.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Year extends FunctionNode 14 | { 15 | private $date; 16 | 17 | public function getSql(SqlWalker $sqlWalker): string 18 | { 19 | return sprintf( 20 | 'EXTRACT(YEAR FROM %s)', 21 | $sqlWalker->walkArithmeticPrimary($this->date) 22 | ); 23 | } 24 | 25 | public function parse(Parser $parser): void 26 | { 27 | $parser->match(TokenType::T_IDENTIFIER); 28 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 29 | $this->date = $parser->ArithmeticPrimary(); 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Query/Postgresql/AtTimeZoneFunction.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->dateExpression = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->timezoneExpression = $parser->ArithmeticPrimary(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return sprintf( 34 | '%s AT TIME ZONE %s', 35 | $this->dateExpression->dispatch($sqlWalker), 36 | $this->timezoneExpression->dispatch($sqlWalker) 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Postgresql/CountFilterFunction.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 24 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 25 | $this->countExpression = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->whereExpression = $parser->WhereClause(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return sprintf( 34 | 'COUNT(%s) FILTER(%s)', 35 | $this->countExpression->dispatch($sqlWalker), 36 | $this->whereExpression->dispatch($sqlWalker) 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Date.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) . ')'; 17 | } 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->date = $parser->ArithmeticPrimary(); 25 | 26 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Query/Postgresql/DateFormat.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->dateExpression = $parser->ArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->patternExpression = $parser->StringPrimary(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'TO_CHAR(' . 30 | $this->dateExpression->dispatch($sqlWalker) . ', ' . 31 | $this->patternExpression->dispatch($sqlWalker) . 32 | ')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Postgresql/DatePart.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->dateString = $parser->ArithmeticPrimary(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->dateFormat = $parser->ArithmeticPrimary(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'DATE_PART(' . 30 | $this->dateString->dispatch($sqlWalker) . ', ' . 31 | $this->dateFormat->dispatch($sqlWalker) . 32 | ')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Query/Postgresql/DateTrunc.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->fieldText = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_COMMA); 24 | $this->fieldTimestamp = $parser->ArithmeticPrimary(); 25 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 26 | } 27 | 28 | public function getSql(SqlWalker $sqlWalker): string 29 | { 30 | return sprintf( 31 | 'DATE_TRUNC(%s::text, %s::timestamp)', 32 | $this->fieldText->dispatch($sqlWalker), 33 | $this->fieldTimestamp->dispatch($sqlWalker) 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Day.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Postgresql/ExtractFunction.php: -------------------------------------------------------------------------------- 1 | field, 29 | $this->value->dispatch($sqlWalker) 30 | ); 31 | } 32 | 33 | /** @throws QueryException */ 34 | public function parse(Parser $parser): void 35 | { 36 | $parser->match(TokenType::T_IDENTIFIER); 37 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 38 | 39 | $parser->match(TokenType::T_IDENTIFIER); 40 | $this->field = $parser->getLexer()->token->value; 41 | 42 | $parser->match(TokenType::T_FROM); 43 | 44 | $this->value = $parser->ScalarExpression(); 45 | 46 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Greatest.php: -------------------------------------------------------------------------------- 1 | 14 | * @author Guven Atbakan 15 | * @author Leonardo B Motyczka 16 | */ 17 | class Greatest extends FunctionNode 18 | { 19 | private $field = null; 20 | 21 | private $values = []; 22 | 23 | public function parse(Parser $parser): void 24 | { 25 | $parser->match(TokenType::T_IDENTIFIER); 26 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 27 | $this->field = $parser->ArithmeticExpression(); 28 | $lexer = $parser->getLexer(); 29 | 30 | while ( 31 | count($this->values) < 1 || 32 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 33 | ) { 34 | $parser->match(TokenType::T_COMMA); 35 | $this->values[] = $parser->ArithmeticExpression(); 36 | } 37 | 38 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 39 | } 40 | 41 | public function getSql(SqlWalker $sqlWalker): string 42 | { 43 | $query = 'GREATEST('; 44 | 45 | $query .= $this->field->dispatch($sqlWalker); 46 | 47 | $query .= ', '; 48 | 49 | for ($i = 0; $i < count($this->values); $i++) { 50 | if ($i > 0) { 51 | $query .= ', '; 52 | } 53 | 54 | $query .= $this->values[$i]->dispatch($sqlWalker); 55 | } 56 | 57 | $query .= ')'; 58 | 59 | return $query; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Hour.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Least.php: -------------------------------------------------------------------------------- 1 | 14 | * @author Leonardo B Motyczka 15 | */ 16 | class Least extends FunctionNode 17 | { 18 | private $field = null; 19 | 20 | private $values = []; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | $this->field = $parser->ArithmeticExpression(); 27 | $lexer = $parser->getLexer(); 28 | 29 | while ( 30 | count($this->values) < 1 || 31 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 32 | ) { 33 | $parser->match(TokenType::T_COMMA); 34 | $this->values[] = $parser->ArithmeticExpression(); 35 | } 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | 40 | public function getSql(SqlWalker $sqlWalker): string 41 | { 42 | $query = 'LEAST('; 43 | 44 | $query .= $this->field->dispatch($sqlWalker); 45 | 46 | $query .= ', '; 47 | 48 | for ($i = 0; $i < count($this->values); $i++) { 49 | if ($i > 0) { 50 | $query .= ', '; 51 | } 52 | 53 | $query .= $this->values[$i]->dispatch($sqlWalker); 54 | } 55 | 56 | $query .= ')'; 57 | 58 | return $query; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Minute.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Month.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Postgresql/RegexpReplace.php: -------------------------------------------------------------------------------- 1 | string->dispatch($sqlWalker) . ', ' . $this->search->dispatch($sqlWalker) . ', ' . $this->replace->dispatch($sqlWalker) . ')'; 26 | } 27 | 28 | public function parse(Parser $parser): void 29 | { 30 | $parser->match(TokenType::T_IDENTIFIER); 31 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 32 | 33 | $this->string = $parser->StringPrimary(); 34 | $parser->match(TokenType::T_COMMA); 35 | $this->search = $parser->StringExpression(); 36 | $parser->match(TokenType::T_COMMA); 37 | $this->replace = $parser->StringExpression(); 38 | 39 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Second.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/Postgresql/StrToDate.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 19 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 20 | $this->dateString = $parser->ArithmeticPrimary(); 21 | $parser->match(TokenType::T_COMMA); 22 | $this->dateFormat = $parser->ArithmeticPrimary(); 23 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 24 | } 25 | 26 | public function getSql(SqlWalker $sqlWalker): string 27 | { 28 | return 'TO_DATE(' . 29 | $this->dateString->dispatch($sqlWalker) . ', ' . 30 | $this->dateFormat->dispatch($sqlWalker) . 31 | ')'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Query/Postgresql/StringAgg.php: -------------------------------------------------------------------------------- 1 | 15 | * @author Vaskevich Eugeniy 16 | */ 17 | class StringAgg extends FunctionNode 18 | { 19 | private $orderBy = null; 20 | 21 | private $expression = null; 22 | 23 | private $delimiter = null; 24 | 25 | private $isDistinct = false; 26 | 27 | public function parse(Parser $parser): void 28 | { 29 | $parser->match(TokenType::T_IDENTIFIER); 30 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 31 | 32 | $lexer = $parser->getLexer(); 33 | if ($lexer->isNextToken(TokenType::T_DISTINCT)) { 34 | $parser->match(TokenType::T_DISTINCT); 35 | 36 | $this->isDistinct = true; 37 | } 38 | 39 | $this->expression = $parser->PathExpression(PathExpression::TYPE_STATE_FIELD); 40 | $parser->match(TokenType::T_COMMA); 41 | $this->delimiter = $parser->StringPrimary(); 42 | 43 | if ($lexer->isNextToken(TokenType::T_ORDER)) { 44 | $this->orderBy = $parser->OrderByClause(); 45 | } 46 | 47 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 48 | } 49 | 50 | public function getSql(SqlWalker $sqlWalker): string 51 | { 52 | return sprintf( 53 | 'string_agg(%s%s, %s%s)', 54 | ($this->isDistinct ? 'DISTINCT ' : ''), 55 | $sqlWalker->walkPathExpression($this->expression), 56 | $sqlWalker->walkStringPrimary($this->delimiter), 57 | ($this->orderBy ? $sqlWalker->walkOrderByClause($this->orderBy) : '') 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Query/Postgresql/Year.php: -------------------------------------------------------------------------------- 1 | walkArithmeticPrimary($this->date) 21 | ); 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | $this->date = $parser->ArithmeticPrimary(); 29 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Query/SortableNullsWalker.php: -------------------------------------------------------------------------------- 1 | createQueryBuilder() 17 | * ->select('p') 18 | * ->from('Webges\Domain\Core\Person\Person', 'p') 19 | * ->where('p.id = 1') 20 | * ->orderBy('p.firstname', 'ASC') 21 | * ->addOrderBy('p.lastname', 'DESC') 22 | * ->addOrderBy('p.id', 'DESC'); // relation to person 23 | * 24 | * $query = $qb->getQuery(); 25 | * $query->setHint(Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Webges\DoctrineExtensions\Query\SortableNullsWalker'); 26 | * $query->setHint("sortableNulls.fields", array( 27 | * "p.firstname" => Webges\DoctrineExtensions\Query\SortableNullsWalker::NULLS_FIRST, 28 | * "p.lastname" => Webges\DoctrineExtensions\Query\SortableNullsWalker::NULLS_LAST, 29 | * "p.id" => Webges\DoctrineExtensions\Query\SortableNullsWalker::NULLS_LAST 30 | * )); 31 | * 32 | * @see http://www.doctrine-project.org/jira/browse/DDC-490 33 | */ 34 | class SortableNullsWalker extends Query\SqlWalker 35 | { 36 | public const NULLS_FIRST = 'NULLS FIRST'; 37 | 38 | public const NULLS_LAST = 'NULLS LAST'; 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function walkOrderByItem($orderByItem): string 44 | { 45 | $sql = parent::walkOrderByItem($orderByItem); 46 | $hint = $this->getQuery()->getHint('sortableNulls.fields'); 47 | $expr = $orderByItem->expression; 48 | $type = strtoupper($orderByItem->type); 49 | 50 | if (is_array($hint) && count($hint)) { 51 | // check for a state field 52 | if ( 53 | $expr instanceof Query\AST\PathExpression && 54 | $expr->type === Query\AST\PathExpression::TYPE_STATE_FIELD 55 | ) { 56 | $fieldName = $expr->field; 57 | $dqlAlias = $expr->identificationVariable; 58 | $search = $this->walkPathExpression($expr) . ' ' . $type; 59 | $index = $dqlAlias . '.' . $fieldName; 60 | if (isset($hint[$index])) { 61 | $sql = str_replace($search, $search . ' ' . $hint[$index], $sql); 62 | } 63 | } 64 | } 65 | 66 | return $sql; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Query/Sqlite/AbstractStrfTime.php: -------------------------------------------------------------------------------- 1 | */ 11 | abstract class AbstractStrfTime extends FunctionNode 12 | { 13 | public $date; 14 | 15 | public function getSql(SqlWalker $sqlWalker): string 16 | { 17 | return "STRFTIME('" 18 | . $this->getFormat() 19 | . "', " 20 | . $sqlWalker->walkArithmeticPrimary($this->date) 21 | . ')'; 22 | } 23 | 24 | public function parse(Parser $parser): void 25 | { 26 | $parser->match(TokenType::T_IDENTIFIER); 27 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 28 | 29 | $this->date = $parser->ArithmeticPrimary(); 30 | 31 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 32 | } 33 | 34 | abstract protected function getFormat(): string; 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Sqlite/ConcatWs.php: -------------------------------------------------------------------------------- 1 | */ 16 | class ConcatWs extends FunctionNode 17 | { 18 | private $values = []; 19 | 20 | private $notEmpty = false; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | 27 | // Add the concat separator to the values array. 28 | $this->values[] = $parser->ArithmeticExpression(); 29 | 30 | // Add the rest of the strings to the values array. CONCAT_WS must 31 | // be used with at least 2 strings not including the separator. 32 | 33 | $lexer = $parser->getLexer(); 34 | 35 | while (count($this->values) < 3 || $lexer->lookahead->type === TokenType::T_COMMA) { 36 | $parser->match(TokenType::T_COMMA); 37 | $peek = $lexer->glimpse(); 38 | 39 | $this->values[] = $peek->value === '(' 40 | ? $parser->FunctionDeclaration() 41 | : $parser->ArithmeticExpression(); 42 | } 43 | 44 | while ($lexer->lookahead->type === TokenType::T_IDENTIFIER) { 45 | switch (strtolower($lexer->lookahead->value)) { 46 | case 'notempty': 47 | $parser->match(TokenType::T_IDENTIFIER); 48 | $this->notEmpty = true; 49 | 50 | break; 51 | default: // Identifier not recognized (causes exception). 52 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 53 | 54 | break; 55 | } 56 | } 57 | 58 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 59 | } 60 | 61 | public function getSql(SqlWalker $sqlWalker): string 62 | { 63 | $separator = $this->values[0]->simpleArithmeticExpression->value; 64 | 65 | // Create an array to hold the query elements. 66 | $queryBuilder = ['(']; 67 | 68 | // Iterate over the captured expressions and add them to the query. 69 | for ($i = 1; $i < count($this->values); $i++) { 70 | if ($i > 1) { 71 | $queryBuilder[] = ' || \'' . $separator . '\' || '; 72 | } 73 | 74 | // Dispatch the walker on the current node. 75 | $queryBuilder[] = sprintf("IFNULL(%s, '')", $sqlWalker->walkArithmeticPrimary($this->values[$i])); 76 | } 77 | 78 | // Close the query. 79 | $queryBuilder[] = ')'; 80 | 81 | // Return the joined query. 82 | return implode('', $queryBuilder); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Date.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Date extends AbstractStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%Y-%m-%d'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Day.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Day extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%d'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Greatest.php: -------------------------------------------------------------------------------- 1 | 14 | * @author Guven Atbakan 15 | */ 16 | class Greatest extends FunctionNode 17 | { 18 | private $field = null; 19 | 20 | private $values = []; 21 | 22 | public function parse(Parser $parser): void 23 | { 24 | $parser->match(TokenType::T_IDENTIFIER); 25 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 26 | $this->field = $parser->ArithmeticExpression(); 27 | $lexer = $parser->getLexer(); 28 | 29 | while ( 30 | count($this->values) < 1 || 31 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 32 | ) { 33 | $parser->match(TokenType::T_COMMA); 34 | $this->values[] = $parser->ArithmeticExpression(); 35 | } 36 | 37 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 38 | } 39 | 40 | public function getSql(SqlWalker $sqlWalker): string 41 | { 42 | $query = 'MAX('; 43 | 44 | $query .= $this->field->dispatch($sqlWalker); 45 | 46 | $query .= ', '; 47 | 48 | for ($i = 0; $i < count($this->values); $i++) { 49 | if ($i > 0) { 50 | $query .= ', '; 51 | } 52 | 53 | $query .= $this->values[$i]->dispatch($sqlWalker); 54 | } 55 | 56 | $query .= ')'; 57 | 58 | return $query; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Hour.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Hour extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%H'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/IfElse.php: -------------------------------------------------------------------------------- 1 | */ 13 | class IfElse extends FunctionNode 14 | { 15 | private $expr = []; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->expr[] = $parser->ConditionalExpression(); 22 | 23 | for ($i = 0; $i < 2; $i++) { 24 | $parser->match(TokenType::T_COMMA); 25 | $this->expr[] = $parser->ArithmeticExpression(); 26 | } 27 | 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return sprintf( 34 | 'CASE WHEN %s THEN %s ELSE %s END', 35 | $sqlWalker->walkConditionalExpression($this->expr[0]), 36 | $sqlWalker->walkArithmeticPrimary($this->expr[1]), 37 | $sqlWalker->walkArithmeticPrimary($this->expr[2]) 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Query/Sqlite/IfNull.php: -------------------------------------------------------------------------------- 1 | */ 11 | class IfNull extends FunctionNode 12 | { 13 | private $expr1; 14 | 15 | private $expr2; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $parser->match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $this->expr1 = $parser->ArithmeticExpression(); 22 | $parser->match(TokenType::T_COMMA); 23 | $this->expr2 = $parser->ArithmeticExpression(); 24 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 25 | } 26 | 27 | public function getSql(SqlWalker $sqlWalker): string 28 | { 29 | return 'IFNULL(' 30 | . $sqlWalker->walkArithmeticPrimary($this->expr1) 31 | . ', ' 32 | . $sqlWalker->walkArithmeticPrimary($this->expr2) 33 | . ')'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Query/Sqlite/JulianDay.php: -------------------------------------------------------------------------------- 1 | */ 6 | class JulianDay extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%J'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Least.php: -------------------------------------------------------------------------------- 1 | */ 13 | class Least extends FunctionNode 14 | { 15 | private $field = null; 16 | 17 | private $values = []; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->field = $parser->ArithmeticExpression(); 24 | $lexer = $parser->getLexer(); 25 | 26 | while ( 27 | count($this->values) < 1 || 28 | $lexer->lookahead->type !== TokenType::T_CLOSE_PARENTHESIS 29 | ) { 30 | $parser->match(TokenType::T_COMMA); 31 | $this->values[] = $parser->ArithmeticExpression(); 32 | } 33 | 34 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 35 | } 36 | 37 | public function getSql(SqlWalker $sqlWalker): string 38 | { 39 | $query = 'MIN('; 40 | 41 | $query .= $this->field->dispatch($sqlWalker); 42 | 43 | $query .= ', '; 44 | 45 | for ($i = 0; $i < count($this->values); $i++) { 46 | if ($i > 0) { 47 | $query .= ', '; 48 | } 49 | 50 | $query .= $this->values[$i]->dispatch($sqlWalker); 51 | } 52 | 53 | $query .= ')'; 54 | 55 | return $query; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Minute.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Minute extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%M'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Month.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Month extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%m'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/NumberFromStrfTime.php: -------------------------------------------------------------------------------- 1 | getFormat() 13 | . "', " 14 | . $sqlWalker->walkArithmeticPrimary($this->date) 15 | . ') AS NUMBER)'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Random.php: -------------------------------------------------------------------------------- 1 | match(TokenType::T_IDENTIFIER); 20 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 21 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Replace.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Replace extends FunctionNode 12 | { 13 | public $search = null; 14 | 15 | public $replace = null; 16 | 17 | public $subject = null; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | $this->subject = $parser->ArithmeticPrimary(); 24 | $parser->match(TokenType::T_COMMA); 25 | $this->search = $parser->ArithmeticPrimary(); 26 | $parser->match(TokenType::T_COMMA); 27 | $this->replace = $parser->ArithmeticPrimary(); 28 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 29 | } 30 | 31 | public function getSql(SqlWalker $sqlWalker): string 32 | { 33 | return 'REPLACE(' . 34 | $this->subject->dispatch($sqlWalker) . ', ' . 35 | $this->search->dispatch($sqlWalker) . ', ' . 36 | $this->replace->dispatch($sqlWalker) . 37 | ')'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Round.php: -------------------------------------------------------------------------------- 1 | */ 11 | class Round extends FunctionNode 12 | { 13 | private $firstExpression = null; 14 | 15 | private $secondExpression = null; 16 | 17 | public function parse(Parser $parser): void 18 | { 19 | $lexer = $parser->getLexer(); 20 | $parser->match(TokenType::T_IDENTIFIER); 21 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 22 | $this->firstExpression = $parser->SimpleArithmeticExpression(); 23 | 24 | // parse second parameter if available 25 | if ($lexer->lookahead->type === TokenType::T_COMMA) { 26 | $parser->match(TokenType::T_COMMA); 27 | $this->secondExpression = $parser->ArithmeticPrimary(); 28 | } 29 | 30 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 31 | } 32 | 33 | public function getSql(SqlWalker $sqlWalker): string 34 | { 35 | // use second parameter if parsed 36 | if ($this->secondExpression !== null) { 37 | return 'ROUND(' 38 | . $this->firstExpression->dispatch($sqlWalker) 39 | . ', ' 40 | . $this->secondExpression->dispatch($sqlWalker) 41 | . ')'; 42 | } 43 | 44 | return 'ROUND(' . $this->firstExpression->dispatch($sqlWalker) . ')'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Second.php: -------------------------------------------------------------------------------- 1 | */ 12 | class StrfTime extends FunctionNode 13 | { 14 | public $date; 15 | 16 | public $formatter; 17 | 18 | /** @throws QueryException */ 19 | public function getSql(SqlWalker $sqlWalker): string 20 | { 21 | return 'strftime(' 22 | . $sqlWalker->walkLiteral($this->formatter) 23 | . ', ' 24 | . $sqlWalker->walkArithmeticPrimary($this->date) 25 | . ')'; 26 | } 27 | 28 | public function parse(Parser $parser): void 29 | { 30 | $parser->match(TokenType::T_IDENTIFIER); 31 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 32 | 33 | $this->formatter = $parser->Literal(); 34 | 35 | $parser->match(TokenType::T_COMMA); 36 | $this->date = $parser->ArithmeticPrimary(); 37 | 38 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Week.php: -------------------------------------------------------------------------------- 1 | */ 10 | class Week extends NumberFromStrfTime 11 | { 12 | /** 13 | * Currently not in use 14 | * 15 | * @var Literal 16 | */ 17 | public $mode; 18 | 19 | public function parse(Parser $parser): void 20 | { 21 | $parser->match(TokenType::T_IDENTIFIER); 22 | $parser->match(TokenType::T_OPEN_PARENTHESIS); 23 | 24 | $this->date = $parser->ArithmeticPrimary(); 25 | 26 | if ($parser->getLexer()->lookahead->type === TokenType::T_COMMA) { 27 | $parser->match(TokenType::T_COMMA); 28 | $this->mode = $parser->Literal(); 29 | } 30 | 31 | $parser->match(TokenType::T_CLOSE_PARENTHESIS); 32 | } 33 | 34 | protected function getFormat(): string 35 | { 36 | return '%W'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Query/Sqlite/WeekDay.php: -------------------------------------------------------------------------------- 1 | */ 6 | class WeekDay extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%w'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Query/Sqlite/Year.php: -------------------------------------------------------------------------------- 1 | */ 6 | class Year extends NumberFromStrfTime 7 | { 8 | protected function getFormat(): string 9 | { 10 | return '%Y'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Types/CarbonDateTimeType.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class ZendDateType extends Type 22 | { 23 | public const ZENDDATE = 'zenddate'; 24 | 25 | /** 26 | * {@inheritDoc} 27 | */ 28 | public function getName() 29 | { 30 | return self::ZENDDATE; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string 37 | { 38 | return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string 45 | { 46 | return $value !== null 47 | ? $value->toString(Zend_Locale_Format::convertPhpToIsoFormat( 48 | $platform->getDateTimeFormatString() 49 | )) 50 | : null; 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | public function convertToPHPValue($value, AbstractPlatform $platform): ?Zend_Date 57 | { 58 | if ($value === null) { 59 | return null; 60 | } 61 | 62 | $dateTimeFormatString = Zend_Locale_Format::convertPhpToIsoFormat( 63 | $platform->getDateTimeFormatString() 64 | ); 65 | 66 | return new Zend_Date($value, $dateTimeFormatString); 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | public function requiresSQLCommentHint(AbstractPlatform $platform) 73 | { 74 | return true; 75 | } 76 | } 77 | --------------------------------------------------------------------------------