Cannot create TRIGGER as shown in SQLite Example #1470
Details for the issue
What did you do?
I tried to create a trigger on an existing database. But without success. So instead I went over to sqlite.org and tried the examples.
The executed lines are:
And it fails on the last line.
What did you expect to see?
I expected to execute the sample code and thus successfully create a trigger.
What did you see instead?
incomplete input: CREATE TRIGGER cust_addr_chng INSTEAD OF UPDATE OF cust_addr ON customer_address BEGIN UPDATE customer SET cust_addr=NEW.cust_addr WHERE cust_id=NEW.cust_id
Useful extra information
The three statements execute successfully in the sqlite3 command line tool which is
What operating system are you using?
What is your DB4S version?
Did you also
The text was updated successfully, but these errors were encountered:
Aah, that's probably the 'gotcha' then. When executed as one lump, DB4S just 'eats the lot'. When told to parse each 'line', it gets a bit confused with the last line ending with ;END, as a semi-colon is normally used to terminate a SQL statement (as in the top two lines). So DB4S is actually treating the 3rd line as 2 separate commands...
So the workaround is to move the 3rd line in all its glory to a separate Execute SQL tab, so it can be run as a whole. So you can still execute it line by line, but not fully on the last line.....
An easier workaround would be to select the current line and click the normal
But yeah, this is definitely a bug. The easiest way to trigger it is by only having this simple statement and trying to execute it by clicking the
As @chrisjlocke suspected, this is because we split the statement at the semicolon. See #780 for details why. I'll have to think about this a bit more - no idea how to fix this and still have the features from #780.
This commit changes the execution logic in the Execute SQL tab. Before this we were trying to first get the exact part of the SQL text to execute and then execute it without further checking. After this we're only trying to find an exact start position for the SQL text to execute while the end position is only a rough estimate. This way the exact end position can be determined by SQLite. This fixes issue #1470. It also cleans up the code a bit and (hopefully) makes it a bit easier to read.