Android Question SQ Lite Database Multi-Access

Discussion in 'Android Questions' started by Devendra, Feb 20, 2015.

  1. Devendra

    Devendra Member Licensed User

    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.
     
  2. KMatle

    KMatle Expert Licensed User

    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).
     
  3. Devendra

    Devendra Member Licensed User

    The database in in the same device difference is 2 different applications are accessing the same Database there is no TCP/IP involvement.
     
  4. sorex

    sorex Expert Licensed User

    how will they connect? via blutooth?
     
  5. Devendra

    Devendra Member Licensed User

    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
     
  6. eurojam

    eurojam Well-Known Member Licensed User

  7. keirS

    keirS Well-Known Member Licensed User

    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.
     
    eurojam likes this.
  8. udg

    udg Expert Licensed User

    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
     
    keirS likes this.
  9. sorex

    sorex Expert Licensed User

    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.
     
  10. sorex

    sorex Expert Licensed User

    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
  11. thedesolatesoul

    thedesolatesoul Expert Licensed User

    NJDude and udg like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice