test user, on Thursday, August 15, 2019 07:35 PM, wrote...
> The reason for the notification is to minimize time spent waiting.
I will tell you what I did with 10 PMs working with a shared windows drive with
an SQLite DB. But, take it with a grain of salt, unless you have high-blood
pressure, which if it is so, may suggest a salt substitute? :-)
Before every write to the DB, I would call a function that would check if
someone was writing to the DB:
while (SharedDBBlocked(false))
std.c.time.msleep(500); // waits 1/2 second
This is what SharedDBBlocked did...
char[] SharedDBBlocked(bool ShowMsgBox)
{
char[] ttdir = std.path.getDirName(sqldb); // =
r"L:\Data\OpenJobsTool\AllOpenProjs.db";
ttdir = ttdir ~ "\\" ~ "dbLockedBy.txt"; // checks for a file in the same
spot where the sharedDB is
char[] who = null;
if (std.file.exists(ttdir)) // someone is writing to the DB
{
try
{
who = cast(char[]) ttdir.read();
}
catch (FileException e)
{
return who;
}
if (who == pm["FirstName"]) // The PMs lack of patience (3-10 seconds).
Long story.
{
if (DeleteFile(ttdir, eStr))
info.text = ttdir[std.string.rfind(ttdir,r"\") .. $] ~ " file deleted.";
return null;
}
else
{
char[] t = who ~ " is writing to the SharedDB. Waiting for release...";
error.text = t;
if (ShowMsgBox)
msgBox(t);
return who;
}
}
return who;
}
Once this was DB was release, you would call for,
LockDBForDataWriting();
to take control of the DB. This is what it contains...
char[] LockDBForDataWriting()
{
while (SharedDBBlocked(false)) //check again to make sure...
std.c.time.msleep(1500);
error.text = "";
char[] ttdir = std.path.getDirName(sqldba); // =
r"L:\Data\OpenJobsTool\AllOpenProjs.db";
ttdir = ttdir ~ "\\dbLockedBy.txt";
char[] t = "";;
if (!std.file.exists(ttdir))
{
try
{
ttdir.write(pm["FirstName"]);
t = pm["FirstName"];
}
catch (FileException e)
{
ttdir.write(GetUserName());
t = GetUserName();
}
}
return t;
}
Once you have control, do some work on the DB...
string q = "INSERT ...; ";
try
{
wdb.execute(q);
}
catch (DBIException dbe)
{
UnLockDBForDataWriting();
msgBox("ERR605: Could not ...:" ~ dbe.toString());
return 1;
}
UnLockDBForDataWriting();
return 0;
And that is it. Of course, this is a primitive and slow way of doing it, but
these were inpatient PMs, and it worked for a long time. If your writters are
not human, the wait times could be lowered and it would be made faster. Just
FYI. Thanks.
josé
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users