B4J Question Concurrent access to SQLite databases

Firpas

Active Member
Licensed User
Longtime User

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Hi to everybody

As i said in my last post, i have a webApp (B4j non UI App) that work with varius SQLite databases

B4X:
Sub Process_Globals
    Public BD1 As SQL
    Public BD2 As SQL
    ...
End Sub

All Updates operations (Insert, Update and Delete) are made by Transaction (like this)

B4X:
Sub LoginClear
    BD1.BeginTransaction
    Try
        BD1.ExecNonQuery("DELETE FROM LOGINS")
        BD1.TransactionSuccessful
    Catch
        Log(LastException)
        BD1.Rollback
    End Try
End Sub

And before stop the server, i close all the connections

B4X:
Public Sub AppClose
       
    BD1.Close
    BD2.Close
    …

    ExitApplication
End Sub

But i have two questions:

Must i do StopMessageLoop before ExitApplication?

And what will happen if any user is updating any database when i stop de app?

Thanks in advance
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Must i do StopMessageLoop before ExitApplication?
No.

And what will happen if any user is updating any database when i stop de app?
If the transaction was not committed then the data will be lost. If you are worried about this case then you can do something like:
B4X:
Sub AppClose
 Main.ServerIsStopping = True
 Sleep(3000)
 BD1.Close
 BD2.Close
 ExitApplication
End Sub

You should check this flag value before you start updating the database.
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Thanks for your replay but ...

Where is this flag value??
 

Attachments

  • Sin título-1.png
    Sin título-1.png
    13.5 KB · Views: 170
  • Sin título-2.png
    Sin título-2.png
    7.4 KB · Views: 183
  • Sin título-3.png
    Sin título-3.png
    14.1 KB · Views: 174
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Sorry for my clumsiness.
Now I understand what you want to say, but ... there are many sites where databases are updated.

I think I'd better set a parameter to block new incoming connections and wait until all users have logged out. This will be the time to stop the server without risk to the databases.

Thank you very much for your cooperation

regards
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
wait until all users have logged out.
I hope you include timing out people, else you might wait for quite awhile :D. I've had plenty of cases where folks just wander off, without ever logging out. Usually sites will post notifications of outages and if you just happen to be using them into that period, oh well. Plus, if it is a WebApp (traditional, not WebSocket), then it is also non-persistent and you can't be 100 percent sure if someone is actually, right at the moment, using your site (you can infer by keeping state server side, but that is all you can do).
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Thanks for your suggestion but it is not a traditional web application.
This application only answers data extracted and processed in JSON format.
The client for this webapp is not an internet browser but rather a desktop application (B4J UI), in which all users must be registered to access it (private web), and its disconnection is also recorded. .
 
Upvote 0
Top