Urgent: SQL script error on database test

I am unable to run a SQL script on SQLITE STUDIO,

Please below is the script:

// DROP TABLE IF EXISTS widgetSales; CREATE TABLE widgetSales(id INTEGER PRIMARY KEY, item_id INT, customer_id INT, quan INT, price INT, reconciled INT); 

INSERT INTO widgetSales(item_id, customer_id, quan, price, reconciled) VALUES (1, 3, 10, 500,1);

INSERT INTO widgetSales(item_id, customer_id, quan, price, reconciled) VALUES (2, 2, 6, 100,0);

INSERT INTO widgetSales(item_id, customer_id, quan, price, reconciled) VALUES (3, 1, 4, 700,0); 

CREATE TRIGGER updatewidgetSales BEFORE UPDATE ON widgetSales BEGIN SELECT RAISE(ROLLBACK, 'Cannot update table "widgetSales"') FROM widgetSales WHERE id=[NEW.id](http://new.id/) AND reconciled=1; END;

BEGIN TRANSACTION; 

UPDATE widgetSales SET quan=9 WHERE id=1; 

END TRANSACTION; SELECT *FROM widgetSales; 

// when I run the BEGIN TRANSACTION - END TRANSACTION… I have this error message : [18:16:25] Error while executing SQL query on database ‘test’: cannot start a transaction within a transaction.

Thanks for your help in advance.

Well obviously it thinks you are in a transaction before you begin the transaction. Looking at your code, are you sure you don’t want tin include the INSERT INTO and create trigger statements in the transaction as well? The idea behind transactions is that you want to run multiple statements where if any of them fail, it rolls them all back.

One test you can try is to run the INSERT INTO and CREATE TRIGGER stuff independently first. Then do the transaction. See if that works first and then you can introduce the other statements in to see which is breaking it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.