Skip to content

ColumnTypes: DatabaseTypeName missing?

Sqlite3 normally provides a DatabaseTypeName when querying the ColumnTypes. While trying out the following code ( see sample code below ), the results are:

Col 0: &{ name:uid hasNullable:false hasLength:false hasPrecisionScale:false nullable:false length:0 databaseType: precision:0 scale:0 scanType:0x9ffc20} Col 1: &{name:username hasNullable:false hasLength:false hasPrecisionScale:false nullable:false length:0 databaseType: precision:0 scale:0 scanType:0x9ffc20} Col 2: &{name:departname hasNullable:false hasLength:false hasPrecisionScale:false nullable:false length:0 databaseType: precision:0 scale:0 scanType:0x9ffc20} Col 3: &{name:created hasNullable:false hasLength:false hasPrecisionScale:false nullable:false length:0 databaseType: precision:0 scale:0 scanType:0x9ffc20}

Notice how the databaseType is empty.


import (
	"database/sql"
	"fmt"
	"log"
	_ "modernc.org/sqlite"
)

func main() {

db, _:= sql.Open("sqlite", "./foo3.db")
_, _ = db.Query("CREATE TABLE IF NOT EXISTS `userinfo` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT,`username` VARCHAR(64) NULL, `departname` VARCHAR(64) NULL, `created` DATE NULL);")

insertStatement := `INSERT INTO userinfo(username, departname, created) values("astaxie", "研发部门", "2012-12-09")`
_, _ := db.Query(insertStatement)

rows2, _ := db.Query("SELECT * FROM userinfo")

columnTypes, _ := rows2.ColumnTypes()
for rows2.Next() {
	for index, value := range columnTypes {
		fmt.Printf("Col %d: %+v", index, value)
	}
}

}

For some reason the DatabaseTypeName seems to be missing.

Edited by Benny Luypaert