Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4579,8 +4579,9 @@ private function translate_token( WP_MySQL_Token $token ): ?string {
$value = substr( $value, 2, -1 );
}

// Convert the binary string to HEX.
$hex = base_convert( $value, 2, 16 );
// Convert the binary string to HEX. An empty value stays empty,
// as "base_convert()" would return "0" for it.
$hex = '' === $value ? '' : base_convert( $value, 2, 16 );
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/*
* The "base_convert()" function doesn't add or preserve padding.
Expand Down
42 changes: 42 additions & 0 deletions packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11997,6 +11997,48 @@ public static function oddLengthQuotedHexadecimalLiterals(): array {
);
}

public function testEmptyBitLiteral(): void {
// An empty bit-value literal is an empty binary string, like an empty
// hex literal, and not the one-byte value "x'0'". See #612.
$this->assertEquals(
$this->assertQuery( "SELECT x'' AS v" ),
$this->assertQuery( "SELECT b'' AS v" )
);
$this->assertEquals(
array( (object) array( 'length' => '0' ) ),
$this->assertQuery( "SELECT LENGTH(b'') AS length" )
);

$this->assertQuery( 'CREATE TABLE t (id INT PRIMARY KEY, data BLOB)' );
$this->assertQuery( "INSERT INTO t (id, data) VALUES (1, b'')" );
$this->assertEquals(
array(
(object) array(
'id' => '1',
'data' => '',
),
),
$this->assertQuery( 'SELECT id, HEX(data) AS data FROM t' )
);
}

public function testEmptyBitLiteralComparesLikeEmptyHexLiteral(): void {
// Hex and bit literals translate to blob literals, and a blob never
// equals a text value in SQLite. MySQL compares the empty binary
// string equal to the empty text string, a difference tracked for
// hex literals in #575. The empty bit literal behaves like the empty
// hex literal, in both directions.
$this->assertEquals(
$this->assertQuery( "SELECT x'' = '' AS v" ),
$this->assertQuery( "SELECT b'' = '' AS v" )
);

$this->assertEquals(
array( (object) array( 'v' => '1' ) ),
$this->assertQuery( "SELECT b'' = x'' AS v" )
);
}

public function testColumnInfo(): void {
$this->assertQuery(
'CREATE TABLE t (
Expand Down
Loading