Commit 6bcd838f authored by gwenn's avatar gwenn

Scan support interface{} pointer (useful when sqlite data type is dynamic).

parent 3dd0fe33
......@@ -37,7 +37,7 @@ Conn#EnableLoadExtension/LoadExtension
Stmt#ExecUpdate
Stmt#BindParameterCount/BindParameterIndex/BindParameterName
Stmt#ClearBindings
Stmt#ColumnCount/ColumnIndex(name)/ColumnName(index)/ColumnType(index)
Stmt#ColumnCount/ColumnNames/ColumnIndex(name)/ColumnName(index)/ColumnType(index)
Stmt#ReadOnly
Blob:
......
......@@ -110,12 +110,7 @@ func (s *stmtImpl) Query(args []interface{}) (driver.Rows, error) {
// TODO Cache result?
func (s *stmtImpl) Columns() []string {
count := s.s.ColumnCount()
cols := make([]string, count)
for i := 0; i < count; i++ {
cols[i] = s.s.ColumnName(i)
}
return cols
return s.s.ColumnNames()
}
func (s *stmtImpl) Next(dest []interface{}) error {
......
......@@ -15,6 +15,7 @@ func ExampleOpen() {
fmt.Printf("%d\n", db.TotalChanges())
}
/*
// <nil>
func ExampleExec() {
db, _ := sqlite.Open(":memory:")
......@@ -22,6 +23,7 @@ func ExampleExec() {
err := db.Exec("CREATE TABLE test(id INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL)")
fmt.Println(err)
}
*/
// true <nil>
func ExamplePrepare() {
......
......@@ -536,6 +536,15 @@ func (s *Stmt) ColumnName(index int) string {
return C.GoString(C.sqlite3_column_name(s.stmt, C.int(index)))
}
func (s *Stmt) ColumnNames() []string {
count := s.ColumnCount()
names := make([]string, count)
for i := 0; i < count; i++ {
names[i] = s.ColumnName(i)
}
return names
}
type Type int
func (t Type) String() string {
......@@ -668,6 +677,9 @@ func (s *Stmt) ScanColumn(index int, value interface{}) (bool, error) {
*value, isNull, err = s.ScanFloat64(index)
case *[]byte:
*value, isNull, err = s.ScanBlob(index)
case *interface{}:
*value = s.ScanValue(index)
isNull = *value == nil
default:
return false, errors.New("unsupported type in Scan: " + reflect.TypeOf(value).String())
}
......@@ -875,7 +887,7 @@ func (c *Conn) Close() error {
// Dangling statements
stmt := C.sqlite3_next_stmt(c.db, nil)
for stmt != nil {
//Log(1, "Dangling statement")
Log(21, "Dangling statement")
C.sqlite3_finalize(stmt)
stmt = C.sqlite3_next_stmt(c.db, stmt)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment