Android Question [SOLVED] How to use smart string literal with SQL

stanks

Active Member
Licensed User
Longtime User
for example i have some stuff in list. i have 2 types of values. numbers and string. numbers are integers only. strings are not only characters but i have /, ?, etc. (like web links).

example:

listNumbers, listNames and listL are the same size
B4X:
For i = 0 To listNumbers.Size - 1
  sql1.ExecNonQuery($"INSERT INTO lTest VALUES(2, ${listNumbers.Get(i)}, ${listNames.Get(i)}, 1, ${listL.Get(i)}, 1)"$)

with this code i always get error
B4X:
    (near "kolo": syntax error (code 1): , while compiling: INSERT INTO lTest VALUES(2, 1, kolo1 - kolo2, 1, /456/234/44?xx=2, 1))

any idea?

thanks

p.s. Logging of above statement gives correct string for inserting
 

npsonic

Active Member
Licensed User
B4X:
For i = 0 To listNumbers.Size - 1
  sql1.ExecNonQuery($"INSERT INTO lTest VALUES(2, '${listNumbers.Get(i)}' , '${listNames.Get(i)}' , 1, '${listL.Get(i)}' , 1)"$)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
The correct answer is to use ExecNonQuery2.

B4X:
sql1.ExecNonQuery($"INSERT INTO lTest VALUES(2, ? ,? , 1, ? , 1)"$, Array As String(listNumbers.Get(i), ...))


Small correction .. should be
B4X:
sql1.ExecNonQuery2($"INSERT INTO lTest VALUES(2, ? ,? , 1, ? , 1)"$, Array As String(listNumbers.Get(i), ...))
 
Upvote 0
Top