=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= *****
Multiple instances of application can be started at the same time *****
***** For example two instances of application are running *****
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= An
Win32 Application runs on Windows 98/XP/2000
It uses SQLite 3.3.5 compiled with -DTHREADSAFE=1
App Creates/opens two SQLite databases one by one. (DB files are not on
network)
Checks in each database if necessary tables exist, if not creates necessary
tables in each database.
Then in loop, application accepts user commands/requests and processes
User screens allow to Add/View/Modify/Delete records.
User screens allow to get some lists/records based on queries and
calculations.
Application uses db1 and db2 as and when needed.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
***** Multiple instances of application can be started at the same time
*****
***** For example two instances of application are running *****
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Two instances of app are running. While each app is inside loop, if one app
instance hangs or killed or user terminates abruptly (Presses
Ctrl+Alt+Delete and kills the app), each database file will be in a
consistant state (SQLite is crash prrof and power-failure proof. Might leave
some rollback journal).
Questions:
1. If app instance is executing some transaction, so it might have locked
database(s) and if that app instance is being killed or hanged, will that
database will remain in locked state or lock will be released ?
2. Pointers to opened databases (db1, db2) in killed app will be consuming
resources, what will happen to them ?
2. How safe it is to continue using those databases by other app instance(s)
?
3. What precautions must be taken care of ? (to avoid database corruption,
to maintain consistant database and for better performance and to avoid any
deadlock)
/* app code snippent just to describe the logic */
int rc;
sqlite3* db1;
sqlite3* db2;
rc = sqlite3_open("C:\file1.db", &db1);
if(rc) {
printf("Cannot open file1.db: %s\n", sqlite3_errmsg(db1));
exit(1);
}
rc = sqlite3_open("C:\file2.db", &db2);
if(rc) {
printf("Cannot open file2.db: %s\n", sqlite3_errmsg(db2));
exit(1);
}
...
/* code to check if necessary tables exist in db1, if not create tables,
indexes etc.*/
/* code to check if necessary tables exist in db2, if not create tables,
indexes etc.*/
...
bool bExit = false;
do { /* loop for processing user commands */
...
/* User screens allow to Add/View/Modify/Delete records */
/* User screens allow to get some lists/records based on queries and
calculations */
/* Uses db1 and db2 as necessary */
...
if(...user chose to exit...)
bExit = true;
} while (bExit != true);
sqlite3_close(db1);
sqlite3_close(db2);
--
View this message in context:
http://www.nabble.com/Two-instances-of-app-access-same-db%2C-one-instance-hangs-or-killed-t1797037.html#a4897129
Sent from the SQLite forum at Nabble.com.