diff --git a/README.md b/README.md index f586c6cb..0599d406 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ MySQL, Oracle, PostgreSQL and SQLite. | DB | Functions | |:--:|:---------:| -| MySQL | `ACOS, ADDTIME, AES_DECRYPT, AES_ENCRYPT, ANY_VALUE, ASCII, ASIN, ATAN, ATAN2, BINARY, BIT_COUNT, BIT_XOR, CAST, CEIL, CHAR_LENGTH, COLLATE, CONCAT_WS, CONVERT_TZ, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DAYOFWEEK, DAYOFYEAR, DEGREES, DIV, EXP, EXTRACT, FIELD, FIND_IN_SET, FLOOR, FORMAT, FROM_UNIXTIME, GREATEST, GROUP_CONCAT, HEX, HOUR, IFELSE, IFNULL, INET_ATON, INET_NTOA, INET6_ATON, INET6_NTOA, INSTR, IS_IPV4, IS_IPV4_COMPAT, IS_IPV4_MAPPED, IS_IPV6, LAST_DAY, LEAST, LOG, LOG10, LOG2, LPAD, MATCH, MD5, MINUTE, MONTH, MONTHNAME, NOW, NULLIF, PERIOD_DIFF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, RPAD, SECOND, SECTOTIME, SHA1, SHA2, SIN, SOUNDEX, STD, STDDEV, STRTODATE, STR_TO_DATE, SUBSTRING_INDEX, TAN, TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, TIMETOSEC, UNHEX, UNIX_TIMESTAMP, UTC_TIMESTAMP, UUID_SHORT, VARIANCE, WEEK, WEEKDAY, YEAR, YEARMONTH, YEARWEEK` | +| MySQL | `ACOS, ADDTIME, AES_DECRYPT, AES_ENCRYPT, ANY_VALUE, ASCII, ASIN, ATAN, ATAN2, BINARY, BIT_COUNT, BIT_XOR, CAST, CEIL, CHAR_LENGTH, COLLATE, CONCAT_WS, CONVERT_TZ, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DAYOFWEEK, DAYOFYEAR, DEGREES, DIV, EXP, EXTRACT, FIELD, FIND_IN_SET, FLOOR, FORMAT, FROM_UNIXTIME, GREATEST, GROUP_CONCAT, HEX, HOUR, IFELSE, IFNULL, INET_ATON, INET_NTOA, INET6_ATON, INET6_NTOA, INSTR, IS_IPV4, IS_IPV4_COMPAT, IS_IPV4_MAPPED, IS_IPV6, LAST_DAY, LEAST, LOG, LOG10, LOG2, LPAD, MAKEDATE, MATCH, MD5, MINUTE, MONTH, MONTHNAME, NOW, NULLIF, PERIOD_DIFF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, RPAD, SECOND, SECTOTIME, SHA1, SHA2, SIN, SOUNDEX, STD, STDDEV, STRTODATE, STR_TO_DATE, SUBSTRING_INDEX, TAN, TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, TIMETOSEC, UNHEX, UNIX_TIMESTAMP, UTC_TIMESTAMP, UUID_SHORT, VARIANCE, WEEK, WEEKDAY, YEAR, YEARMONTH, YEARWEEK` | | Oracle | `DAY, LISTAGG, MONTH, NVL, TO_CHAR, TO_DATE, TRUNC, YEAR` | | Sqlite | `DATE, MINUTE, HOUR, DAY, WEEK, WEEKDAY, MONTH, YEAR, JULIANDAY, STRFTIME, DATE_FORMAT*, CASE WHEN THEN ELSE END, IFNULL, REPLACE, ROUND` | | PostgreSQL | `DATE_PART, GREATEST, LEAST, COUNT_FILTER, STRING_AGG, TO_DATE, TO_CHAR, AT_TIME_ZONE` | diff --git a/config/mysql.yml b/config/mysql.yml index 8283e2c1..240dbcd3 100644 --- a/config/mysql.yml +++ b/config/mysql.yml @@ -17,6 +17,7 @@ doctrine: from_unixtime: DoctrineExtensions\Query\Mysql\FromUnixtime hour: DoctrineExtensions\Query\Mysql\Hour last_day: DoctrineExtensions\Query\Mysql\LastDay + makedate: DoctrineExtensions\Query\Mysql\MakeDate minute: DoctrineExtensions\Query\Mysql\Minute now: DoctrineExtensions\Query\Mysql\Now month: DoctrineExtensions\Query\Mysql\Month diff --git a/src/Query/Mysql/MakeDate.php b/src/Query/Mysql/MakeDate.php new file mode 100644 index 00000000..6d90e48d --- /dev/null +++ b/src/Query/Mysql/MakeDate.php @@ -0,0 +1,31 @@ +match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + $this->year = $parser->ArithmeticPrimary(); + $parser->match(Lexer::T_COMMA); + $this->dayOfYear = $parser->ArithmeticPrimary(); + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + return 'MAKEDATE('. + $sqlWalker->walkArithmeticPrimary($this->year).', '. + $sqlWalker->walkArithmeticPrimary($this->dayOfYear). + ')'; + } +} diff --git a/tests/Query/Mysql/MakeDateTest.php b/tests/Query/Mysql/MakeDateTest.php new file mode 100644 index 00000000..9e90ad50 --- /dev/null +++ b/tests/Query/Mysql/MakeDateTest.php @@ -0,0 +1,16 @@ +assertDqlProducesSql( + "SELECT MAKEDATE(2019, 5) FROM DoctrineExtensions\Tests\Entities\Blank b", + 'SELECT MAKEDATE(2019, 5) AS sclr_0 FROM Blank b0_' + ); + } +}