@@ -11153,15 +11153,82 @@ public function testBinaryLiterals(): void {
1115311153 $this->assertEquals( array( (object) array( '0b000000001' => pack( 'H*', '0001' ) ) ), $result );
1115411154 }
1115511155
11156- public function testHexadecimalLiterals(): void {
11157- $result = $this->assertQuery( 'SELECT 0x417a' );
11158- $this->assertEquals( array( (object) array( '0x417a' => 'Az' ) ), $result );
11156+ /**
11157+ * @dataProvider hexadecimalLiterals
11158+ */
11159+ public function testHexadecimalLiterals( string $literal, string $hex ): void {
11160+ $result = $this->assertQuery( "SELECT $literal" );
11161+ $this->assertEquals( array( (object) array( $literal => hex2bin( $hex ) ) ), $result );
11162+
11163+ $result = $this->assertQuery( "SELECT HEX($literal) AS value" );
11164+ $this->assertSame( $hex, $result[0]->value );
11165+ }
1115911166
11160- $result = $this->assertQuery( "SELECT x'417a'" );
11161- $this->assertEquals( array( (object) array( "x'417a'" => 'Az' ) ), $result );
11167+ public static function hexadecimalLiterals(): array {
11168+ return array(
11169+ array( '0x0', '00' ),
11170+ array( '0x1', '01' ),
11171+ array( '0xF', '0F' ),
11172+ array( '0x711', '0711' ),
11173+ array( '0xaBc', '0ABC' ),
11174+ array( '0x0711', '0711' ),
11175+ array( '0x00711', '000711' ),
11176+ array( '0x000711', '000711' ),
11177+ array( '0x000', '0000' ),
11178+ array( '0x123456789abcdef01', '0123456789ABCDEF01' ),
11179+ array( '0x417a', '417A' ),
11180+ array( "x'417a'", '417A' ),
11181+ array( "X'417a'", '417A' ),
11182+ array( "x''", '' ),
11183+ array( "X''", '' ),
11184+ );
11185+ }
1116211186
11163- $result = $this->assertQuery( "SELECT X'417a'" );
11164- $this->assertEquals( array( (object) array( "X'417a'" => 'Az' ) ), $result );
11187+ public function testOddLengthHexadecimalLiteralsInWrites(): void {
11188+ $this->assertQuery( 'CREATE TABLE t (id INT PRIMARY KEY, title TEXT, name VARCHAR(200), data BLOB)' );
11189+ $this->assertQuery( 'INSERT INTO t (id, title, name, data) VALUES (51701, 0x711, 0x711, 0x711)' );
11190+ $this->assertEquals(
11191+ array(
11192+ (object) array(
11193+ 'id' => '51701',
11194+ 'title' => '0711',
11195+ 'name' => '0711',
11196+ 'data' => '0711',
11197+ ),
11198+ ),
11199+ $this->assertQuery( 'SELECT id, HEX(title) AS title, HEX(name) AS name, HEX(data) AS data FROM t' )
11200+ );
11201+
11202+ $this->assertQuery( 'UPDATE t SET title = 0x00711, name = 0x00711, data = 0x00711 WHERE id = 51701' );
11203+ $this->assertEquals(
11204+ array(
11205+ (object) array(
11206+ 'id' => '51701',
11207+ 'title' => '000711',
11208+ 'name' => '000711',
11209+ 'data' => '000711',
11210+ ),
11211+ ),
11212+ $this->assertQuery( 'SELECT id, HEX(title) AS title, HEX(name) AS name, HEX(data) AS data FROM t' )
11213+ );
11214+ }
11215+
11216+ /**
11217+ * @dataProvider oddLengthQuotedHexadecimalLiterals
11218+ */
11219+ public function testOddLengthQuotedHexadecimalLiteralsAreRejected( string $literal ): void {
11220+ $this->expectException( WP_MySQL_On_SQLite_Exception::class );
11221+ $this->expectExceptionMessage( 'unrecognized token: "' . $literal . '"' );
11222+ $this->assertQuery( "SELECT $literal" );
11223+ }
11224+
11225+ public static function oddLengthQuotedHexadecimalLiterals(): array {
11226+ return array(
11227+ array( "x'1'" ),
11228+ array( "X'1'" ),
11229+ array( "x'711'" ),
11230+ array( "X'711'" ),
11231+ );
1116511232 }
1116611233
1116711234 public function testColumnInfo(): void {
0 commit comments