@@ -578,6 +578,7 @@ type rows struct {
578
578
* stmt
579
579
names []string
580
580
types []string
581
+ nulls []bool
581
582
}
582
583
583
584
func (r * rows ) Close () error {
@@ -596,6 +597,22 @@ func (r *rows) Columns() []string {
596
597
return r .names
597
598
}
598
599
600
+ func (r * rows ) loadTypes () {
601
+ if r .nulls == nil {
602
+ count := r .Stmt .ColumnCount ()
603
+ r .nulls = make ([]bool , count )
604
+ r .types = make ([]string , count )
605
+ for i := range r .nulls {
606
+ if col := r .Stmt .ColumnOriginName (i ); col != "" {
607
+ r .types [i ], _ , r .nulls [i ], _ , _ , _ = r .Stmt .Conn ().TableColumnMetadata (
608
+ r .Stmt .ColumnDatabaseName (i ),
609
+ r .Stmt .ColumnTableName (i ),
610
+ col )
611
+ }
612
+ }
613
+ }
614
+ }
615
+
599
616
func (r * rows ) declType (index int ) string {
600
617
if r .types == nil {
601
618
count := r .Stmt .ColumnCount ()
@@ -608,7 +625,8 @@ func (r *rows) declType(index int) string {
608
625
}
609
626
610
627
func (r * rows ) ColumnTypeDatabaseTypeName (index int ) string {
611
- decltype := r .declType (index )
628
+ r .loadTypes ()
629
+ decltype := r .types [index ]
612
630
if len := len (decltype ); len > 0 && decltype [len - 1 ] == ')' {
613
631
if i := strings .LastIndexByte (decltype , '(' ); i >= 0 {
614
632
decltype = decltype [:i ]
@@ -617,6 +635,14 @@ func (r *rows) ColumnTypeDatabaseTypeName(index int) string {
617
635
return strings .TrimSpace (decltype )
618
636
}
619
637
638
+ func (r * rows ) ColumnTypeNullable (index int ) (nullable , ok bool ) {
639
+ r .loadTypes ()
640
+ if r .nulls [index ] {
641
+ return false , true
642
+ }
643
+ return true , false
644
+ }
645
+
620
646
func (r * rows ) Next (dest []driver.Value ) error {
621
647
old := r .Stmt .Conn ().SetInterrupt (r .ctx )
622
648
defer r .Stmt .Conn ().SetInterrupt (old )
0 commit comments