@@ -588,10 +588,16 @@ func TestRowsColumnTypes(t *testing.T) {
588
588
nt1 := NullTime {Time : time .Date (2006 , 01 , 02 , 15 , 04 , 05 , 100000000 , time .UTC ), Valid : true }
589
589
nt2 := NullTime {Time : time .Date (2006 , 01 , 02 , 15 , 04 , 05 , 110000000 , time .UTC ), Valid : true }
590
590
nt6 := NullTime {Time : time .Date (2006 , 01 , 02 , 15 , 04 , 05 , 111111000 , time .UTC ), Valid : true }
591
+ nd1 := NullTime {Time : time .Date (2006 , 01 , 02 , 0 , 0 , 0 , 0 , time .UTC ), Valid : true }
592
+ nd2 := NullTime {Time : time .Date (2006 , 03 , 04 , 0 , 0 , 0 , 0 , time .UTC ), Valid : true }
593
+ ndNULL := NullTime {Time : time.Time {}, Valid : false }
591
594
rbNULL := sql .RawBytes (nil )
592
595
rb0 := sql .RawBytes ("0" )
593
596
rb42 := sql .RawBytes ("42" )
594
597
rbTest := sql .RawBytes ("Test" )
598
+ rb0pad4 := sql .RawBytes ("0\x00 \x00 \x00 " ) // BINARY right-pads values with 0x00
599
+ rbx0 := sql .RawBytes ("\x00 " )
600
+ rbx42 := sql .RawBytes ("\x42 " )
595
601
596
602
var columns = []struct {
597
603
name string
@@ -604,13 +610,15 @@ func TestRowsColumnTypes(t *testing.T) {
604
610
valuesIn [3 ]string
605
611
valuesOut [3 ]interface {}
606
612
}{
613
+ {"bit8null" , "BIT(8)" , "BIT" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0x0" , "NULL" , "0x42" }, [3 ]interface {}{rbx0 , rbNULL , rbx42 }},
607
614
{"boolnull" , "BOOL" , "TINYINT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"NULL" , "true" , "0" }, [3 ]interface {}{niNULL , ni1 , ni0 }},
608
615
{"bool" , "BOOL NOT NULL" , "TINYINT" , scanTypeInt8 , false , 0 , 0 , [3 ]string {"1" , "0" , "FALSE" }, [3 ]interface {}{int8 (1 ), int8 (0 ), int8 (0 )}},
609
616
{"intnull" , "INTEGER" , "INT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"0" , "NULL" , "42" }, [3 ]interface {}{ni0 , niNULL , ni42 }},
610
617
{"smallint" , "SMALLINT NOT NULL" , "SMALLINT" , scanTypeInt16 , false , 0 , 0 , [3 ]string {"0" , "-32768" , "32767" }, [3 ]interface {}{int16 (0 ), int16 (- 32768 ), int16 (32767 )}},
611
618
{"smallintnull" , "SMALLINT" , "SMALLINT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"0" , "NULL" , "42" }, [3 ]interface {}{ni0 , niNULL , ni42 }},
612
619
{"int3null" , "INT(3)" , "INT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"0" , "NULL" , "42" }, [3 ]interface {}{ni0 , niNULL , ni42 }},
613
620
{"int7" , "INT(7) NOT NULL" , "INT" , scanTypeInt32 , false , 0 , 0 , [3 ]string {"0" , "-1337" , "42" }, [3 ]interface {}{int32 (0 ), int32 (- 1337 ), int32 (42 )}},
621
+ {"mediumintnull" , "MEDIUMINT" , "MEDIUMINT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"0" , "42" , "NULL" }, [3 ]interface {}{ni0 , ni42 , niNULL }},
614
622
{"bigint" , "BIGINT NOT NULL" , "BIGINT" , scanTypeInt64 , false , 0 , 0 , [3 ]string {"0" , "65535" , "-42" }, [3 ]interface {}{int64 (0 ), int64 (65535 ), int64 (- 42 )}},
615
623
{"bigintnull" , "BIGINT" , "BIGINT" , scanTypeNullInt , true , 0 , 0 , [3 ]string {"NULL" , "1" , "42" }, [3 ]interface {}{niNULL , ni1 , ni42 }},
616
624
{"tinyuint" , "TINYINT UNSIGNED NOT NULL" , "TINYINT" , scanTypeUint8 , false , 0 , 0 , [3 ]string {"0" , "255" , "42" }, [3 ]interface {}{uint8 (0 ), uint8 (255 ), uint8 (42 )}},
@@ -630,11 +638,21 @@ func TestRowsColumnTypes(t *testing.T) {
630
638
{"decimal3null" , "DECIMAL(5,0)" , "DECIMAL" , scanTypeRawBytes , true , 5 , 0 , [3 ]string {"0" , "NULL" , "-12345.123456" }, [3 ]interface {}{rb0 , rbNULL , sql .RawBytes ("-12345" )}},
631
639
{"char25null" , "CHAR(25)" , "CHAR" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
632
640
{"varchar42" , "VARCHAR(42) NOT NULL" , "VARCHAR" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
633
- {"textnull" , "TEXT" , "BLOB" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
634
- {"longtext" , "LONGTEXT NOT NULL" , "BLOB" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
641
+ {"binary4null" , "BINARY(4)" , "BINARY" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0pad4 , rbNULL , rbTest }},
642
+ {"varbinary42" , "VARBINARY(42) NOT NULL" , "VARBINARY" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
643
+ {"tinyblobnull" , "TINYBLOB" , "BLOB" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
644
+ {"tinytextnull" , "TINYTEXT" , "TEXT" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
645
+ {"blobnull" , "BLOB" , "BLOB" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
646
+ {"textnull" , "TEXT" , "TEXT" , scanTypeRawBytes , true , 0 , 0 , [3 ]string {"0" , "NULL" , "'Test'" }, [3 ]interface {}{rb0 , rbNULL , rbTest }},
647
+ {"mediumblob" , "MEDIUMBLOB NOT NULL" , "BLOB" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
648
+ {"mediumtext" , "MEDIUMTEXT NOT NULL" , "TEXT" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
649
+ {"longblob" , "LONGBLOB NOT NULL" , "BLOB" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
650
+ {"longtext" , "LONGTEXT NOT NULL" , "TEXT" , scanTypeRawBytes , false , 0 , 0 , [3 ]string {"0" , "'Test'" , "42" }, [3 ]interface {}{rb0 , rbTest , rb42 }},
635
651
{"datetime" , "DATETIME" , "DATETIME" , scanTypeNullTime , true , 0 , 0 , [3 ]string {"'2006-01-02 15:04:05'" , "'2006-01-02 15:04:05.1'" , "'2006-01-02 15:04:05.111111'" }, [3 ]interface {}{nt0 , nt0 , nt0 }},
636
652
{"datetime2" , "DATETIME(2)" , "DATETIME" , scanTypeNullTime , true , 2 , 2 , [3 ]string {"'2006-01-02 15:04:05'" , "'2006-01-02 15:04:05.1'" , "'2006-01-02 15:04:05.111111'" }, [3 ]interface {}{nt0 , nt1 , nt2 }},
637
653
{"datetime6" , "DATETIME(6)" , "DATETIME" , scanTypeNullTime , true , 6 , 6 , [3 ]string {"'2006-01-02 15:04:05'" , "'2006-01-02 15:04:05.1'" , "'2006-01-02 15:04:05.111111'" }, [3 ]interface {}{nt0 , nt1 , nt6 }},
654
+ {"date" , "DATE" , "DATE" , scanTypeNullTime , true , 0 , 0 , [3 ]string {"'2006-01-02'" , "NULL" , "'2006-03-04'" }, [3 ]interface {}{nd1 , ndNULL , nd2 }},
655
+ {"year" , "YEAR NOT NULL" , "YEAR" , scanTypeUint16 , false , 0 , 0 , [3 ]string {"2006" , "2000" , "1994" }, [3 ]interface {}{uint16 (2006 ), uint16 (2000 ), uint16 (1994 )}},
638
656
}
639
657
640
658
schema := ""
0 commit comments