SQLite User Forum

Retrieve run-time error
Login

Retrieve run-time error

(1) By Aask (AAsk1902) on 2022-10-31 18:49:36 [link] [source]

Given this:

SQLite version 3.39.4 2022-09-29 15:55:41
Enter ".help" for usage hints.
sqlite> select * from tblne;
Parse error: no such table: tblne

What SQLITE API will enable me to retrieve the error message

Parse error: no such table: tblne

from my application using SQLite3.DLL?

(2) By Keith Medcalf (kmedcalf) on 2022-10-31 19:07:28 in reply to 1 [link] [source]

This error is returned during "Prepare", so your call to sqlite3_prepare* API will return an error. You can access the error message, standard code, and extended code (assuming the returned code is insufficient) via the standard API https://sqlite.org/c3ref/errcode.html

Note that all the API's are documented and if you look at the list of them they are all pretty self-explanitory (that is, the API does what the tin says). https://sqlite.org/c3ref/funclist.html

(3.2) By Aask (AAsk1902) on 2022-10-31 19:25:29 edited from 3.1 in reply to 2 [source]

Thanks Keith.

I am using sqlite3_exec.

Before posting:

  • I had tried sqlite3_errmsg with the database handle as the argument but that did not give me the runtime error text.
  • I had also tried sqlite3_errstr with the return value yielded by sqlite3_exec (the fifth argument) as the argument which did not give me the runtime error text either.

What am I missing?

(4) By Ryan Smith (cuz) on 2022-10-31 19:27:46 in reply to 3.0 [link] [source]

Those functions work for us all, so they should work for you too.

Lots of little things might be wrong, but we won't know until we see what you've tried, so all that remain is for you to show your code.

(5) By Aask (AAsk1902) on 2022-10-31 19:51:47 in reply to 4 [link] [source]

Those functions work for us all, so they should work for you too.

That is what I too expected; obviously, there is a subtle flaw in my code which I am reviewing. I can't show you my code because the language I am using uses a proprietary font that is unsupported by this forum.

(6) By Larry Brasfield (larrybr) on 2022-10-31 19:53:51 in reply to 3.2 [link] [source]

What you are missing seems to be this:

The CLI classifies and tags errors as "Parse error" or "Runtime error" (or something even more vague sometimes) when its input is subject to sqlite3_prepare() or when a prepared statement is run, respectively. So the above-quoted portions of the text you see do not come from the SQLite library. Only the part after ": " comes from the APIs others have mentioned.

(7) By Aask (AAsk1902) on 2022-10-31 19:57:05 in reply to 6 [link] [source]

Only the part after ": " comes from the APIs others have mentioned.

The CLI message has two colons. If you mean the part after the first colon then it will suffice.

(8) By Keith Medcalf (kmedcalf) on 2022-10-31 20:43:20 in reply to 3.2 [link] [source]

When you attempt to prepare the statement (using one of the sqlite3_prepare* APIs), the result code will be something other than SQLITE_OK. When this happens no statement is produced -- the compile failed.

You may then access additional particulars of the error condition using the various error fetching APIs described.

You are checking the return code of every API call that returns a return code, are you not?

(9) By Keith Medcalf (kmedcalf) on 2022-10-31 20:49:19 in reply to 7 [link] [source]

Yes. The two parts (separated by the first colon) are an identifier as to where the error occurred, and the message produced by the error as retrieved by the sqlite3_errmsg API.

The part before the first colon tells you where the error was detected (many people were confused since a statement error (like when you compile anything at all) can occur at "compile" (prepare/parse) time or at "execution time" (runtime) al;though this is not really a problem. Some classes of error are detected at "compile" (prepare) time and preclude the creation of a compiled "statement". Things like misspelled or missing identifiers are detected solely at compile/prepare time (if you try to compile a statement that is accessing a table that does not exist, then the compile/prepare fails and there is no thing to execute).

Other error conditions (such as contraint violations) are detected at runtime (by sqlite3_step returning other than SQLITE_ROW or SQLITE_DONE.

(10.1) By Aask (AAsk1902) on 2022-10-31 20:58:32 edited from 10.0 in reply to 8 [link] [source]

You are checking the return code of every API call that returns a return code, are you not?

Yes, I do and in this instance/context, I intend to engage the exception reporting code segment when the return code of sqlite3_exec is non-zero i.e. not SQLITE_OK.