B4J Question Using jSQL to Lock a mySQL table for writing

Discussion in 'B4J Questions' started by MegatenFreak, Sep 16, 2018.

  1. MegatenFreak

    MegatenFreak Member

    Hello.
    I'm writing an app that allows several computers to add new orders to the database. To avoid any conflicts, I want to make sure that when one system is adding a new list of orders, no others can interrupt and will have to wait for the first one to finish up. I understand that the most straightforward way for it is to use the SQL command "LOCK TABLE mytable WRITE;" and once finished: "UNLOCK TABLES;"

    I'm using mySql and InnoDB.
    What I want to know is that will these commands work when passed as a query to jSQL? In other words, can I use the following code:
    Code:
    sql1.BeginTransaction
    Try
        sql1.ExecQuery(
    "LOCK TABLE mytable WRITE")
        
    'Do both reading and writing operations on the database....
        '.......
        sql1.ExecQuery("UNLOCK TABLES")
    Catch
        
    Log(LastException.Message)
        
    sql.RollBack
    EndTry
    If that works, yaaay! If it doesn't, how else can I do it conveniently?

    Thank you so much in advance.
     
    ShaneG30 likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should use ExecNonQuery for such commands. I expect it to work.
     
    MegatenFreak likes this.
  3. MegatenFreak

    MegatenFreak Member

    Thank you Erel. I will.
    You're the mastermind behind the incredible b4x, so if you expect it to work, then it should!:D
     
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