SQLite Forum

PROBLEM WITH TRANSACTION
Login
Hello, I am trying to learn SQLite and I am taking an online course. I have a problem with the transaction code. In particular, the message return by status on SQL is "Error while executing SQL query on database 'test': cannot start a transaction within a transaction"

The text in the qery is:

CREATE TABLE widgetInventory (
    id INTEGER PRIMARY KEY,
    description TEXT,
    onhand INTEGER NOT NULL
);

CREATE TABLE widgetSales
( 
    id INTEGER PRIMARY KEY,
    inv_id INTEGER,
    quant INTEGER,
    price INTEGER
);

INSERT INTO widgetInventory (description, onhand) VALUES ('rock', 25);
INSERT INTO widgetInventory (description, onhand) VALUES ('paper', 25);
INSERT INTO widgetInventory (description, onhand) VALUES ('scissor', 25);
  
SELECT * FROM widgetSales; 
SELECT * FROM widgetInventory;

BEGIN TRANSACTION;
    INSERT INTO widgetSales (inv_id, quant, price) VALUES (1, 5, 100),
    UPDATE widgetInventory SET onhand = (onhand - 5) WHERE id=1;
END TRANSACTION;

The transaction code doesn't work, what's wrong?