@@ -818,6 +818,11 @@ public static function data_binary_column_defaults(): array {
818818 'empty text' => array( 'varbinary(4)', "''", "''", '', '' ),
819819 'text like a number' => array( 'varbinary(4)', "'0x41'", "'0x41'", '0x30783431', '30783431' ),
820820 'text like a string' => array( 'varbinary(8)', "'x''41'''", "'x''41'''", '0x7827343127', '7827343127' ),
821+ 'binary introducer' => array( 'varbinary(4)', "_binary'abc'", "'abc'", '0x616263', '616263' ),
822+ 'charset introducer' => array( 'varbinary(4)', "_utf8mb4'abc'", "'abc'", '0x616263', '616263' ),
823+ 'hex introducer' => array( 'varbinary(4)', '_binary 0x616263', "'abc'", '0x616263', '616263' ),
824+ 'national string' => array( 'varbinary(4)', "N'abc'", "'abc'", '0x616263', '616263' ),
825+ 'national quoted' => array( 'varbinary(4)', "n'it''s'", "'it''s'", '0x69742773', '69742773' ),
821826 'number' => array( 'varbinary(4)', '5', "'5'", '0x35', '35' ),
822827 'negative number' => array( 'varbinary(4)', '-5', "'-5'", '0x2D35', '2D35' ),
823828 'true' => array( 'varbinary(4)', 'TRUE', "'1'", '0x31', '31' ),
@@ -840,6 +845,45 @@ public function testBinaryColumnSetDefault(): void {
840845 $this->assertSame( 'DEADBEEF', $this->last_result[0]->v );
841846 }
842847
848+ /**
849+ * @dataProvider data_binary_column_generated_defaults
850+ */
851+ public function testBinaryColumnGeneratedDefaults( string $column_type, string $default_value, string $expected_value ): void {
852+ $this->assertQuery( "CREATE TABLE t (id INT PRIMARY KEY, v $column_type NOT NULL DEFAULT $default_value)" );
853+
854+ $this->assertQuery( 'INSERT INTO t (id) VALUES (1)' );
855+
856+ $this->assertQuery( 'SELECT HEX(v) AS v FROM t' );
857+ $this->assertSame( $expected_value, $this->last_result[0]->v );
858+ }
859+
860+ public static function data_binary_column_generated_defaults(): array {
861+ return array(
862+ 'varbinary text' => array( 'varbinary(4)', "('abc')", '616263' ),
863+ 'binary text' => array( 'binary(3)', "('abc')", '616263' ),
864+ 'blob text' => array( 'blob', "('abc')", '616263' ),
865+ 'hex' => array( 'varbinary(4)', '(0x616263)', '616263' ),
866+ 'function' => array( 'longblob', "(CONCAT('a', 'bc'))", '616263' ),
867+ 'number' => array( 'varbinary(4)', '(1 + 1)', '32' ),
868+ );
869+ }
870+
871+ public function testTextColumnDefaultsWithPrefixes(): void {
872+ $this->assertQuery(
873+ "CREATE TABLE t (
874+ id INT PRIMARY KEY,
875+ a VARCHAR(8) NOT NULL DEFAULT _utf8mb4'abc',
876+ b VARCHAR(8) NOT NULL DEFAULT N'it''s'
877+ )"
878+ );
879+
880+ $this->assertQuery( 'INSERT INTO t (id) VALUES (1)' );
881+
882+ $this->assertQuery( 'SELECT a, b FROM t' );
883+ $this->assertSame( 'abc', $this->last_result[0]->a );
884+ $this->assertSame( "it's", $this->last_result[0]->b );
885+ }
886+
843887 /**
844888 * Older versions stored most BINARY and VARBINARY defaults as written.
845889 *
0 commit comments