B4J Question total rows from db table via jRDC

Sifu

Active Member
Hello,
in PDO you can use one liner(almost) to get the total nr of rows of your DB table
pdo:
$nRows = $pdo->query('select count(*) from blah')->fetchColumn();
echo $nRows;
is there something similar for jRDC, so I do not need to fetch all data and then count it in my program, but let the server count it?

Thanks a lot.
 

Sifu

Active Member
ok I used this in config.properties:
B4X:
sql.select_countallrows=query('select count(*) from tablename')->fetchColumn();

then used this in the program to fetch it:
B4X:
Private Sub totalrows_btn9_MouseClicked (EventData As MouseEvent)
    GetTotalRecords
End Sub

Sub GetTotalRecords
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_countallrows",Array())
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'work with result
        Dim row() As Object = res.Rows.Get(0)
        Log(row(0))
        idad = row(0)
    Else
        Log("ERROR: " & j.ErrorMessage)
        CSSUtils.SetStyleProperty(result_ad_txt17,"-fx-text-fill","#FF0000")
        result_ad_txt17.Text = "Something went wrong"
    End If
    j.Release
    
    totalrows_txt18.Text = idad
    
End Sub

giving this error:
B4X:
<pre>    java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near &apos;query(&apos;select count(*) from tablename&apos;)-&gt;fetchColumn()&apos; at line 1</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>

Perhaps because it is a PDO command and not MySQL ?

Thanks for any help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…