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:
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
 

Mahares

Expert
Licensed User
Longtime User
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?
B4X:
SQL1.ExecNonQuery2("UPDATE TblProva SET Inviato = ? WHERE Id = ?", Array As Object(1, ID))

If that does not work for you you can try this:
B4X:
Wait for (UpdateMyRecord) Complete (res As Object)
B4X:
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

OliverA

Expert
Licensed User
Longtime User
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
B4X:
Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
to
B4X:
Wait For (SenderFilter) SQL1_NonQueryComplete (Success As Boolean)
should do the trick.

FYI:
Instead of
B4X:
SQL1.AddNonQueryToBatch("UPDATE TblProva SET Inviato = 1 WHERE Id = " & ID, Null)
do
B4X:
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
Top