DALB Active Member Licensed User Feb 25, 2025 #1 Hello everyone. Just a thing: I wish to do a SUM of amounts in a table (column named 'montant': With this code... Code: Copy Dim va As Double=sql.ExecQuerySingleResult( _ ' "SELECT SUM(montant) FROM depenses WHERE idlieu = " & f ) where f is an id in a list ( 'Dim f As Int=li.Get(t)') appears this message ... B4X: Copy java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null BUT, with this code which is the same operation... Code: Copy For u=0 To li.Size-1 cursor=sql.ExecQuery( _ "SELECT montant FROM depenses WHERE idlieu=" & li.Get(u)) montants(u)=0 Do While cursor.nextrow montants(u)=montants(u)+cursor.GetDouble("montant") Loop montants(u)=Round2(montants(u),2) Next where 'li' is a list containing the id of the table's cities and where I make a reading line by line not using sqlite SUM. It works perfectly. I don't think that it's a problem of writing my values. What about this ? I have read other lines on the web, but I didn't find any answer for this, even if I found a solution.
Hello everyone. Just a thing: I wish to do a SUM of amounts in a table (column named 'montant': With this code... Code: Copy Dim va As Double=sql.ExecQuerySingleResult( _ ' "SELECT SUM(montant) FROM depenses WHERE idlieu = " & f ) where f is an id in a list ( 'Dim f As Int=li.Get(t)') appears this message ... B4X: Copy java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null BUT, with this code which is the same operation... Code: Copy For u=0 To li.Size-1 cursor=sql.ExecQuery( _ "SELECT montant FROM depenses WHERE idlieu=" & li.Get(u)) montants(u)=0 Do While cursor.nextrow montants(u)=montants(u)+cursor.GetDouble("montant") Loop montants(u)=Round2(montants(u),2) Next where 'li' is a list containing the id of the table's cities and where I make a reading line by line not using sqlite SUM. It works perfectly. I don't think that it's a problem of writing my values. What about this ? I have read other lines on the web, but I didn't find any answer for this, even if I found a solution.
teddybear Well-Known Member Licensed User Feb 26, 2025 #2 DALB said: Code: Copy Dim va As Double=sql.ExecQuerySingleResult( _ ' "SELECT SUM(montant) FROM depenses WHERE idlieu = " & f ) Click to expand... Why not using parameterized queries? B4X: Copy sql.ExecQuerySingleResult2( "SELECT SUM(montant) FROM depenses WHERE idlieu =?", Array(f) ) 'or cursor=sql.ExecQuery2( _ "SELECT montant FROM depenses WHERE idlieu=?",Array(li.Get(u))) Upvote 0
DALB said: Code: Copy Dim va As Double=sql.ExecQuerySingleResult( _ ' "SELECT SUM(montant) FROM depenses WHERE idlieu = " & f ) Click to expand... Why not using parameterized queries? B4X: Copy sql.ExecQuerySingleResult2( "SELECT SUM(montant) FROM depenses WHERE idlieu =?", Array(f) ) 'or cursor=sql.ExecQuery2( _ "SELECT montant FROM depenses WHERE idlieu=?",Array(li.Get(u)))
aeric Expert Licensed User Longtime User Feb 26, 2025 #3 Inside the For loop, check for the value of li.Get(t). It may returns Null value. Code: Copy For t = 0 To li.Size - 1 Log("id=" & li.Get(t)) Upvote 0
Inside the For loop, check for the value of li.Get(t). It may returns Null value. Code: Copy For t = 0 To li.Size - 1 Log("id=" & li.Get(t))
DALB Active Member Licensed User Feb 26, 2025 #4 Hi ! Just a moment, I'll try these and come back to tell you what about ! Thanks for these points ! I' m busy ! Upvote 0
Hi ! Just a moment, I'll try these and come back to tell you what about ! Thanks for these points ! I' m busy !
DALB Active Member Licensed User Mar 8, 2025 #5 Aeric and Teddybear, thanks for your answers. Copying my pages in a new app, it works perfectly. I don't know why, amybe a bug somewhere ! Upvote 0
Aeric and Teddybear, thanks for your answers. Copying my pages in a new app, it works perfectly. I don't know why, amybe a bug somewhere !
peacemaker Expert Licensed User Longtime User Mar 8, 2025 #6 DALB said: WHERE idlieu = " & f Click to expand... f must be quoted, as it can be considered as a column name or an expression that should be evaluated first. Upvote 0
DALB said: WHERE idlieu = " & f Click to expand... f must be quoted, as it can be considered as a column name or an expression that should be evaluated first.