Android Question Sql Update

Pesciolina

Active Member
Licensed User
Longtime User
Hi,
I need to have the record update confirmation before extracting the next one, in the method I use where am I wrong?

Thaks
Marco
B4X: Copy
SQL1.AddNonQueryToBatch("UPDATE TblProva SET Inviato = 1 WHERE Id = " & ID, Null)
    
    Dim SenderFilter As Object = SQL1.ExecNonQueryBatch("SQL1")
    Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
        
    If Success Then
        TimerInvioHttp.Enabled = True
        CallSubDelayed(Main, "FillWebView")
        Else
        Log("NonQuery: " & Success)
        
    End If
 
I need to have the record update confirmation before extracting the next one
Since you are updating 1 record, why do you need the batch method. Did you try this or is that not one of your choices?
Code: Copy
SQL1.ExecNonQuery2("UPDATE TblProva SET Inviato = ? WHERE Id = ?", Array As Object(1, ID))

If that does not work for you you can try this:
Code: Copy
Wait for (UpdateMyRecord) Complete (res As Object)
Code: Copy
Sub UpdateMyRecord As ResumableSub
    SQL1.ExecNonQuery2("UPDATE TblProva SET Inviato = ? WHERE Id = ?", Array As Object(1, ID))
    Return Null
End Sub
 
Last edited:
Upvote 0
Dim SenderFilter As Object = SQL1.ExecNonQueryBatch("SQL1")
You're telling ExecNonQueryBatch to preface the callback with SQL1, yet you preface your callback with just SQL.
So changing
Code: Copy
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
to
Code: Copy
Wait For (SenderFilter) SQL1_NonQueryComplete (Success As Boolean)
should do the trick.

FYI:
Instead of
Code: Copy
SQL1.AddNonQueryToBatch("UPDATE TblProva SET Inviato = 1 WHERE Id = " & ID, Null)
do
Code: Copy
SQL1.AddNonQueryToBatch("UPDATE TblProva SET Inviato = ? WHERE Id = ?", Array(1, ID))
(@Mahares does this in his example, using the ExecNonQuery2 method)

1) You can prevent SQL injection attacks this way
2) Depending on the underlying JDBC driver, the driver may cache the "compiled" SQL statement for you. In this case, since the statement is always the same, you may gain some performance improvements.

Point #1 above is really important and Point #2 is just some icing on the cake.

@Mahares:
ExecNonQuery2 is still a blocking call (even with your workaround). Does it matter in the end? Only testing would give an answer (I don't know if a simple Update statement would take much longer in a weak signal environment).
 
Upvote 0
Back
Top