Implement RowsColumnScanner.

This commit is contained in:
Nuno Cruces
2025-08-14 01:36:45 +01:00
parent 8f9a8e2752
commit 8a64ee6eaa

View File

@@ -604,15 +604,6 @@ func (r resultRowsAffected) RowsAffected() (int64, error) {
return int64(r), nil
}
type rows struct {
ctx context.Context
*stmt
names []string
types []string
nulls []bool
scans []scantype
}
type scantype byte
const (
@@ -648,10 +639,20 @@ func scanFromDecl(decl string) scantype {
return _ANY
}
type rows struct {
ctx context.Context
*stmt
names []string
types []string
nulls []bool
scans []scantype
}
var (
// Ensure these interfaces are implemented:
_ driver.RowsColumnTypeDatabaseTypeName = &rows{}
_ driver.RowsColumnTypeNullable = &rows{}
// _ driver.RowsColumnScanner = &rows{}
)
func (r *rows) Close() error {
@@ -830,3 +831,23 @@ func (r *rows) Next(dest []driver.Value) error {
}
return nil
}
func (r *rows) ScanColumn(dest any, index int) error {
// notest // Go 1.26
var ptr *time.Time
switch d := dest.(type) {
case *time.Time:
ptr = d
case *sql.NullTime:
ptr = &d.Time
case *sql.Null[time.Time]:
ptr = &d.V
default:
return driver.ErrSkip
}
if t := r.Stmt.ColumnTime(index, r.tmRead); !t.IsZero() {
*ptr = t
return nil
}
return driver.ErrSkip
}