Please consider offering answers and suggestions to help other students!
And if you fix a problem by following a suggestion here,
it would be great if other interested students could see a short
"Great, fixed it!" followup message.
I have the same question!
After looking up online, it should be something like:
CREATE TRIGGER abort_delete_from_my_tbl
BEFORE DELETE ON my_tbl
BEGIN
SELECT RAISE(ABORT, 'You can''t delete records from my_tbl');
END;
However, my output runs perfectly, but the way the error is presented in the Expected section of the test cases don't match my output.
Expected section shows:
Trigger failed as expected due to related po_items: Error: Cannot delete pos record with associated po_items.
My section shows:
Unexpected sqlite3 error: Error: near line 12: Cannot delete pos record with associated po_items
Don't know how to fix that though!
I also got the 'Unexpected sqlite3 error: Error: near line 13: Cannot delete pos record with associated po_items' error
I used both abort & fail but the results remained the same (also as the hint provided by the question we're supposed to use abort to solve this one),I have no idea where should i debug and find where the issues are. I didn't find relevant materials for the raise() that could help me solve this problem, and it raises my concern that if this kind of situation would happen in the exam, as the materials provided from lms do not provide enough support for students to solve the problems
The reason you're not getting the correct answer is due to your format, not your SQL grammar. You need to ensure the error is in Line 12; otherwise, you won't get the expected result. A simple way to address this is by ensuring there are no blank lines in your command.
Actually this is a little bit silly but you have to put period (.) on the message
'Cannot delete pos record with associated po_items.'
It should be something like this. Found it after meddling around.