@@ -1403,3 +1403,67 @@ func TestOptionShouldPing_HookCalledOnReuse(t *testing.T) {
14031403
14041404 require .True (t , hookCalled , "hook should be called on reuse" )
14051405}
1406+
1407+ func TestRowsColumnTypeLength (t * testing.T ) {
1408+ testWithAllQueryExecModes (t , func (t * testing.T , db * sql.DB ) {
1409+ columnTypeLengthTests := []struct {
1410+ Len int64
1411+ OK bool
1412+ }{
1413+ {
1414+ math .MaxInt64 ,
1415+ true ,
1416+ },
1417+ {
1418+ math .MaxInt64 ,
1419+ true ,
1420+ },
1421+ {
1422+ 255 ,
1423+ true ,
1424+ },
1425+ {
1426+ 10 ,
1427+ true ,
1428+ },
1429+ {
1430+ 50 ,
1431+ true ,
1432+ },
1433+ {
1434+ 0 ,
1435+ false ,
1436+ },
1437+ }
1438+
1439+ _ , err := db .Exec (`CREATE TEMPORARY TABLE temp_column_type_length (
1440+ text_column TEXT,
1441+ bytea_column BYTEA,
1442+ varchar_column VARCHAR(255),
1443+ bpcharA_column BPCHAR(10)[],
1444+ varbit_column VARBIT(50),
1445+ int_column INT
1446+ );` )
1447+ require .NoError (t , err )
1448+
1449+ rows , err := db .Query ("SELECT * FROM temp_column_type_length" )
1450+ require .NoError (t , err )
1451+
1452+ columns , err := rows .ColumnTypes ()
1453+ require .NoError (t , err )
1454+ assert .Len (t , columns , 6 )
1455+
1456+ for i , tt := range columnTypeLengthTests {
1457+ c := columns [i ]
1458+
1459+ l , ok := c .Length ()
1460+ if l != tt .Len {
1461+ t .Errorf ("(%d) got: %d, want: %d" , i , l , tt .Len )
1462+ }
1463+ if ok != tt .OK {
1464+ t .Errorf ("(%d) got: %t, want: %t" , i , ok , tt .OK )
1465+ }
1466+
1467+ }
1468+ })
1469+ }
0 commit comments