Ordering Database Inserts

Added by iNTERFACEWARE

How to use transactions and conn:begin{}, conn:execute{} and conn:commit{} to insert data into a database in a specific order.

Source Code
local conn = db.connect{
api=db.MY_SQL,
name='Test',
user='root',
password='',
live = true
}

function main()
conn:begin{}
conn:execute{
sql=[[INSERT INTO Patient (GivenName, LastName)
VALUES('Fred', 'Smith')]],
live=true
}
local ID=conn:execute{sql='SELECT @@IDENTITY', live=true}
conn:execute{
sql=[[INSERT INTO Kin (FirstName, LastName, PatientId)
VALUES('Fred', 'Smith', ]]..ID[1].Column_1..")",
live=true
}
conn:commit{}
end
Description
How to use transactions and conn:begin{}, conn:execute{} and conn:commit{} to insert data into a database in a specific order.