Android Question sf = Main.mysql.ExecQueryAsync()

julio lutjens

Member
Licensed User
Longtime User
dear all,
sorry bother, I am in a hole and no ideas to go out, please some light. I am consulting a database in MYSQL in order to know if the codbar is in the database or not.
I need to know how capture "something" when the codbar isnt in the DB.

I am using:

' connection to MYSQL
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Main.mysql.InitializeAsync("mysql", Main.driver, Main.jdbcUrl, Main.Username, Main.Password)
Wait For MySQL_Ready (Success As Boolean)

If Success Then
Dim senderfile As Object
senderfile = Main.mysql.ExecQueryAsync("mysql", $"SELECT codbar,descripcion FROM maestro_formatos WHERE codbar= ? "$, Array As String(Main.codbarorigen) )
Wait For (senderfile) mysql_QueryComplete(exito As Boolean, Crsr As JdbcResultSet)

========================================================================================================
HOW CAN I CAPTURE WHEN CRSR is null ???? When the CODBAR is not in the database ???

The "EXITO" boolean always has TRUE
========================================================================================================
If exito Then

end if
end if

================================================================================

The connection with MYSqL is ok, but I need to know how capture NULL or something in order to know when the codbar is not in the database.

THANKS A LOT !!!!!!!!!
 

drgottjr

Expert
Licensed User
Longtime User
por favor, no dupliques, camarada.

success doesn't refer to the result set (which may or may not be empty).
it refers to the validity of the request and transmission to the client.
it is especially important in non-query requests, as it indicates whether
or not the request was successful.

as for a query, normally you would test for sucess, then whether the result set is
initialized. a typical approach is something like this example here:

https://www.b4x.com/android/forum/threads/b4x-sql-with-wait-for.79532/#content

B4X:
Dim SenderFilter As Object = sql.ExecQueryAsync("SQL", "SELECT * FROM table1", Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
   Do While rs.NextRow
     Log(rs.GetInt2(0))
   Loop
   rs.Close
Else
   Log(LastException)
End If


"do while resultset.nextrow" allí está la clave. if there is no "nextrow", the result set was empty. success == true just means there was no
error. an empty resultset isn't an error, it's just an empty resultset
 
Upvote 1
Top