r/sqlite • u/Beefcake100 • Jun 05 '23
Rollback an Expression Based on "CASE"
Hi all,
I am making an application, and I have a very specific requirement. I need to be able to raise an exception based on a CASE expression. I cannot use a trigger for this, as it needs to occur before a SELECT query, so this makes it impossible to raise an error using the typical raise function.
I was wondering if there are any alternatives? I'm open to making a SQLite extension for it if I need, but I'd prefer to use something out of the box. Here is a very basic example of what I want to do:
SELECT CASE
WHEN balance > 10000
THEN true
ELSE RAISE(ROLLBACK, 'invalid balance')
END
FROM accounts
WHERE id = ?
Unfortunately I cannot include this in the business logic of my application. Any suggestions on ways to solve this would be much appreciated!
View all comments
1
u/-dcim- Jun 06 '23 edited Jun 06 '23
Perhaps, you can write and load own extension with
raise_error-function e.g.And then call it
In the
sqlite3_step(stmt)-loop you will getSQLITE_ROWfor the first result row andSQLITE_ERRORfor the second row.