diff --git a/pegjs/mariadb.pegjs b/pegjs/mariadb.pegjs index e95e65da..e253a0cc 100644 --- a/pegjs/mariadb.pegjs +++ b/pegjs/mariadb.pegjs @@ -2471,10 +2471,12 @@ in_op / KW_IN like_op_right - = op:like_op __ right:(literal / comparison_expr) __ es:escape_op? { - if (es) right.escape = es - return { op: op, right: right }; - } + = op:like_op __ right:(literal / param / comparison_expr ) __ ca:(__ collate_expr)? __ es:escape_op? { + if (es) right.escape = es + if (ca) right.suffix = { collate: ca[1] } + return { op: op, right: right }; + } + regexp_op_right = op:regexp_op __ b:'BINARY'i? __ e:(func_call / literal_string / column_ref) { diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index 53f84d84..aa1263c5 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -2759,8 +2759,9 @@ regexp_op_right } like_op_right - = op:like_op __ right:(literal / comparison_expr) __ es:escape_op? { + = op:like_op __ right:(literal / param / comparison_expr ) __ ca:(__ collate_expr)? __ es:escape_op? { if (es) right.escape = es + if (ca) right.suffix = { collate: ca[1] } return { op: op, right: right }; } @@ -3679,8 +3680,6 @@ KW_COMMENT = "COMMENT"i !ident_start { return 'COMMENT'; } KW_CONSTRAINT = "CONSTRAINT"i !ident_start { return 'CONSTRAINT'; } KW_REFERENCES = "REFERENCES"i !ident_start { return 'REFERENCES'; } - - // MySQL extensions to SQL OPT_SQL_CALC_FOUND_ROWS = "SQL_CALC_FOUND_ROWS"i OPT_SQL_CACHE = "SQL_CACHE"i diff --git a/test/mysql-mariadb.spec.js b/test/mysql-mariadb.spec.js index ae29183d..a4c767f2 100644 --- a/test/mysql-mariadb.spec.js +++ b/test/mysql-mariadb.spec.js @@ -867,6 +867,18 @@ describe('mysql', () => { 'SELECT -`foo` > 0 ; SELECT +`foo` > 0 ; SELECT ~`foo` > 0 ; SELECT !1 > 0' ] }, + { + title: 'like pattern', + sql: [ + `SELECT + * + FROM + test + WHERE + name LIKE :pattern COLLATE utf8mb4_general_ci`, + 'SELECT * FROM `test` WHERE `name` LIKE :pattern COLLATE UTF8MB4_GENERAL_CI' + ] + }, ] SQL_LIST.forEach(sqlInfo => { const { title, sql } = sqlInfo