From 847660225dee2a7d02b3413c60b35021e28a0885 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Tue, 17 Apr 2018 10:55:42 +0200 Subject: [PATCH 1/4] fix all unconvert issues --- sqlite3.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index bff6b7c..8c83e4d 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -336,7 +336,7 @@ func (c *SQLiteConn) RegisterCommitHook(callback func() int) { if callback == nil { C.sqlite3_commit_hook(c.db, nil, nil) } else { - C.sqlite3_commit_hook(c.db, (*[0]byte)(unsafe.Pointer(C.commitHookTrampoline)), unsafe.Pointer(newHandle(c, callback))) + C.sqlite3_commit_hook(c.db, (*[0]byte)(C.commitHookTrampoline), unsafe.Pointer(newHandle(c, callback))) } } @@ -349,7 +349,7 @@ func (c *SQLiteConn) RegisterRollbackHook(callback func()) { if callback == nil { C.sqlite3_rollback_hook(c.db, nil, nil) } else { - C.sqlite3_rollback_hook(c.db, (*[0]byte)(unsafe.Pointer(C.rollbackHookTrampoline)), unsafe.Pointer(newHandle(c, callback))) + C.sqlite3_rollback_hook(c.db, (*[0]byte)(C.rollbackHookTrampoline), unsafe.Pointer(newHandle(c, callback))) } } @@ -366,7 +366,7 @@ func (c *SQLiteConn) RegisterUpdateHook(callback func(int, string, string, int64 if callback == nil { C.sqlite3_update_hook(c.db, nil, nil) } else { - C.sqlite3_update_hook(c.db, (*[0]byte)(unsafe.Pointer(C.updateHookTrampoline)), unsafe.Pointer(newHandle(c, callback))) + C.sqlite3_update_hook(c.db, (*[0]byte)(C.updateHookTrampoline), unsafe.Pointer(newHandle(c, callback))) } } @@ -448,7 +448,7 @@ func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) erro } func sqlite3CreateFunction(db *C.sqlite3, zFunctionName *C.char, nArg C.int, eTextRep C.int, pApp uintptr, xFunc unsafe.Pointer, xStep unsafe.Pointer, xFinal unsafe.Pointer) C.int { - return C._sqlite3_create_function(db, zFunctionName, nArg, eTextRep, C.uintptr_t(pApp), (*[0]byte)(unsafe.Pointer(xFunc)), (*[0]byte)(unsafe.Pointer(xStep)), (*[0]byte)(unsafe.Pointer(xFinal))) + return C._sqlite3_create_function(db, zFunctionName, nArg, eTextRep, C.uintptr_t(pApp), (*[0]byte)(xFunc), (*[0]byte)(xStep), (*[0]byte)(xFinal)) } // AutoCommit return which currently auto commit or not. @@ -859,7 +859,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error { case int64: rv = C.sqlite3_bind_int64(s.s, n, C.sqlite3_int64(v)) case bool: - if bool(v) { + if v { rv = C.sqlite3_bind_int(s.s, n, 1) } else { rv = C.sqlite3_bind_int(s.s, n, 0) @@ -1070,10 +1070,10 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i))) switch dest[i].(type) { case sql.RawBytes: - dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n] + dest[i] = (*[1 << 30]byte)(p)[0:n] default: slice := make([]byte, n) - copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]) + copy(slice[:], (*[1 << 30]byte)(p)[0:n]) dest[i] = slice } case C.SQLITE_NULL: From 28e6f6d6751aaa0657ccdf9f330a7e6843b15ece Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Tue, 17 Apr 2018 11:00:36 +0200 Subject: [PATCH 2/4] fix all gosimple issues --- sqlite3_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sqlite3_test.go b/sqlite3_test.go index 09e6727..8d65243 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -563,7 +563,7 @@ func TestBoolean(t *testing.T) { t.Fatalf("Expected 1 row but %v", counter) } - if id != 1 && fbool != true { + if id != 1 && !fbool { t.Fatalf("Value for id 1 should be %v, not %v", bool1, fbool) } @@ -585,7 +585,7 @@ func TestBoolean(t *testing.T) { t.Fatalf("Expected 1 row but %v", counter) } - if id != 2 && fbool != false { + if id != 2 && fbool { t.Fatalf("Value for id 2 should be %v, not %v", bool2, fbool) } @@ -1410,10 +1410,7 @@ func BenchmarkCustomFunctions(b *testing.B) { sql.Register("sqlite3_BenchmarkCustomFunctions", &SQLiteDriver{ ConnectHook: func(conn *SQLiteConn) error { // Impure function to force sqlite to reexecute it each time. - if err := conn.RegisterFunc("custom_add", customAdd, false); err != nil { - return err - } - return nil + return conn.RegisterFunc("custom_add", customAdd, false) }, }) }) From 4bde157d91c6061ab47312761ca440d2b06bdb25 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Tue, 17 Apr 2018 11:13:35 +0200 Subject: [PATCH 3/4] fix all goconst issues --- sqlite3.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index 8c83e4d..3273da4 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -141,6 +141,12 @@ var SQLiteTimestampFormats = []string{ "2006-01-02", } +const ( + columnDate string = "date" + columnDatetime string = "datetime" + columnTimestamp string = "timestamp" +) + func init() { sql.Register("sqlite3", &SQLiteDriver{}) } @@ -1039,7 +1045,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { case C.SQLITE_INTEGER: val := int64(C.sqlite3_column_int64(rc.s.s, C.int(i))) switch rc.decltype[i] { - case "timestamp", "datetime", "date": + case columnTimestamp, columnDatetime, columnDate: var t time.Time // Assume a millisecond unix timestamp if it's 13 digits -- too // large to be a reasonable timestamp in seconds. @@ -1086,7 +1092,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { s := C.GoStringN((*C.char)(unsafe.Pointer(C.sqlite3_column_text(rc.s.s, C.int(i)))), C.int(n)) switch rc.decltype[i] { - case "timestamp", "datetime", "date": + case columnTimestamp, columnDatetime, columnDate: var t time.Time s = strings.TrimSuffix(s, "Z") for _, format := range SQLiteTimestampFormats { From b75aefcf462ece8ce34da3f6e9d3877157506669 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Tue, 17 Apr 2018 11:42:17 +0200 Subject: [PATCH 4/4] fix small codespell issue --- sqlite3_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlite3_test.go b/sqlite3_test.go index 8d65243..5803042 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1517,7 +1517,7 @@ func (db *TestDB) tearDown() { // q replaces ? parameters if needed func (db *TestDB) q(sql string) string { switch db.dialect { - case POSTGRESQL: // repace with $1, $2, .. + case POSTGRESQL: // replace with $1, $2, .. qrx := regexp.MustCompile(`\?`) n := 0 return qrx.ReplaceAllStringFunc(sql, func(string) string {