Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db_sqlite: Empty string in query causes unclear error #2

Open
Toromino opened this issue May 13, 2022 · 1 comment
Open

db_sqlite: Empty string in query causes unclear error #2

Toromino opened this issue May 13, 2022 · 1 comment

Comments

@Toromino
Copy link

Function exec in db_sqlite.nim throws an unclear error when passing an empty query.

Example

let db = open("nimskey.db", "", "", "")
db.exec(sql(""))

Current Output

/usr/lib/nim/lib/impure/db_sqlite.nim(271) exec
/usr/lib/nim/lib/impure/db_sqlite.nim(198) dbError
Error: unhandled exception: not an error [DbError]

Possible Solution

Let the empty string pass, or throw a more clear exception.

Additional Information

$ nim -v
Nim Compiler Version 1.6.0
@Zectbumo
Copy link

This is a bit of the fault of the sqlite3 lib since passing an empty string to prepare_v2() statement causes a misuse error (21) but doesn't set the error message which is SQLITE_OK message "not an error".

sqlite.h:

(#define SQLITE_MISUSE      21   /* Library used incorrectly */)

main.c:

static const char* const aMsg[] = {
    /* SQLITE_OK          */ "not an error",
...
    /* SQLITE_MISUSE      */ "bad parameter or other API misuse",

The wrapped sqlite3_exec() lib function which is a convenience function that does: prepare(), step() and finalize() doesn't return this error and returns an SQLITE_OK even when passed a string that only contains whitespace.
The impure nim library exec() doesn't call the wrapped sqlite3.exec() but instead makes it's own prepare(), step() and finalize() calls which means it does not inherit the same behavior as the wrapped sqlite3_exec().

Proposed solutions:

  1. make db_sqlite.exec() act like sqlite3.exec()
  2. return the proper error message for SQLITE_MISUSE: "bad parameter or other API misuse"
  3. actually use the sqlite3.exec() to inherit the behavior.

I'm leaning towards option 3

@ringabout ringabout transferred this issue from nim-lang/Nim Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants