Skip to content

Commit

Permalink
Merge branch '5.10.x' into 5.11.x
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Nov 10, 2024
2 parents 4652d80 + b14fd66 commit a05588a
Show file tree
Hide file tree
Showing 11 changed files with 1,614 additions and 313 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [5.10.1] - 2024-11-10

### Fixed

- Fix parsing of ALTER TABLE … RENAME KEY (#580)
- Fix parsing table names that start with "e1" (#578)
- Improve handling of negative and overflowed offsets on TokensList (#582)
- Fix parsing of queries with 'AND' (#590)
- Fix C style comments with two asterisks (#597)
- Fix parsing of SRID in column definition (#595)

## [5.10.0] - 2024-08-29

- Fix parsing of UPDATE ... SET (#577)
Expand Down Expand Up @@ -579,6 +590,7 @@ __Breaking changes:__

* First release of this library.

[5.10.1]: https://github.com/phpmyadmin/sql-parser/compare/5.10.0...5.10.1
[5.10.0]: https://github.com/phpmyadmin/sql-parser/compare/5.9.1...5.10.0
[5.9.1]: https://github.com/phpmyadmin/sql-parser/compare/5.9.0...5.9.1
[5.9.0]: https://github.com/phpmyadmin/sql-parser/compare/5.8.2...5.9.0
4 changes: 4 additions & 0 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class CreateDefinition extends Component
'ENFORCED' => 14,
'NOT' => 15,
'COMPRESSED' => 16,
'SRID' => [
17,
'var',
],
// Common entries.
//
// NOTE: Some of the common options are not in the same order which
Expand Down
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public function parseComment()
// - "SELECT */* comment */ FROM ..."
// - "SELECT 2*/* comment */3 AS `six`;"
$next = $this->last + 1;
if (($next < $this->len) && $this->str[$next] === '*') {
if (($next < $this->len) && $this->str[$next] === '*' && $token === '*/') {
// Conflict in "*/*": first "*" was not for ending a comment.
// Stop here and let other parsing method define the true behavior of that first star.
$this->last = $iBak;
Expand Down
1 change: 1 addition & 0 deletions tests/Lexer/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static function lexProvider(): array
['lexer/lexOperator'],
['lexer/lexOperatorStarIsArithmetic'],
['lexer/lexOperatorStarIsWildcard'],
['lexer/lexEmptyCStyleComment'],
['lexer/lexString'],
['lexer/lexStringErr1'],
['lexer/lexSymbol'],
Expand Down
1 change: 1 addition & 0 deletions tests/Parser/CreateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static function createProvider(): array
['parser/parseCreateTableAsSelect'],
['parser/parseCreateTableLike'],
['parser/parseCreateTableSpatial'],
['parser/parseCreateTableSRID'],
['parser/parseCreateTableTimestampWithPrecision'],
['parser/parseCreateTableEnforcedCheck'],
['parser/parseCreateTableNotEnforcedCheck'],
Expand Down
5 changes: 5 additions & 0 deletions tests/data/lexer/lexEmptyCStyleComment.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT /**/ 1
SELECT /*+*/ 1
SELECT /***/ 1
SELECT /** */ 1
SELECT /* **/ 1
304 changes: 304 additions & 0 deletions tests/data/lexer/lexEmptyCStyleComment.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
{
"query": "SELECT /**/ 1\nSELECT /*+*/ 1\nSELECT /***/ 1\nSELECT /** */ 1\nSELECT /* **/ 1\n",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "SELECT /**/ 1\nSELECT /*+*/ 1\nSELECT /***/ 1\nSELECT /** */ 1\nSELECT /* **/ 1\n",
"len": 76,
"last": 76,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/**/",
"value": "/**/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 13
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 14
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 20
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/*+*/",
"value": "/*+*/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 21
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 26
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 27
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 28
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 29
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 35
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/***/",
"value": "/***/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 36
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 41
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 42
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 43
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 44
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 50
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/** */",
"value": "/** */",
"keyword": null,
"type": 4,
"flags": 2,
"position": 51
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 57
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 58
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 59
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 60
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 66
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/* **/",
"value": "/* **/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 67
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 73
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 74
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 75
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 31,
"idx": 0
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": null,
"errors": {
"lexer": [],
"parser": []
}
}
4 changes: 2 additions & 2 deletions tests/data/lexer/lexOperatorStarIsWildcard.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SELECT a.*, b.* FROM
SELECT a.*, /* with a comment */ b.* FROM
SELECT a.*,/* with a comment */b.* FROM
SELECT a.* /* comment */ FROM
-- SELECT a.*/* comment */ FROM (This one is not working yet because of https://github.com/phpmyadmin/sql-parser/issues/285. Please uncomment when this issue is fixed.)
SELECT a.*/* comment */ FROM
SELECT DISTINCT * FROM
SELECT DISTINCT *FROM
SELECT DISTINCT a.* FROM
Expand All @@ -15,7 +15,7 @@ SELECT DISTINCT a.*, b.* FROM
SELECT DISTINCT a.*, /* with a comment */ b.* FROM
SELECT DISTINCT a.*,/* with a comment */b.* FROM
SELECT DISTINCT a.* /* comment */ FROM
-- SELECT DISTINCT a.*/* comment */ FROM (This one is not working yet because of https://github.com/phpmyadmin/sql-parser/issues/285. Please uncomment when this issue is fixed.)
SELECT DISTINCT a.*/* comment */ FROM
SELECT `*` FROM table_name
SELECT `*`.* FROM table_name AS `*`
SELECT COUNT(*) FROM table_name
Expand Down
Loading

0 comments on commit a05588a

Please sign in to comment.