Open margual56 opened 1 year ago
Isn't the constraint violation reported when you execute the statement with exec ?
Do you have a reproducer that I can test ?
Isn't the constraint violation reported when you execute the statement with exec ?
May be. I Just did Ctrl+F
to search the message I get when the error gets reported: "error(sqlite): unable to finalize prepared statement, result[...]".
The only match is on the deinit function.
Do you have a reproducer that I can test ?
I have created a simple project to demonstrate: here. If you try to run it, it will create a database and add to it all the files you pass as arguments. If you then run it again and pass the same files, it will print two errors per file: One by me and another printed by sqlite. Example:
> zig build run -- .gitignore build.zig
File inserted
File inserted
> zig build run -- .gitignore build.zig
steps [2/6] zig build-exe sqlite-test Debug native-native-gnu.2.28... LLVM Emit Object... error: Error while inserting file:
Error: error.SQLiteConstraint
Diags: none
File inserted
error(sqlite): unable to finalize prepared statement, result: 19, detailed error: {code: 2067, near: -1, message: UNIQUE constraint failed: files.local_path}
error: Error while inserting file:
Error: error.SQLiteConstraint
Diags: none
File inserted
error(sqlite): unable to finalize prepared statement, result: 19, detailed error: {code: 2067, near: -1, message: UNIQUE constraint failed: files.local_path}
The rfc is regarding that last error message: If I handle the error, zig-sqlite shouldn't print the error.
Note that I'm fairly new to zig, so I may be doing something wrong here. Thank you!
Hi, sorry I haven't responded in a long time. I'll try to take a look this week.
Nah don't worry, take your time :)
Hi, sorry for ghosting you on this, personal life got in the way.
Is still issue still relevant for you ?
Imagine I have a
UNIQUE
constraint in my Db. I may use the error that the prepared statement generates to detect that the value I'm trying to insert is already present. If I catch the error and handle it myself, zig-sqlite still prints an error when callingstmt.deinit()
:https://github.com/vrischmann/zig-sqlite/blob/19535aab5760eeaf2979a9dadfca3bb21d1594b9/sqlite.zig#L1556
This isn't desirable because it's being logged with the "error" level which always shows. This is a good approach for debugging during development, but it's ugly in production.
Note: Sorry for not following the template, I clicked on "open a new issue" on the line of code mentioned above and created the issue by itself :(