Skip to content

Commit b4c1089

Browse files
committed
sqlite: string error messages for some Step errors
Sometimes the string error message SQLite returns from sqlite3_step is extremely useful. In cases where we expect the error is not an expected behavior in fast paths (for example, the CONSTRAINT errors) we extract it.
1 parent 0c46935 commit b4c1089

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sqlite.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func (stmt *Stmt) Step() (rowReturned bool, err error) {
457457
if err := stmt.conn.interrupted("Stmt.Step", stmt.query); err != nil {
458458
return false, err
459459
}
460-
switch res := C.sqlite3_step(stmt.stmt); res {
460+
switch res := C.sqlite3_step(stmt.stmt); uint8(res) { // reduce to non-extended error code
461461
case C.SQLITE_LOCKED:
462462
if res := C.wait_for_unlock_notify(stmt.conn.conn, stmt.conn.unlockNote); res != C.SQLITE_OK {
463463
return false, stmt.conn.reserr("Stmt.Step(Wait)", stmt.query, res)
@@ -468,8 +468,11 @@ func (stmt *Stmt) Step() (rowReturned bool, err error) {
468468
return true, nil
469469
case C.SQLITE_DONE:
470470
return false, nil
471-
default:
471+
case C.SQLITE_BUSY, C.SQLITE_INTERRUPT, C.SQLITE_CONSTRAINT:
472+
// TODO: embed some of these errors into the stmt for zero-alloc errors?
472473
return false, stmt.conn.reserr("Stmt.Step", stmt.query, res)
474+
default:
475+
return false, stmt.conn.extreserr("Stmt.Step", stmt.query, res)
473476
}
474477
}
475478
}

0 commit comments

Comments
 (0)