Skip to content

Commit 397c95c

Browse files
authored
Merge pull request #549 from mjtrangoni/fix-linter-issues
Fix linter issues
2 parents d896508 + b75aefc commit 397c95c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

sqlite3.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ var SQLiteTimestampFormats = []string{
173173
"2006-01-02",
174174
}
175175

176+
const (
177+
columnDate string = "date"
178+
columnDatetime string = "datetime"
179+
columnTimestamp string = "timestamp"
180+
)
181+
176182
func init() {
177183
sql.Register("sqlite3", &SQLiteDriver{})
178184
}
@@ -392,7 +398,7 @@ func (c *SQLiteConn) RegisterCommitHook(callback func() int) {
392398
if callback == nil {
393399
C.sqlite3_commit_hook(c.db, nil, nil)
394400
} else {
395-
C.sqlite3_commit_hook(c.db, (*[0]byte)(unsafe.Pointer(C.commitHookTrampoline)), unsafe.Pointer(newHandle(c, callback)))
401+
C.sqlite3_commit_hook(c.db, (*[0]byte)(C.commitHookTrampoline), unsafe.Pointer(newHandle(c, callback)))
396402
}
397403
}
398404

@@ -405,7 +411,7 @@ func (c *SQLiteConn) RegisterRollbackHook(callback func()) {
405411
if callback == nil {
406412
C.sqlite3_rollback_hook(c.db, nil, nil)
407413
} else {
408-
C.sqlite3_rollback_hook(c.db, (*[0]byte)(unsafe.Pointer(C.rollbackHookTrampoline)), unsafe.Pointer(newHandle(c, callback)))
414+
C.sqlite3_rollback_hook(c.db, (*[0]byte)(C.rollbackHookTrampoline), unsafe.Pointer(newHandle(c, callback)))
409415
}
410416
}
411417

@@ -422,7 +428,7 @@ func (c *SQLiteConn) RegisterUpdateHook(callback func(int, string, string, int64
422428
if callback == nil {
423429
C.sqlite3_update_hook(c.db, nil, nil)
424430
} else {
425-
C.sqlite3_update_hook(c.db, (*[0]byte)(unsafe.Pointer(C.updateHookTrampoline)), unsafe.Pointer(newHandle(c, callback)))
431+
C.sqlite3_update_hook(c.db, (*[0]byte)(C.updateHookTrampoline), unsafe.Pointer(newHandle(c, callback)))
426432
}
427433
}
428434

@@ -504,7 +510,7 @@ func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) erro
504510
}
505511

506512
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 {
507-
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)))
513+
return C._sqlite3_create_function(db, zFunctionName, nArg, eTextRep, C.uintptr_t(pApp), (*[0]byte)(xFunc), (*[0]byte)(xStep), (*[0]byte)(xFinal))
508514
}
509515

510516
// RegisterAggregator makes a Go type available as a SQLite aggregation function.
@@ -1073,7 +1079,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
10731079
case int64:
10741080
rv = C.sqlite3_bind_int64(s.s, n, C.sqlite3_int64(v))
10751081
case bool:
1076-
if bool(v) {
1082+
if v {
10771083
rv = C.sqlite3_bind_int(s.s, n, 1)
10781084
} else {
10791085
rv = C.sqlite3_bind_int(s.s, n, 0)
@@ -1279,7 +1285,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
12791285
case C.SQLITE_INTEGER:
12801286
val := int64(C.sqlite3_column_int64(rc.s.s, C.int(i)))
12811287
switch rc.decltype[i] {
1282-
case "timestamp", "datetime", "date":
1288+
case columnTimestamp, columnDatetime, columnDate:
12831289
var t time.Time
12841290
// Assume a millisecond unix timestamp if it's 13 digits -- too
12851291
// large to be a reasonable timestamp in seconds.
@@ -1310,10 +1316,10 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
13101316
n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i)))
13111317
switch dest[i].(type) {
13121318
case sql.RawBytes:
1313-
dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]
1319+
dest[i] = (*[1 << 30]byte)(p)[0:n]
13141320
default:
13151321
slice := make([]byte, n)
1316-
copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(p))[0:n])
1322+
copy(slice[:], (*[1 << 30]byte)(p)[0:n])
13171323
dest[i] = slice
13181324
}
13191325
case C.SQLITE_NULL:
@@ -1326,7 +1332,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
13261332
s := C.GoStringN((*C.char)(unsafe.Pointer(C.sqlite3_column_text(rc.s.s, C.int(i)))), C.int(n))
13271333

13281334
switch rc.decltype[i] {
1329-
case "timestamp", "datetime", "date":
1335+
case columnTimestamp, columnDatetime, columnDate:
13301336
var t time.Time
13311337
s = strings.TrimSuffix(s, "Z")
13321338
for _, format := range SQLiteTimestampFormats {

sqlite3_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ func TestBoolean(t *testing.T) {
563563
t.Fatalf("Expected 1 row but %v", counter)
564564
}
565565

566-
if id != 1 && fbool != true {
566+
if id != 1 && !fbool {
567567
t.Fatalf("Value for id 1 should be %v, not %v", bool1, fbool)
568568
}
569569

@@ -585,7 +585,7 @@ func TestBoolean(t *testing.T) {
585585
t.Fatalf("Expected 1 row but %v", counter)
586586
}
587587

588-
if id != 2 && fbool != false {
588+
if id != 2 && fbool {
589589
t.Fatalf("Value for id 2 should be %v, not %v", bool2, fbool)
590590
}
591591

@@ -1591,10 +1591,7 @@ func BenchmarkCustomFunctions(b *testing.B) {
15911591
sql.Register("sqlite3_BenchmarkCustomFunctions", &SQLiteDriver{
15921592
ConnectHook: func(conn *SQLiteConn) error {
15931593
// Impure function to force sqlite to reexecute it each time.
1594-
if err := conn.RegisterFunc("custom_add", customAdd, false); err != nil {
1595-
return err
1596-
}
1597-
return nil
1594+
return conn.RegisterFunc("custom_add", customAdd, false)
15981595
},
15991596
})
16001597
})
@@ -1701,7 +1698,7 @@ func (db *TestDB) tearDown() {
17011698
// q replaces ? parameters if needed
17021699
func (db *TestDB) q(sql string) string {
17031700
switch db.dialect {
1704-
case POSTGRESQL: // repace with $1, $2, ..
1701+
case POSTGRESQL: // replace with $1, $2, ..
17051702
qrx := regexp.MustCompile(`\?`)
17061703
n := 0
17071704
return qrx.ReplaceAllStringFunc(sql, func(string) string {

0 commit comments

Comments
 (0)