Skip to content

Commit c156cf1

Browse files
youknowriadclaudeJanJakes
authored
Fix BINARY and VARBINARY column defaults (#596)
Literal defaults on `BINARY` and `VARBINARY` columns are stored as written and then treated as text, which breaks them in two ways: - **Exports don't import.** `SHOW CREATE TABLE` turns `x'00…'` into the string `'x''00…'''`, and MySQL and MariaDB reject it with `Invalid default value`. A shorter value can load but then stores the text `0xDEADBEEF` rather than those bytes. This is blocking a WordPress Studio user from pushing a site with Wordfence tables. - **Inserts fail.** An insert that omits such a column fails with `cannot store TEXT value in BLOB column`, whatever form the default takes, including `''` and `'\0…'`. See the [comment on #551](#551 (comment)). **This change handles these defaults as bytes, following the approach suggested on #551.** - Defaults are read from the parsed literal, so the text `'0x41'` stays distinct from the hex literal `0x41`, and stored in hex as `0x41`, like MySQL's `INFORMATION_SCHEMA`. - They are written to SQLite as blobs, so inserts work. - `SHOW CREATE TABLE` matches MySQL: a quoted string such as `'\0\0'` for valid UTF-8, and `0xDEADBEEF` otherwise. - Rebuilding missing table metadata reads these defaults back as the same bytes. **Existing tables are migrated when the driver is upgraded.** Older versions stored these defaults as written (`x'…'`, `0x…`, `b'…'`, `0b…`, text and raw bytes), and they gave the SQLite tables text defaults. The upgrade stores these defaults in hex and rebuilds the affected tables, including tables with binary expression defaults, so their exports and inserts work. **Three neighbouring bugs are fixed as well, since they'd otherwise undermine this one:** - **Charset prefixes:** `_binary'abc'` and `N'abc'` kept their prefix in the default, on every column type. With binary defaults now working, inserts would have silently stored `_binaryabc`. MySQL stores `abc`, and now so does the driver. - **National strings:** `N'abc'` in a query failed with `no such column: N` or a syntax error. It now works like `'abc'`, and its column is named `abc`, as in MySQL. - **Generated defaults:** `DEFAULT ('abc')` on a `BINARY`, `VARBINARY` or `BLOB` column failed on insert with the same `cannot store TEXT value in BLOB column` error. These are now cast to a blob. This only covers defaults on binary columns and these cases, so it's related to #551 but doesn't close it. ## Limitations - **Older stored text:** a text default stored by an older version that looks like a literal, such as `x'41'`, can't be told apart from the hex literal, so the migration reads it as hex. - **Existing rows:** the migration doesn't change them. Only the unsafe mode for SQLite < 3.37, which doesn't check types, can have rows that got the old text defaults. - **Migration timing:** the migration runs when the driver version changes. A build of this branch before the next version bump handles old defaults as before. - **`BINARY` padding:** defaults aren't padded to the column length, which matches how the driver stores other `BINARY` values. MySQL shows `'A\0\0\0'` for `BINARY(4) DEFAULT 'A'` where this shows `'A'`, and the padding is applied when that's imported into MySQL. - **Zero bytes:** `INFORMATION_SCHEMA` keeps the full value, while MySQL cuts it at the first zero byte, such as `0x41` for `'A\0'` and `0x` for `'\0\0'`. ## API changes - `INFORMATION_SCHEMA.COLUMNS` and `SHOW COLUMNS` now report these defaults in hex. - `WP_SQLite_Information_Schema_Builder` gains a public static `get_binary_default_bytes()`, which the migration uses to read the forms older versions stored. - `WP_MySQL_Token::get_value()` now unquotes `NCHAR_TEXT` tokens, in both `mysql-on-sqlite` and `mysql-parser`. ## Testing - Added tests for each literal form, `ALTER COLUMN … SET DEFAULT`, the migration of stored forms from older versions, metadata recovery, charset prefixes, national strings and generated defaults. - I compared the expected output with real MySQL 8.4 and MariaDB 10.11, and loaded the patched `SHOW CREATE TABLE` output into both. MariaDB also needed the `utf8mb4_0900_ai_ci` collation swapped, which is a separate known issue. Default bytes were exact on both. - With an earlier version of this change, which read the old forms directly instead of migrating them, real Wordfence 9.0.2 tables created with hex defaults by the old driver exported correctly end to end through WordPress Studio. The full dump restored on both servers. `INSERT … VALUES (…, DEFAULT)` fails with a syntax error for every column type on `trunk`, including `INT`. That's separate, so it isn't covered here. So is `DEFAULT (_utf8mb4'abc')`, the form MySQL 8 prints for expression defaults, which fails at `CREATE TABLE` with a syntax error for every string column type I tried, on `trunk` too. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of binary-column defaults, including hexadecimal, bit-pattern, and expression-based defaults. Values display consistently in table definitions and column metadata. - Binary defaults with valid UTF-8 bytes display as text; other byte values remain in hexadecimal. Defaults from older versions are handled correctly, and affected existing databases are updated. - National string literals are decoded consistently in queries and defaults, including when their contents resemble SQL syntax. - **Tests** - Added coverage for binary defaults, default changes, database migrations, and national string literals. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jan Jakeš <jan@jakes.pro>
1 parent 6b22c0e commit c156cf1

11 files changed

Lines changed: 616 additions & 31 deletions

‎packages/mysql-on-sqlite/src/mysql/class-wp-mysql-token.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ public function get_name(): string {
6464
*/
6565
public function get_value(): string {
6666
$value = $this->get_bytes();
67+
if ( WP_MySQL_Lexer::NCHAR_TEXT === $this->id ) {
68+
// Remove the national string prefix.
69+
$value = substr( $value, 1 );
70+
}
6771
if (
6872
WP_MySQL_Lexer::SINGLE_QUOTED_TEXT === $this->id
6973
|| WP_MySQL_Lexer::DOUBLE_QUOTED_TEXT === $this->id
74+
|| WP_MySQL_Lexer::NCHAR_TEXT === $this->id
7075
|| WP_MySQL_Lexer::BACK_TICK_QUOTED_ID === $this->id
7176
) {
7277
// Remove bounding quotes.

‎packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php‎

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,7 +4383,7 @@ private function translate( $node ): ?string {
43834383
}
43844384
return $value;
43854385
case 'textStringLiteral':
4386-
return $this->translate_string_literal( $node );
4386+
return $this->translate_string_literal( $node->get_first_child_token() );
43874387
case 'dataType':
43884388
case 'nchar':
43894389
$child = $node->get_first_child();
@@ -4607,6 +4607,9 @@ private function translate_token( WP_MySQL_Token $token ): ?string {
46074607
return sprintf( "x'%s'", $hex );
46084608
}
46094609
return $value;
4610+
case WP_MySQL_Lexer::NCHAR_TEXT:
4611+
// A national string, such as N'abc', is a regular string in SQLite.
4612+
return $this->translate_string_literal( $token );
46104613
case WP_MySQL_Lexer::AUTO_INCREMENT_SYMBOL:
46114614
return 'AUTOINCREMENT';
46124615
case WP_MySQL_Lexer::BINARY_SYMBOL:
@@ -4657,11 +4660,10 @@ private function translate_sequence( array $nodes, string $separator = ' ' ): ?s
46574660
/**
46584661
* Translate a MySQL string literal to SQLite.
46594662
*
4660-
* @param WP_Parser_Node $node The "textStringLiteral" AST node.
4661-
* @return string The translated value.
4663+
* @param WP_MySQL_Token $token The string literal token.
4664+
* @return string The translated value.
46624665
*/
4663-
private function translate_string_literal( WP_Parser_Node $node ): string {
4664-
$token = $node->get_first_child_token();
4666+
private function translate_string_literal( WP_MySQL_Token $token ): string {
46654667
$value = $token->get_value();
46664668

46674669
/*
@@ -5591,6 +5593,7 @@ private function translate_select_item( WP_Parser_Node $node ): string {
55915593
*
55925594
* Descend the AST until we reach a textStringLiteral. If at any level
55935595
* we don't have a single child node, bail out; it's not a bare literal.
5596+
* A national string, such as N'abc', is a single NCHAR_TEXT token.
55945597
*/
55955598
$current = $node;
55965599
while ( 'textStringLiteral' !== $current->rule_name ) {
@@ -5600,7 +5603,10 @@ private function translate_select_item( WP_Parser_Node $node ): string {
56005603
}
56015604
$current = $children[0];
56025605
}
5603-
if ( 'textStringLiteral' === $current->rule_name ) {
5606+
if (
5607+
'textStringLiteral' === $current->rule_name
5608+
|| ( 1 === count( $current->get_children() ) && $current->has_child_token( WP_MySQL_Lexer::NCHAR_TEXT ) )
5609+
) {
56045610
$alias = $current->get_first_child_token()->get_value();
56055611

56065612
// When the literal value contains a NULL byte, MySQL truncates the
@@ -7413,7 +7419,11 @@ private function get_sqlite_create_table_statement(
74137419
$ast = $this->create_parser( 'SELECT ' . $column['COLUMN_DEFAULT'] )->parse();
74147420
$expr = $ast->get_first_descendant_node( 'selectItem' )->get_first_child_node();
74157421
$default_clause = $this->translate( $expr );
7416-
$query .= sprintf( ' DEFAULT (%s)', $default_clause );
7422+
if ( 'BLOB' === $type ) {
7423+
// STRICT tables reject a TEXT default in a BLOB column.
7424+
$default_clause = sprintf( 'CAST(%s AS BLOB)', $default_clause );
7425+
}
7426+
$query .= sprintf( ' DEFAULT (%s)', $default_clause );
74177427
} else {
74187428
$query .= ' DEFAULT ' . $this->format_sqlite_column_default( $column );
74197429
}
@@ -7899,6 +7909,12 @@ private function format_sqlite_column_default( array $column ): string {
78997909
return (string) bindec( substr( $column['COLUMN_DEFAULT'], 2, -1 ) );
79007910
}
79017911

7912+
// A BLOB column in a STRICT table only accepts a BLOB default.
7913+
$bytes = $this->get_binary_column_default_bytes( $column );
7914+
if ( null !== $bytes ) {
7915+
return sprintf( "x'%s'", bin2hex( $bytes ) );
7916+
}
7917+
79027918
return $this->quote_sqlite_value( $column['COLUMN_DEFAULT'] );
79037919
}
79047920

@@ -7914,9 +7930,38 @@ private function format_mysql_column_default( array $column ): string {
79147930
return $column['COLUMN_DEFAULT'];
79157931
}
79167932

7933+
// Like MySQL, keep the hex literal for bytes that aren't valid utf8mb3,
7934+
// i.e., UTF-8 with no characters above U+FFFF.
7935+
$bytes = $this->get_binary_column_default_bytes( $column );
7936+
if ( null !== $bytes ) {
7937+
return 1 === preg_match( '/\A[\x{0}-\x{FFFF}]*\z/u', $bytes )
7938+
? $this->quote_mysql_utf8_string_literal( $bytes )
7939+
: $column['COLUMN_DEFAULT'];
7940+
}
7941+
79177942
return $this->quote_mysql_utf8_string_literal( $column['COLUMN_DEFAULT'] );
79187943
}
79197944

7945+
/**
7946+
* Get the bytes of a BINARY or VARBINARY column default.
7947+
*
7948+
* These defaults are stored as "0x..." hex literals, or as an empty string.
7949+
* The forms that older driver versions stored are migrated to this format.
7950+
*
7951+
* @param array $column The information schema column data.
7952+
* @return string|null The default value bytes, or null when the column
7953+
* is not binary or its default is not migrated.
7954+
*/
7955+
private function get_binary_column_default_bytes( array $column ): ?string {
7956+
if (
7957+
( 'binary' !== $column['DATA_TYPE'] && 'varbinary' !== $column['DATA_TYPE'] )
7958+
|| 1 !== preg_match( '/\A(?:0x((?:[0-9A-F]{2})+))?\z/', $column['COLUMN_DEFAULT'], $matches )
7959+
) {
7960+
return null;
7961+
}
7962+
return hex2bin( $matches[1] ?? '' );
7963+
}
7964+
79207965
/**
79217966
* Unquote a quoted SQLite identifier.
79227967
*

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-configurator.php‎

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ private function run_migrations( string $saved_version ): void {
345345
$this->migrate_datetime_precision();
346346
$this->migrate_temporal_zero_defaults();
347347
}
348+
349+
// Fix binary column defaults stored by versions <= 3.1.2.
350+
if ( version_compare( $saved_version, '3.1.2', '<=' ) ) {
351+
$this->migrate_binary_defaults();
352+
}
348353
}
349354

350355
/**
@@ -484,7 +489,7 @@ private function migrate_temporal_zero_defaults(): void {
484489
);
485490
}
486491

487-
$alter_list = array();
492+
$defaults = array();
488493
foreach ( $repaired_columns as $column ) {
489494
// Preserve numeric and string types so comparisons apply the same
490495
// SQLite conversion as when the defaults were stored.
@@ -502,26 +507,95 @@ private function migrate_temporal_zero_defaults(): void {
502507
: array( $column['zero_value'] )
503508
);
504509

505-
$alter_list[] = sprintf(
506-
'ALTER COLUMN `%s` SET DEFAULT %s',
507-
str_replace( '`', '``', $column['name'] ),
508-
$this->driver->quote( $column['zero_value'] )
509-
);
510+
$defaults[ $column['name'] ] = $this->driver->quote( $column['zero_value'] );
510511
}
512+
$this->recreate_table( $table_name, $defaults );
513+
}
514+
}
511515

512-
// ALTER TABLE stores the new defaults, and it recreates the table to apply them.
513-
try {
514-
$this->driver->query(
515-
sprintf( 'ALTER TABLE `%s` %s', str_replace( '`', '``', $table_name ), implode( ', ', $alter_list ) )
516-
);
517-
} catch ( WP_MySQL_On_SQLite_Exception $e ) {
518-
throw new WP_MySQL_On_SQLite_Exception(
519-
$this->driver,
520-
sprintf( 'Failed to recreate table "%s": %s', $table_name, $e->getMessage() ),
521-
$e->getCode(),
522-
$e
523-
);
516+
/**
517+
* Migrate binary column defaults stored by older driver versions.
518+
*
519+
* Older driver versions stored BINARY and VARBINARY defaults as written, such
520+
* as x'00', while MySQL stores their bytes in hex, such as 0x00. They also gave
521+
* the SQLite tables TEXT defaults for these and for binary expression defaults,
522+
* which STRICT tables reject in BLOB columns, so inserts omitting them failed.
523+
*/
524+
private function migrate_binary_defaults(): void {
525+
$columns_table = $this->driver->get_connection()->quote_identifier(
526+
$this->schema_builder->get_table_name( false, 'columns' )
527+
);
528+
529+
$columns = $this->driver->execute_sqlite_query(
530+
sprintf(
531+
"SELECT c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.COLUMN_DEFAULT, c.EXTRA, p.dflt_value
532+
FROM %s AS c
533+
JOIN pragma_table_info(c.TABLE_NAME, 'main') AS p ON c.COLUMN_NAME = p.name
534+
WHERE c.TABLE_SCHEMA = ?
535+
AND c.DATA_TYPE IN ('binary', 'varbinary', 'tinyblob', 'blob', 'mediumblob', 'longblob')
536+
AND c.COLUMN_DEFAULT IS NOT NULL",
537+
$columns_table
538+
),
539+
array( WP_SQLite_Information_Schema_Builder::SAVED_DATABASE_NAME )
540+
)->fetchAll( PDO::FETCH_ASSOC );
541+
542+
$table_defaults = array();
543+
foreach ( $columns as $column ) {
544+
$table_name = $column['TABLE_NAME'];
545+
$sqlite_default = (string) $column['dflt_value'];
546+
if ( str_contains( $column['EXTRA'], 'DEFAULT_GENERATED' ) ) {
547+
// Recreating the table casts the expression to BLOB.
548+
if ( 1 !== preg_match( '/\ACAST\(.* AS BLOB\)\z/s', $sqlite_default ) ) {
549+
$table_defaults[ $table_name ] = $table_defaults[ $table_name ] ?? array();
550+
}
551+
} elseif ( 'binary' === $column['DATA_TYPE'] || 'varbinary' === $column['DATA_TYPE'] ) {
552+
// A literal default is stored as "0x..." and used as "x'...'" in SQLite.
553+
if (
554+
1 !== preg_match( '/\A(?:0x(?:[0-9A-F]{2})+)?\z/', $column['COLUMN_DEFAULT'] )
555+
|| 1 !== preg_match( "/\A[xX]'[0-9a-fA-F]*'\z/", $sqlite_default )
556+
) {
557+
$bytes = WP_SQLite_Information_Schema_Builder::get_binary_default_bytes( $column['COLUMN_DEFAULT'] );
558+
559+
$table_defaults[ $table_name ][ $column['COLUMN_NAME'] ] = '' === $bytes ? "''" : '0x' . bin2hex( $bytes );
560+
}
524561
}
525562
}
563+
564+
foreach ( $table_defaults as $table_name => $defaults ) {
565+
$this->recreate_table( $table_name, $defaults );
566+
}
567+
}
568+
569+
/**
570+
* Recreate a table with new column defaults.
571+
*
572+
* ALTER TABLE stores the new defaults, and it recreates the table to apply them.
573+
* Without new defaults, ALTER TABLE ... FORCE only recreates the table.
574+
*
575+
* @param string $table_name The table name.
576+
* @param array $defaults The new defaults as MySQL literals, keyed by column name.
577+
*/
578+
private function recreate_table( string $table_name, array $defaults ): void {
579+
$alter_list = array();
580+
foreach ( $defaults as $column_name => $default ) {
581+
$alter_list[] = sprintf( 'ALTER COLUMN `%s` SET DEFAULT %s', str_replace( '`', '``', $column_name ), $default );
582+
}
583+
584+
try {
585+
$this->driver->query(
586+
sprintf(
587+
'ALTER TABLE `%s` %s',
588+
str_replace( '`', '``', $table_name ),
589+
count( $alter_list ) > 0 ? implode( ', ', $alter_list ) : 'FORCE'
590+
)
591+
);
592+
} catch ( WP_MySQL_On_SQLite_Exception $e ) {
593+
throw new WP_MySQL_On_SQLite_Exception(
594+
$this->driver,
595+
sprintf( 'Failed to recreate table "%s": %s', $table_name, $e->getMessage() ),
596+
$e->getCode(),
597+
$e
598+
);
599+
}
526600
}
527601
}

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-information-schema-builder.php‎

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,33 @@ public function record_drop_index( WP_Parser_Node $node ): void {
878878
$this->record_drop_index_data( $table_is_temporary, $table_name, $index_name );
879879
}
880880

881+
/**
882+
* Get the bytes of a BINARY or VARBINARY default from a hex or bit literal.
883+
*
884+
* Older driver versions stored these defaults as written, so this also reads
885+
* any other value as the bytes of a text default, for their migration.
886+
*
887+
* @param string $default_value A hex or bit literal, or a default stored by an older version.
888+
* @return string The default value bytes.
889+
*/
890+
public static function get_binary_default_bytes( string $default_value ): string {
891+
if ( 1 === preg_match( "/\A(?|0x([0-9a-fA-F]+)|[xX]'([0-9a-fA-F]*)')\z/", $default_value, $matches ) ) {
892+
// MySQL pads odd-length 0x literals with a leading zero.
893+
return hex2bin( 1 === strlen( $matches[1] ) % 2 ? '0' . $matches[1] : $matches[1] );
894+
}
895+
896+
if ( 1 === preg_match( "/\A(?|0b([01]+)|[bB]'([01]*)')\z/", $default_value, $matches ) ) {
897+
$bits = str_pad( $matches[1], (int) ceil( strlen( $matches[1] ) / 8 ) * 8, '0', STR_PAD_LEFT );
898+
$bytes = '';
899+
for ( $i = 0; $i < strlen( $bits ); $i += 8 ) {
900+
$bytes .= chr( bindec( substr( $bits, $i, 8 ) ) );
901+
}
902+
return $bytes;
903+
}
904+
905+
return $default_value;
906+
}
907+
881908
/**
882909
* Analyze ADD COLUMN definition and record data in the information schema.
883910
*
@@ -2274,6 +2301,10 @@ private function get_literal_default( WP_Parser_Node $literal, string $data_type
22742301
return null;
22752302
}
22762303

2304+
if ( 'binary' === $data_type || 'varbinary' === $data_type ) {
2305+
return $this->get_binary_literal_default( $literal );
2306+
}
2307+
22772308
// DEFAULT TRUE or DEFAULT FALSE
22782309
if ( $literal->has_child_node( 'boolLiteral' ) ) {
22792310
$bool_literal = $literal->get_first_child_node( 'boolLiteral' );
@@ -2315,19 +2346,57 @@ private function normalize_literal_default( string $default_value, string $data_
23152346
return $bit_default;
23162347
}
23172348

2349+
if ( 'binary' === $data_type || 'varbinary' === $data_type ) {
2350+
return $this->format_binary_default( $default_value );
2351+
}
2352+
23182353
/*
2319-
* @TODO: Non-BIT literal defaults, except for temporal zero values, are
2354+
* @TODO: Other literal defaults, except for temporal zero values, are
23202355
* currently stored verbatim. To match MySQL, they should be normalized.
23212356
* For example:
2322-
* - BINARY/VARBINARY defaults stored as 0x hex literals.
23232357
* - Hex and bit literals coerced to raw bytes for text columns and to
23242358
* their decimal value for numeric columns.
2325-
* - The charset introducer dropped from text-literal defaults.
23262359
* - Numeric defaults normalized, e.g. 1.0 to 1 or 1e3 to 1000.
23272360
*/
23282361
return $default_value;
23292362
}
23302363

2364+
/**
2365+
* Get the default of a BINARY or VARBINARY column from a literal.
2366+
*
2367+
* Hex and bit literals are byte strings. Other literals give the bytes of
2368+
* their text, so the text '0x41' stays distinct from the hex literal 0x41.
2369+
*
2370+
* @param WP_Parser_Node $literal The "literal" AST node.
2371+
* @return string The default value as stored in information schema.
2372+
*/
2373+
private function get_binary_literal_default( WP_Parser_Node $literal ): string {
2374+
$byte_string = $literal->get_first_child_token( WP_MySQL_Lexer::HEX_NUMBER )
2375+
?? $literal->get_first_child_token( WP_MySQL_Lexer::BIN_NUMBER );
2376+
if ( null !== $byte_string ) {
2377+
return $this->format_binary_default( self::get_binary_default_bytes( $byte_string->get_value() ) );
2378+
}
2379+
2380+
$bool_literal = $literal->get_first_child_node( 'boolLiteral' );
2381+
if ( null !== $bool_literal ) {
2382+
return $this->format_binary_default( $bool_literal->has_child_token( WP_MySQL_Lexer::TRUE_SYMBOL ) ? '1' : '0' );
2383+
}
2384+
2385+
return $this->format_binary_default( $this->get_value( $literal ) );
2386+
}
2387+
2388+
/**
2389+
* Format the bytes of a BINARY or VARBINARY default for the information schema.
2390+
*
2391+
* Like in MySQL, the bytes are shown in hex, except for an empty default.
2392+
*
2393+
* @param string $bytes The default value bytes.
2394+
* @return string The default value as stored in information schema.
2395+
*/
2396+
private function format_binary_default( string $bytes ): string {
2397+
return '' === $bytes ? '' : '0x' . strtoupper( bin2hex( $bytes ) );
2398+
}
2399+
23312400
/**
23322401
* Get the zero value of a temporal column when its default is zero.
23332402
*
@@ -3310,6 +3379,9 @@ private function get_value( WP_Parser_Node $node ): string {
33103379
}
33113380
}
33123381
}
3382+
} elseif ( WP_MySQL_Lexer::UNDERSCORE_CHARSET === $child->id ) {
3383+
// A charset introducer isn't part of the value.
3384+
continue;
33133385
} else {
33143386
$value = $child->get_value();
33153387
}

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-information-schema-reconstructor.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ private function generate_column_default( string $mysql_type, ?string $default_v
600600
// BLOB literals (string). E.g.: x'1a2f', X'1A2F'
601601
// Checking the prefix is enough as SQLite doesn't allow malformed values.
602602
if ( str_starts_with( $uppercase_default_value, "X'" ) ) {
603-
// Convert the hex string to ASCII bytes.
604-
return "'" . pack( 'H*', substr( $default_value, 2, -1 ) ) . "'";
603+
// Convert the hex string to bytes, and quote them as a string literal.
604+
return $this->quote_mysql_utf8_string_literal( pack( 'H*', substr( $default_value, 2, -1 ) ) );
605605
}
606606

607607
// Unquoted string literal. E.g.: abc

0 commit comments

Comments
 (0)