Problem with DBUtils.ExecuteMap

mrjaw

Active Member
Licensed User
Longtime User
My problem now is with DBUtils.ExecuteMap

When I run DBUtils.ExecuteMap and there is no records this functions returns NULL but


PHP:
Dim m As Map
   m.Initialize
   m = DBUtils.ExecuteMap(Main.SQL, "SELECT * FROM t_press",Null)
      
   If m = Null Then 'Null will return if there is no match'
      Main.prefer.puid=0      
   Else
      '
      Main.prefer.Initialize
      Main.prefer.codigo=m.Get("f_codigo")
      Main.prefer.nombre=m.Get("f_nombre")
   End If
The problem here is DBUtils.ExecuteMap return NULL but when it ask for NULL doesnt execute true condition because m,map, is not initialized not null so execute the else but how there is no initialize get error

PHP:
java.lang.RuntimeException: Object should first be initialized (Map).
 

kimble01

Member
Licensed User
Longtime User
It should be:
B4X:
If m.IsInitialized = False Then

I am using dbutils.executeMap, and when I test for isinitialized, the map is null, and vice versa. What is the recommended way to test for return for executemap?
 
Upvote 0

kimble01

Member
Licensed User
Longtime User
Go on the safe side:
B4X:
If m <> Null AND m.IsInitialized Then

Thanks! I will.

Edit: When I put the test in exactly as this I get "Try Catch Block last error message: java.lang.NullPointerException" and the map is null. This is in a code module and the map is declared in the process globals. This is a big deal for me, as elsewhere in the code I have many similar tests. I appreciate any insight you can give for this issue. I think for now I will use executequerysingle result as the test for population...
 
Last edited:
Upvote 0
Top