B4J Question [BANanoMySQLE] and VueMaterial (Update record)

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
With this Code
B4X:
Dim dbsql As BANanoMySQLE
dbsql.Initialize(pgIndex.db, "", "", "")
'dbsql.SetConnection(pgIndex.dbhost, pgIndex.user, pgIndex.pass)
dbsql.query = $"UPDATE ${currentable.ToUpperCase} SET TELEFONO = '${telefono}', CELLULARE = '${cellulare}', MAIL = '${mail}' WHERE CLIENTE.ID = '${id}'"$
dbsql.Execute(dbsql.query)
dbsql.json = BANano.CallInlinePHPWait(dbsql.MethodName, dbsql.Build)
dbsql.FromJSON

The update work fine but the dbsql.Response.Ok is always false, why?
 

micro

Well-Known Member
Licensed User
Longtime User
dbsql.Response is a string and does not have an .ok property, perhaps you want to check dbsql.ok.
I'm sorry I was wrong to write, I use dbsql.Ok
You can also check the reason after dbsql.fromjson by logging dbsql.error, this should give you the exact reason why nothing is saved.
maybe you misread my previous post, the record is updated correctly but the error still appears (dbsql.Ok is False)
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
The recommended way to check success of your DB operation is the following

1. Check dbSQL.Response if Success / Error and then
2. Check dbSQL.AffectedRecords

This is the php code that is used behind the scenes..

B4X:
if (!($result = $stmt->get_result())) {
            $response = $stmt->error;
            $resp['response'] = "Error";
            $resp['error'] = $response;
            $resp['result'] = array();
            $output = json_encode($resp);
            die($output);
        }
       
        $affRows = $conn->affected_rows;
        $rows = array();
        while ($row = $result->fetch_assoc()) {
            $rows[] = $row;
        }
        $resp['response'] = "Success";
        $resp['error'] = '';
        $resp['result'] = $rows;
        $resp['affectedRows'] = $affRows;
        $output = json_encode($resp);
        break;

Doing those 2 checks is guaranteed to give out the expected result.

The .OK parameter is generated when you call .FromJSON, it expects a particular format of a response. For example, by default, OK = false

B4X:
'convert the json
Sub FromJSON As BANanoMySQLE
    OK = False
    If json.StartsWith("{") Or json.Startswith("[") Then
        Dim m As Map = BANano.FromJson(json)
        response = m.Get("response")
        error = m.Get("error")
        result = m.Get("result")
        affectedRows = m.Get("affectedRows")
        If response = "Success" Then
            OK = True
        End If
    Else
        response = json
        error = json
        result = NewList
        affectedRows = -1
    End If
    Return Me
End Sub

So in your case, what is returned does not start with { or [ I wouldn't know why that is though. Perhaps if you log dbsql.json after you retrieve it might provide you with what is happening.

Ta!
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
So in your case, what is returned does not start with { or [ I wouldn't know why that is though. Perhaps if you log dbsql.json after you retrieve it might provide you with what is happening.
This is the result of log(dbsql.json):
B4X:
{"response":"Error","error":"","result":[]}
The result of log(dbsql.affectedRoes) is 0
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
If the result is 0, it means nothing was changed due to affected records being 0. Perhaps PM me your project I will check what could be happening.

Q(uestion). Are you running this from an external server or from your development server.

A(sumption). If you are running from an external webserver, did you update the BANano.PHPHost in AppStart to point to your external web server IP/Domain Name?
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
If the result is 0, it means nothing was changed due to affected records being 0. Perhaps PM me your project I will check what could be happening.

Q(uestion). Are you running this from an external server or from your development server.

A(sumption). If you are running from an external webserver, did you update the BANano.PHPHost in AppStart to point to your external web server IP/Domain Name?
both locally and on an external server the problem is the same
See PM, thanks
 
Upvote 0
Top