fix Scan NullTime type failed at sqlite3 (#33)
This commit is contained in:
parent
7cd4078f0b
commit
7ba98d23bc
|
@ -12,3 +12,4 @@ test:
|
|||
override:
|
||||
# './...' is a relative pattern which means all subdirectories
|
||||
- go test -v -race
|
||||
- go test -v -race --dbtype=sqlite3
|
||||
|
|
25
db_test.go
25
db_test.go
|
@ -2,7 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -12,8 +12,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
//dbtype string = "sqlite3"
|
||||
dbtype string = "mysql"
|
||||
dbtype = flag.String("dbtype", "mysql", "database type")
|
||||
createTableSql string
|
||||
)
|
||||
|
||||
|
@ -28,7 +27,8 @@ type User struct {
|
|||
}
|
||||
|
||||
func init() {
|
||||
switch dbtype {
|
||||
flag.Parse()
|
||||
switch *dbtype {
|
||||
case "sqlite3":
|
||||
createTableSql = "CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NULL, " +
|
||||
"`title` TEXT NULL, `age` FLOAT NULL, `alias` TEXT NULL, `nick_name` TEXT NULL, `created` datetime);"
|
||||
|
@ -41,7 +41,7 @@ func init() {
|
|||
}
|
||||
|
||||
func testOpen() (*DB, error) {
|
||||
switch dbtype {
|
||||
switch *dbtype {
|
||||
case "sqlite3":
|
||||
os.Remove("./test.db")
|
||||
return Open("sqlite3", "./test.db")
|
||||
|
@ -133,7 +133,7 @@ func BenchmarkStructQuery(b *testing.B) {
|
|||
b.Error(err)
|
||||
}
|
||||
if user.Name != "xlw" {
|
||||
fmt.Println(user)
|
||||
b.Log(user)
|
||||
b.Error(errors.New("name should be xlw"))
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ func BenchmarkStruct2Query(b *testing.B) {
|
|||
b.Error(err)
|
||||
}
|
||||
if user.Name != "xlw" {
|
||||
fmt.Println(user)
|
||||
b.Log(user)
|
||||
b.Error(errors.New("name should be xlw"))
|
||||
}
|
||||
}
|
||||
|
@ -228,9 +228,8 @@ func BenchmarkSliceInterfaceQuery(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
fmt.Println(slice)
|
||||
b.Log(slice)
|
||||
if *slice[1].(*string) != "xlw" {
|
||||
fmt.Println(slice)
|
||||
b.Error(errors.New("name should be xlw"))
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +331,7 @@ func BenchmarkSliceStringQuery(b *testing.B) {
|
|||
b.Error(err)
|
||||
}
|
||||
if (*slice[1]) != "xlw" {
|
||||
fmt.Println(slice)
|
||||
b.Log(slice)
|
||||
b.Error(errors.New("name should be xlw"))
|
||||
}
|
||||
}
|
||||
|
@ -378,7 +377,7 @@ func BenchmarkMapInterfaceQuery(b *testing.B) {
|
|||
b.Error(err)
|
||||
}
|
||||
if m["name"].(string) != "xlw" {
|
||||
fmt.Println(m)
|
||||
b.Log(m)
|
||||
b.Error(errors.New("name should be xlw"))
|
||||
}
|
||||
}
|
||||
|
@ -579,7 +578,7 @@ func TestExecMap(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println("--", user)
|
||||
t.Log("--", user)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -621,7 +620,7 @@ func TestExecStruct(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println("1--", user)
|
||||
t.Log("1--", user)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -12,14 +11,14 @@ func TestPK(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println(str)
|
||||
t.Log(str)
|
||||
|
||||
s := &PK{}
|
||||
err = s.FromString(str)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println(s)
|
||||
t.Log(s)
|
||||
|
||||
if len(*p) != len(*s) {
|
||||
t.Fatal("p", *p, "should be equal", *s)
|
||||
|
|
Loading…
Reference in New Issue