

Nota: Estoy trabajando con Sqlite 2 y Ams 8.5.2.0

--============================================================================================
-- Centralized SQLite read query processor. Reads data from the database
-- This is implemented for network use so that we can check to see if the database is
-- locked and keep trying until it is unlocked.
-- Parameters: DB (the full path and file name of the database), Query (the query to you want to run)
function ReadFromDB(DB, Query)
nDbLockError = 30005
while nDbLockError == 30005 do
QueryTable = SQLite.QueryToTable(DB, Query)
-- Check for error
nDbLockError = Application.GetLastError();
-- If nDbLockError = 30005 then the database is locked so repeat
end
-- Check to make sure there was no other error
if nDbLockError == 0 then
return QueryTable
else
Dialog.Message("Error", "The following error occurred while reading data from the database:\r\n\r\n Error #: ".. nDbLockError .. "\r\n\r\n" .. SQLite.GetLastErrorString(), MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1)
return "Error"
end
end
--============================================================================================
DB = "Path and file name of your database"
ReadCustomerQuery = "SELECT * FROM Customers"
tblCustomers = ReadFromDB(DB, ReadCustomerQuery)
if tblCustomers ~= "Error" then
-- Do what ever with the returned data
end
--============================================================================================
-- Centralized SQLite write query processor. Saves data to the database
-- This is implemented for network use so that we can check to see if the database is
-- locked and keep trying until it is unlocked.
-- Parameters: DB (the full path and file name of the database), Query (the query to you want to run)
function WriteToDB(DB, Query)
nDbLockError = 30005
while nDbLockError == 30005 do
SQLite.Query(DB, Query)
-- Check for error
nDbLockError = Application.GetLastError();
-- If nDbLockError = 30005 then the database is locked so repeat
end
-- Check to make sure there was no other error
if nDbLockError == 0 then
return "OK"
else
if nDbLockError == 30001 or nDbLockError == 30019 then
return "OK"
else
Dialog.Message("Error", "The following error occurred while performing the operation on the database:\r\n\r\n Error #: " .. nDbLockError .. "\r\n\r\n" .. SQLite.GetLastErrorString(), MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1)
return "Error"
end
end
end
--============================================================================================
DB = "Path and file name of your database"
sTitle = "Mr."
sFirstName = "John"
sLastName = "Smith"
AddNewCustomerQuery = "INSERT INTO Customers values(NULL, \""..sTitle.."\", \"" .. sFirstName.."\", \"".. sLastName.."\")"
AddNewCustomer = WriteToDB(DB, AddNewCustomerQuery)
if AddNewCustomer == "OK" then
-- Save was successfull.
end