SQLite puede soportar múltiples usuarios a la vez. Solo bloquea toda la base de datos al escribir.
puede probar la "solución" sugerida por dermot (Foro IR)
"La base de datos solo se bloquea cuando alguien le escribe datos. El problema es que nadie puede acceder a él mientras está bloqueado, ni siquiera leer datos, por lo que una consulta simple que llena un cuadro de lista, por ejemplo, fallará.
Sin embargo, una solución simple es pasar todas sus consultas a través de una función central que luego las envía a la base de datos. Si la base de datos está bloqueada, devolverá el error # 30005. La función puede verificar este error y seguir intentando la consulta hasta que ya no reciba 30005 (por supuesto, querrá verificar otros errores). Generalmente, la base de datos solo estará bloqueada por un tiempo muy corto, por lo que no verá ninguno. retrasar.
Esto es más aparente y evita el problema de usar archivos de bloqueo cuando no se eliminan debido a un bloqueo o lo que sea.
Esto me ha funcionado incluso accediendo a una base de datos en un servidor remoto. Por supuesto, solo será adecuado para un pequeño número de usuarios. Si tienes muchos usuarios que escriben en la base de datos, las cosas se volverán lentas."
Función de lectura:
GLOBAL
--============================================================================================
-- 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
--============================================================================================
LLAMADA
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
Función de escritura:
GLOBAL
--============================================================================================
-- 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
--============================================================================================
LLAMADA
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
regards