In addition to executing SQL statements directly, Iguana offers another method for writing to databases using a Database Schema File (*.vdb), db.tables{}
and the conn:merge{}
function.
...
Expand |
---|
title | Error Handling Merges |
---|
|
The merge process all happens within a single database transaction. If it fails, the transaction is rolled back and nothing is altered in the database. This behavior can be optionally turned off if you pass in transaction=false as an argument. Just like with conn:execute{} , you can use pcall() to catch and gracefully handle any errors that arise from conn:merge{} operations: Code Block |
---|
| function doMerge(conn, T)
local R = conn:merge{data=T, live=true}
end
function main()
-- create empty table
local T = db.tables{vdb='report.vdb, name ='Patients'}
-- map vdb table values
T.Patients[1].FirstName = 'John'
T.Patients[1].LastName = 'Doe'
T.Patients[1].ID = 1
-- call merge function and handle response
local Success, R = pcall(doMerge, conn, T)
if not Success then
iguana.log('Error during merge: ', R.message)
end
end |
|
...