aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite3_test.go')
-rw-r--r--sqlite3_test.go94
1 files changed, 37 insertions, 57 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go
index cf826dd..eb9d18e 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -207,12 +207,12 @@ func TestUpdate(t *testing.T) {
if err != nil {
t.Fatal("Failed to update record:", err)
}
- lastId, err := res.LastInsertId()
+ lastID, err := res.LastInsertId()
if err != nil {
t.Fatal("Failed to get LastInsertId:", err)
}
- if expected != lastId {
- t.Errorf("Expected %q for last Id, but %q:", expected, lastId)
+ if expected != lastID {
+ t.Errorf("Expected %q for last Id, but %q:", expected, lastID)
}
affected, _ = res.RowsAffected()
if err != nil {
@@ -272,12 +272,12 @@ func TestDelete(t *testing.T) {
if err != nil {
t.Fatal("Failed to delete record:", err)
}
- lastId, err := res.LastInsertId()
+ lastID, err := res.LastInsertId()
if err != nil {
t.Fatal("Failed to get LastInsertId:", err)
}
- if expected != lastId {
- t.Errorf("Expected %q for last Id, but %q:", expected, lastId)
+ if expected != lastID {
+ t.Errorf("Expected %q for last Id, but %q:", expected, lastID)
}
affected, err = res.RowsAffected()
if err != nil {
@@ -993,42 +993,6 @@ func TestVersion(t *testing.T) {
}
}
-func TestNumberNamedParams(t *testing.T) {
- tempFilename := TempFilename(t)
- defer os.Remove(tempFilename)
- db, err := sql.Open("sqlite3", tempFilename)
- if err != nil {
- t.Fatal("Failed to open database:", err)
- }
- defer db.Close()
-
- _, err = db.Exec(`
- create table foo (id integer, name text, extra text);
- `)
- if err != nil {
- t.Error("Failed to call db.Query:", err)
- }
-
- _, err = db.Exec(`insert into foo(id, name, extra) values($1, $2, $2)`, 1, "foo")
- if err != nil {
- t.Error("Failed to call db.Exec:", err)
- }
-
- row := db.QueryRow(`select id, extra from foo where id = $1 and extra = $2`, 1, "foo")
- if row == nil {
- t.Error("Failed to call db.QueryRow")
- }
- var id int
- var extra string
- err = row.Scan(&id, &extra)
- if err != nil {
- t.Error("Failed to db.Scan:", err)
- }
- if id != 1 || extra != "foo" {
- t.Error("Failed to db.QueryRow: not matched results")
- }
-}
-
func TestStringContainingZero(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
@@ -1106,12 +1070,12 @@ func TestDateTimeNow(t *testing.T) {
}
func TestFunctionRegistration(t *testing.T) {
- addi_8_16_32 := func(a int8, b int16) int32 { return int32(a) + int32(b) }
- addi_64 := func(a, b int64) int64 { return a + b }
- addu_8_16_32 := func(a uint8, b uint16) uint32 { return uint32(a) + uint32(b) }
- addu_64 := func(a, b uint64) uint64 { return a + b }
+ addi8_16_32 := func(a int8, b int16) int32 { return int32(a) + int32(b) }
+ addi64 := func(a, b int64) int64 { return a + b }
+ addu8_16_32 := func(a uint8, b uint16) uint32 { return uint32(a) + uint32(b) }
+ addu64 := func(a, b uint64) uint64 { return a + b }
addiu := func(a int, b uint) int64 { return int64(a) + int64(b) }
- addf_32_64 := func(a float32, b float64) float64 { return float64(a) + b }
+ addf32_64 := func(a float32, b float64) float64 { return float64(a) + b }
not := func(a bool) bool { return !a }
regex := func(re, s string) (bool, error) {
return regexp.MatchString(re, s)
@@ -1143,22 +1107,22 @@ func TestFunctionRegistration(t *testing.T) {
sql.Register("sqlite3_FunctionRegistration", &SQLiteDriver{
ConnectHook: func(conn *SQLiteConn) error {
- if err := conn.RegisterFunc("addi_8_16_32", addi_8_16_32, true); err != nil {
+ if err := conn.RegisterFunc("addi8_16_32", addi8_16_32, true); err != nil {
return err
}
- if err := conn.RegisterFunc("addi_64", addi_64, true); err != nil {
+ if err := conn.RegisterFunc("addi64", addi64, true); err != nil {
return err
}
- if err := conn.RegisterFunc("addu_8_16_32", addu_8_16_32, true); err != nil {
+ if err := conn.RegisterFunc("addu8_16_32", addu8_16_32, true); err != nil {
return err
}
- if err := conn.RegisterFunc("addu_64", addu_64, true); err != nil {
+ if err := conn.RegisterFunc("addu64", addu64, true); err != nil {
return err
}
if err := conn.RegisterFunc("addiu", addiu, true); err != nil {
return err
}
- if err := conn.RegisterFunc("addf_32_64", addf_32_64, true); err != nil {
+ if err := conn.RegisterFunc("addf32_64", addf32_64, true); err != nil {
return err
}
if err := conn.RegisterFunc("not", not, true); err != nil {
@@ -1189,12 +1153,12 @@ func TestFunctionRegistration(t *testing.T) {
query string
expected interface{}
}{
- {"SELECT addi_8_16_32(1,2)", int32(3)},
- {"SELECT addi_64(1,2)", int64(3)},
- {"SELECT addu_8_16_32(1,2)", uint32(3)},
- {"SELECT addu_64(1,2)", uint64(3)},
+ {"SELECT addi8_16_32(1,2)", int32(3)},
+ {"SELECT addi64(1,2)", int64(3)},
+ {"SELECT addu8_16_32(1,2)", uint32(3)},
+ {"SELECT addu64(1,2)", uint64(3)},
{"SELECT addiu(1,2)", int64(3)},
- {"SELECT addf_32_64(1.5,1.5)", float64(3)},
+ {"SELECT addf32_64(1.5,1.5)", float64(3)},
{"SELECT not(1)", false},
{"SELECT not(0)", true},
{`SELECT regex("^foo.*", "foobar")`, true},
@@ -1315,6 +1279,22 @@ func TestDeclTypes(t *testing.T) {
}
}
+func TestPinger(t *testing.T) {
+ db, err := sql.Open("sqlite3", ":memory:")
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = db.Ping()
+ if err != nil {
+ t.Fatal(err)
+ }
+ db.Close()
+ err = db.Ping()
+ if err == nil {
+ t.Fatal("Should be closed")
+ }
+}
+
var customFunctionOnce sync.Once
func BenchmarkCustomFunctions(b *testing.B) {