Android Question [not SOLVED] Strange problem with QUERY MSMariaDB

Magma

Expert
Licensed User
Longtime User
Hi there to all,

something strange happens or somewhere i am wrong (as always)...

This is my code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim db As MSMaria
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    If FirstTime=True Then
    db.DisableReconnect
    db.Initialize("MySQL","192.168.168.3:3306","myroot","mypass","mydatabase")
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub MySQL_Status(Connected As Boolean, ReConnecting As Boolean, RetriesLeft As Int)
    Log($"Connected = ${Connected}"$)
    If Connected=True Then
        'i will have a simple routine to remove escape chars
        db.QueryASync("select * from cars WHERE id='myid' AND password='test';","login") 'The right one is test - but i am getting strange error
        db.EnableReconnect
    End If
End Sub

Sub MySQL_QueryResult(data As List, meta As Map)
    Log(meta)

    Dim m As Map = meta
  
    Select Case m.Get("TaskID")
        Case "login"

            If data.size > 0 Then
                ToastMessageShow("ok!",True)
                db.ExecuteASync("UPDATE INTO cars SET login=1, lastdate='"& DateTime.Date(DateTime.Now) &"', lasttime='"& DateTime.time(DateTime.Now) & "' WHERE id='myid';","")
              
            Else
                ToastMessageShow("wrong user/pass",True)
            End If
  
  
    End Select
      
End Sub


I am getting the following (if i am querying right password for ex. test):

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Raising.. mysql_status
Connected to Database
** Activity (main) Resume **
Connected = true
lib:queryasync()
lib:Exception:java.lang.NullPointerException: Attempt to invoke virtual method 'double java.math.BigDecimal.doubleValue()' on a null object reference
null
main_mysql_queryresult (java line: 377)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference
at b4a.example.main._mysql_queryresult(main.java:377)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

If i have wrong password the app return the toastmessage with wrong user/pass

So where i am having problem ?
 

fixit30

Active Member
Licensed User
Longtime User
Looks like your Update statement is incorrect. Should it be:

B4X:
UPDATE cars SET .............
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Yes that have mistake... but again have the same problem because the problem is in start (check null---> that is meta - must not null)


*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Raising.. mysql_status
Connected to Database
** Activity (main) Resume **
Connected = true
lib:queryasync()
lib:Exception:java.lang.NullPointerException: Attempt to invoke virtual method 'double java.math.BigDecimal.doubleValue()' on a null object reference
null
main_mysql_queryresult (java line: 375)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference
at b4a.example.main._mysql_queryresult(main.java:375)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
I have a kind of solution.. but not the best...

if at select have the needed fields work ok - if change with star comes the problem..

B4X:
db.QueryASync("select * from cars WHERE id='myid' AND password='test';","login")

if turned in this way:
B4X:
db.QueryASync("select id,password from cars WHERE id='myid' AND password='test';","login")
works
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
That's my table... seems something wrong ?
B4X:
CREATE TABLE cars (
   `id` VARCHAR(50) NOT NULL,
   `password` VARCHAR(50) NOT NULL,
   `isadmin` INT(1) UNSIGNED ZEROFILL NULL DEFAULT '0',
   `nowwork` DOUBLE UNSIGNED ZEROFILL NULL DEFAULT '0000000000000000000000',
   `logins` INT(1) UNSIGNED ZEROFILL NULL DEFAULT '0',
   `lastdate` DATE NULL DEFAULT NULL,
   `lasttime` VARCHAR(8) NULL DEFAULT NULL
)

have in mind change the field names for not being lucky with maria db name uses !
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
When you say the select * statement doesn't work, what actually happens when it is executed?

Have you tried executing the sql statement from an ms maria db application/manager? From a command line? Does that work?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@eps actually is working perfect from HeidiSql at the query with any query/execution i ve made

When query this:
B4X:
db.QueryASync("select * from cars WHERE id='myid' AND password='test';","login")

The error getting is this:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Raising.. mysql_status
Connected to Database
** Activity (main) Resume **
Connected = true
lib:queryasync()
lib:Exception:java.lang.NullPointerException: Attempt to invoke virtual method 'double java.math.BigDecimal.doubleValue()' on a null object reference

null
main_mysql_queryresult (java line: 375)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference
at b4a.example.main._mysql_queryresult(main.java:375)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5624)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
That's my table
the tablename ist dummy, not cars
Please post the correct definition.
How does the result from the query look like in HeidiSQL?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@DonManfred I have this problem only at specific table (and bypassed with giving at select specific fields) - at other tables (* works perfect)..

The result from HeidiSQL is:

resultquery.png


The same query select from B4A with msmariadb gives problem.
lib:queryasync()
lib:Exception:java.lang.NullPointerException: Attempt to invoke virtual method 'double java.math.BigDecimal.doubleValue()' on a null object reference
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Is it because have null in nowwork...? but again this must not give problem at query...

If you want you can use my simple routine:

B4X:
Sub isnotempty(s As String) As Boolean
   If s=Null Then
   Return False
   End If
   If s.Trim="" Then
   Return False
   Else
   Return True
   End If
   Return False
End Sub
 
Upvote 0
Top