Skip to content

Commit

Permalink
Merge pull request #47 from evan-snyk/add-scantype-support
Browse files Browse the repository at this point in the history
Add support for ScanType in ColumnType.
  • Loading branch information
l3pp4rd authored Oct 10, 2022
2 parents 0e9ad8c + 10aa843 commit efef918
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"database/sql/driver"
"fmt"
"io"
"reflect"
"sync"
)

Expand Down Expand Up @@ -401,6 +402,10 @@ func (rs *rowSets) ColumnTypeDatabaseTypeName(index int) string {
return rs.sets[rs.pos].ColumnTypeDatabaseTypeName(index)
}

func (rs *rowSets) ColumnTypeScanType(index int) reflect.Type {
return rs.sets[rs.pos].colTypes[index].ScanType()
}

func (rs *rowSets) Close() error {
return nil
}
Expand Down
31 changes: 30 additions & 1 deletion postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@

package txdb

import _ "github.com/lib/pq"
import (
"database/sql"
"reflect"
"testing"

_ "github.com/lib/pq"
)

func init() {
Register("psql_txdb", "postgres", "postgres://postgres@localhost/txdb_test?sslmode=disable")
}

func TestRowsScanTypeTables(t *testing.T) {
db, err := sql.Open("psql_txdb", "scantype")
if err != nil {
t.Fatalf("psql: failed to open a postgres connection, have you run 'make test'? err: %s", err)
}
defer db.Close()

rows, err := db.Query("SELECT 1")
if err != nil {
t.Fatalf("psql: unable to execute trivial query: %v", err)
}

colTypes, err := rows.ColumnTypes()
if err != nil {
t.Fatalf("psql: unable to retrieve column types: %v", err)
}

int32Type := reflect.TypeOf(int32(0))
if colTypes[0].ScanType() != int32Type {
t.Fatalf("psql: column scan type is %s, but should be %s", colTypes[0].ScanType().String(), int32Type.String())
}
}

0 comments on commit efef918

Please sign in to comment.