Android Question MYSQL update with VARIABLE

Samo

Member
Licensed User
Longtime User
Hello,
Can you please help me with MYSQL problem.
I am using MAriaDB library and B4A latest version

This is working:
'MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-16' WHERE `promet`.`ime` = 'JON DOE' AND `promet`.`datum` = '2017-05-14'")


When i try to use variable vime not working.

Dim vime As String
vime = "JON DOE"

MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-16' WHERE `promet`.`ime` =" .vime. "AND `promet`.`datum` = '2017-05-20'"")
MySQLConnection.ExecuteNonQueryBatch("updatepromet")
 

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-16' WHERE `promet`.`ime` = " &vime& " AND `promet`.`datum` = '2017-05-20'")
try to remove the dot
 
Last edited:
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
did you remove the last quotation mark? i edit the code sample at post #2 .. try it again
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
=" .vime. "
B4A is not PHP.

If you want to concenate strings you should use & or better directly use the Smart String Literal.
 
Upvote 0

Samo

Member
Licensed User
Longtime User
Yes i remove it.

B4X:
    MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-21' WHERE `promet`.`ime` =" &vime& "AND `promet`.`datum` = '2017-05-20'")
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
&vime& " AND `
put spacing after vime

edit:
also add apostrophe
B4X:
`ime` ='" &vime& "' AND `promet`
 
Last edited:
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
use logs to see the result .. if you didnt put space before the AND
the result will be = JON DOEAND

B4X:
dim vime as string
vime ="JON DOE"
dim query as string
query = "UPDATE `promet` SET `datum` = '2017-01-16' WHERE `promet`.`ime` = " &vime& " AND `promet`.`datum` = '2017-05-20'"

log(query)
 
Upvote 0

Samo

Member
Licensed User
Longtime User
Same result - grrrrrr :)

B4X:
    MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-23' WHERE `promet`.`ime` ='" &vime& "' AND `promet`.`datum` = '2017-05-20'")

B4X:
    MySQLConnection.AddNonQueryToBatch ("UPDATE `promet` SET `datum` = '2017-01-23' WHERE `promet`.`ime` =" &vime& " AND `promet`.`datum` = '2017-05-20'")
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
add this line when using release to access logs
B4X:
#bridgelogger: true

logs.png
 
Last edited:
Upvote 0

afields

Member
Licensed User
Hello.
In what i know if you would use directly in Heidi (which is a query tool for databases) you would write:
UPDATE promet SET datum = '2017-01-16' WHERE ime = vime AND datum` = '2017-05-20'
for that i assume that:
i've got a table whose name is promet;
that that table has fields datum ( which is a string), and ime (which is the variable)
so ( i do not have that library ) but it seem to me that you would write:
"update promet set datum='2017-01-16' where ime=".vime." and datum='2017-05-20'"
 
Upvote 0
Top