Commit 488b8db
authored
Pad binary string literals to full bytes as required by SQLite HEX notation (#255)
This fixes the following error:
```bash
SQLSTATE[HY000]: General error: 1 unrecognized token: "x'1'"
```
For queries like the following:
```sql
SELECT 0b1;
SELECT 0b01;
SELECT 0b001;
...
```
SQLite doesn't have binary string literals, so [we need to convert them
to HEX string
literals](#245).
However, HEX string literals in SQLite must be aligned to full bytes
(their length needs to be even) — `x'01'` is valid, while `x'1'` is
invalid.
In MySQL, binary strings don't require such alignment, and `0b1` is
valid (and `SELECT 0b1 = 0b01` returns `true`).
Additionally, the `base_convert()` function used in the [original
implementation](#245)
doesn't preserve existing leading `0` padding.
To solve both of these issues, this PR implements the following:
1. Count how many full bytes the original binary string requires.
2. Make sure the resulting HEX string has that number of bytes, using
leading `0` padding.
For HEX strings, this fix is not needed, as those require to be
byte-aligned also in MySQL, so throwing an error for `x'1'` is actually
correct.1 parent 990a4e2 commit 488b8db
2 files changed
Lines changed: 28 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6896 | 6896 | | |
6897 | 6897 | | |
6898 | 6898 | | |
| 6899 | + | |
| 6900 | + | |
| 6901 | + | |
| 6902 | + | |
| 6903 | + | |
| 6904 | + | |
| 6905 | + | |
| 6906 | + | |
| 6907 | + | |
| 6908 | + | |
| 6909 | + | |
| 6910 | + | |
| 6911 | + | |
| 6912 | + | |
| 6913 | + | |
| 6914 | + | |
6899 | 6915 | | |
6900 | 6916 | | |
6901 | 6917 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2873 | 2873 | | |
2874 | 2874 | | |
2875 | 2875 | | |
2876 | | - | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
2877 | 2888 | | |
2878 | 2889 | | |
2879 | 2890 | | |
| |||
0 commit comments