canonical / dqlite

Embeddable, replicated and fault-tolerant SQL engine.
https://dqlite.io
Other
3.86k stars 216 forks source link

Confusing error message when trying to run a query statement with Exec #499

Closed Aflynn50 closed 1 year ago

Aflynn50 commented 1 year ago

When executing a SELECT statement with db.Exec the error returned the error returned is a bit confusing, it claims that it is not an error.

_, err = db.Exec("SELECT name FROM person")
if err != nil {
    panic(err)
}

Gives

panic: not an error

The full error object appears to be:

protocol.Error{Code:100, Message:"not an error"}
cole-miller commented 1 year ago

Yes, this happens because of the way we handle EXEC_SQL requests, we call sqlite3_step once and return an error if it returns something other than SQLITE_DONE. That happens in particular if the executed SQL yields rows, so the first return value of sqlite3_step is SQLITE_ROW (= 100). It should be easy to add a path to check this and insert a more helpful error message.