Devendra Member Licensed User Longtime User Feb 20, 2015 #1 I have a requirement in my application that one SQ-Lite Database to be shared with 2 Android application running @ the same time, Both the applications will be accessing the SQ-Lite file same time. Is it possible with Android OS and also whether SQ-Lite support this scenario. It is like in Windows Access Database can be shared with 2 Applications @ the same time. Is it the Same Scenario Here. Pls Advice.
I have a requirement in my application that one SQ-Lite Database to be shared with 2 Android application running @ the same time, Both the applications will be accessing the SQ-Lite file same time. Is it possible with Android OS and also whether SQ-Lite support this scenario. It is like in Windows Access Database can be shared with 2 Applications @ the same time. Is it the Same Scenario Here. Pls Advice.
KMatle Expert Licensed User Longtime User Feb 20, 2015 #2 Where is the db located? On one device and another needs data from it? How do you connect the devices? You could have one device as a server and other devices connect to it (via TCP/IP socket) and get the data from *one* app running on it (like a db server). Upvote 0
Where is the db located? On one device and another needs data from it? How do you connect the devices? You could have one device as a server and other devices connect to it (via TCP/IP socket) and get the data from *one* app running on it (like a db server).
Devendra Member Licensed User Longtime User Feb 20, 2015 #3 The database in in the same device difference is 2 different applications are accessing the same Database there is no TCP/IP involvement. Upvote 0
The database in in the same device difference is 2 different applications are accessing the same Database there is no TCP/IP involvement.
S sorex Expert Licensed User Longtime User Feb 20, 2015 #4 how will they connect? via blutooth? Upvote 0
Devendra Member Licensed User Longtime User Feb 20, 2015 #5 Even the Both Applications in same device, All i want is when one application is using the database, another service app in the same device is sharing the same database there is no Bluetooth or any external device involvement, The Database is in the External Folder Upvote 0
Even the Both Applications in same device, All i want is when one application is using the database, another service app in the same device is sharing the same database there is no Bluetooth or any external device involvement, The Database is in the External Folder
eurojam Well-Known Member Licensed User Longtime User Feb 20, 2015 #6 There are some interesting threads outside of this forum about this, but I am not shure, if this is really helping you: http://stackoverflow.com/questions/7053809/share-sqlite-database-between-2-android-apps Upvote 0
There are some interesting threads outside of this forum about this, but I am not shure, if this is really helping you: http://stackoverflow.com/questions/7053809/share-sqlite-database-between-2-android-apps
K keirS Well-Known Member Licensed User Longtime User Feb 20, 2015 #7 B4A doesn't support it. The main issue is that SQLite does not support multiple writes to the DB at the same time. You can read at the same time but not write. B4A only supports transactions in exclusive mode which means you cannot read from the DB at the same time as it is being written to. SQLite has another transaction mode which is non exclusive and allows reads and writes at the same time but the SQL library doesn't implement this. One way round this is to do all the DB code in a service in one of the apps and use intents in the other app to communicate with the service. That way you only have one app doing all the reads and updates to the database. Upvote 0
B4A doesn't support it. The main issue is that SQLite does not support multiple writes to the DB at the same time. You can read at the same time but not write. B4A only supports transactions in exclusive mode which means you cannot read from the DB at the same time as it is being written to. SQLite has another transaction mode which is non exclusive and allows reads and writes at the same time but the SQL library doesn't implement this. One way round this is to do all the DB code in a service in one of the apps and use intents in the other app to communicate with the service. That way you only have one app doing all the reads and updates to the database.
udg Expert Licensed User Longtime User Feb 20, 2015 #8 One way round this is to do all the DB code in a service in one of the apps and use intents in the other app to communicate with the service. That way you only have one app doing all the reads and updates to the database. Click to expand... I would have suggested that same solution. A more general one could be that of set all the DB-related functions in a sticky service belonging to a no-UI app so to have any number of apps using intents to send/receive data from that first "service-only" app (that in a way plays the role of a dedicated DBMS). udg Upvote 0
One way round this is to do all the DB code in a service in one of the apps and use intents in the other app to communicate with the service. That way you only have one app doing all the reads and updates to the database. Click to expand... I would have suggested that same solution. A more general one could be that of set all the DB-related functions in a sticky service belonging to a no-UI app so to have any number of apps using intents to send/receive data from that first "service-only" app (that in a way plays the role of a dedicated DBMS). udg
S sorex Expert Licensed User Longtime User Feb 20, 2015 #9 I guess it might work when you open and close the database after every query. As it are apps and not service the chance that a write happends at the same time is none existing I guess since you need to switch apps extremely fast to make that possible. You only need to store it at a location both apps can read. Upvote 0
I guess it might work when you open and close the database after every query. As it are apps and not service the chance that a write happends at the same time is none existing I guess since you need to switch apps extremely fast to make that possible. You only need to store it at a location both apps can read.
S sorex Expert Licensed User Longtime User Feb 20, 2015 #10 ok, just read it's an app and service. I guess the open/send query/close method would work here aswell. there's a minimal chance that both might write at the same time but then can be solved by writing a file to the same location that has the app/service name in it. so it becomes Code: if file.exists(lockfile)=false createLockfile opendb send query closedb removeLockfile else queueQueryForLaterRetry end if Last edited: Feb 20, 2015 Upvote 0
ok, just read it's an app and service. I guess the open/send query/close method would work here aswell. there's a minimal chance that both might write at the same time but then can be solved by writing a file to the same location that has the app/service name in it. so it becomes Code: if file.exists(lockfile)=false createLockfile opendb send query closedb removeLockfile else queueQueryForLaterRetry end if
thedesolatesoul Expert Licensed User Longtime User Feb 20, 2015 #11 I would like to point out the correct Android solution is to use ContentProviders: http://developer.android.com/guide/topics/providers/content-providers.html Otherwise you have to provide your own semaphore mechanism as suggested by others above. Upvote 0
I would like to point out the correct Android solution is to use ContentProviders: http://developer.android.com/guide/topics/providers/content-providers.html Otherwise you have to provide your own semaphore mechanism as suggested by others above.