Commit b9af09c
authored
Translate MySQL CONVERT() expressions to SQLite (#356)
## Summary
Fixes #344.
MySQL's `CONVERT()` function was passed through to SQLite unchanged,
causing queries like `SELECT CONVERT('Customer' USING utf8mb4) COLLATE
utf8mb4_bin` to fail with a syntax error.
This PR has two parts:
1. **Extract `simpleExprBody` as a named grammar rule.** The
`%simpleExpr_factored` fragment is promoted to a real `simpleExprBody`
rule so it creates its own AST node. This separates the core expression
(CONVERT, CAST, literals, etc.) from trailing modifiers (COLLATE,
CONCAT_PIPES) that remain in the parent `simpleExpr` node, making
individual expression handlers simpler.
2. **Translate `CONVERT()` expressions.** Adds explicit handling for
both forms of `CONVERT()` in the AST-based driver:
- **`CONVERT(expr, type)`** is translated to `CAST(expr AS type)`,
reusing the existing `castType` translation.
- **`CONVERT(expr USING charset)`** is reduced to just the expression,
as SQLite stores all text as UTF-8 and charset conversions are not
needed.
## Test plan
- [x] Added `testConvert` translation test — verifies SQL-to-SQL
translation for both CONVERT forms and COLLATE.
- [x] Added `testConvertExpression` — verifies CONVERT with type casting
(BINARY, CHAR, SIGNED, UNSIGNED, DECIMAL, DATE).
- [x] Added `testConvertUsingExpression` — verifies CONVERT with charset
conversion (utf8mb4, utf8, latin1).
- [x] Added `testConvertUsingWithCollate` — verifies the exact query
from #344.
- [x] Added `testConvertWithColumnReferences` — verifies CONVERT with
column references in SELECT, WHERE, and ORDER BY.
- [x] Full test suite passes (640 tests, 0 failures).
- [x] PHPCS passes.1 parent ee854d2 commit b9af09c
File tree
6 files changed
+157
-16
lines changed- .github/workflows
- grammar-tools
- packages/mysql-on-sqlite
- src
- mysql
- sqlite
- tests
6 files changed
+157
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2961 | 2961 | | |
2962 | 2962 | | |
2963 | 2963 | | |
2964 | | - | |
| 2964 | + | |
2965 | 2965 | | |
2966 | 2966 | | |
2967 | 2967 | | |
2968 | | - | |
| 2968 | + | |
2969 | 2969 | | |
2970 | | - | |
| 2970 | + | |
2971 | 2971 | | |
2972 | 2972 | | |
2973 | 2973 | | |
| |||
Large diffs are not rendered by default.
Lines changed: 32 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3691 | 3691 | | |
3692 | 3692 | | |
3693 | 3693 | | |
3694 | | - | |
3695 | | - | |
| 3694 | + | |
| 3695 | + | |
3696 | 3696 | | |
3697 | 3697 | | |
3698 | 3698 | | |
| |||
3790 | 3790 | | |
3791 | 3791 | | |
3792 | 3792 | | |
| 3793 | + | |
| 3794 | + | |
3793 | 3795 | | |
3794 | 3796 | | |
3795 | 3797 | | |
| |||
4204 | 4206 | | |
4205 | 4207 | | |
4206 | 4208 | | |
4207 | | - | |
| 4209 | + | |
4208 | 4210 | | |
4209 | | - | |
| 4211 | + | |
4210 | 4212 | | |
4211 | 4213 | | |
4212 | 4214 | | |
4213 | | - | |
| 4215 | + | |
4214 | 4216 | | |
4215 | 4217 | | |
4216 | 4218 | | |
| |||
4221 | 4223 | | |
4222 | 4224 | | |
4223 | 4225 | | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
| 4237 | + | |
| 4238 | + | |
| 4239 | + | |
| 4240 | + | |
| 4241 | + | |
| 4242 | + | |
| 4243 | + | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
4224 | 4248 | | |
4225 | 4249 | | |
4226 | 4250 | | |
| |||
5350 | 5374 | | |
5351 | 5375 | | |
5352 | 5376 | | |
5353 | | - | |
5354 | | - | |
| 5377 | + | |
| 5378 | + | |
5355 | 5379 | | |
5356 | 5380 | | |
5357 | 5381 | | |
5358 | | - | |
| 5382 | + | |
5359 | 5383 | | |
5360 | 5384 | | |
5361 | 5385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9971 | 9971 | | |
9972 | 9972 | | |
9973 | 9973 | | |
9974 | | - | |
| 9974 | + | |
| 9975 | + | |
9975 | 9976 | | |
9976 | 9977 | | |
9977 | 9978 | | |
| |||
9986 | 9987 | | |
9987 | 9988 | | |
9988 | 9989 | | |
| 9990 | + | |
| 9991 | + | |
| 9992 | + | |
| 9993 | + | |
| 9994 | + | |
| 9995 | + | |
| 9996 | + | |
| 9997 | + | |
| 9998 | + | |
| 9999 | + | |
| 10000 | + | |
| 10001 | + | |
| 10002 | + | |
| 10003 | + | |
| 10004 | + | |
| 10005 | + | |
| 10006 | + | |
| 10007 | + | |
| 10008 | + | |
| 10009 | + | |
| 10010 | + | |
| 10011 | + | |
| 10012 | + | |
| 10013 | + | |
| 10014 | + | |
| 10015 | + | |
| 10016 | + | |
| 10017 | + | |
| 10018 | + | |
| 10019 | + | |
| 10020 | + | |
| 10021 | + | |
| 10022 | + | |
| 10023 | + | |
| 10024 | + | |
| 10025 | + | |
| 10026 | + | |
| 10027 | + | |
| 10028 | + | |
| 10029 | + | |
| 10030 | + | |
| 10031 | + | |
| 10032 | + | |
| 10033 | + | |
| 10034 | + | |
| 10035 | + | |
| 10036 | + | |
| 10037 | + | |
| 10038 | + | |
| 10039 | + | |
| 10040 | + | |
| 10041 | + | |
| 10042 | + | |
| 10043 | + | |
| 10044 | + | |
| 10045 | + | |
| 10046 | + | |
| 10047 | + | |
| 10048 | + | |
| 10049 | + | |
| 10050 | + | |
| 10051 | + | |
| 10052 | + | |
| 10053 | + | |
| 10054 | + | |
| 10055 | + | |
| 10056 | + | |
| 10057 | + | |
| 10058 | + | |
| 10059 | + | |
| 10060 | + | |
| 10061 | + | |
| 10062 | + | |
| 10063 | + | |
| 10064 | + | |
| 10065 | + | |
| 10066 | + | |
| 10067 | + | |
| 10068 | + | |
| 10069 | + | |
| 10070 | + | |
| 10071 | + | |
| 10072 | + | |
| 10073 | + | |
9989 | 10074 | | |
9990 | 10075 | | |
9991 | 10076 | | |
| |||
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
104 | 139 | | |
105 | 140 | | |
106 | 141 | | |
| |||
0 commit comments