Android Question Sqlite saveing

TomDuncan

Active Member
Licensed User
Longtime User
Hi All,
I have a program which does this
B4X:
SQL.ExecNonQuery("UPDATE daytimes SET patient = '" & DataToSave & "', modified = 1 " & Where)
Where DataToSave is a String.
All is fine till today when testing I put in
Tom's birthday.
What has happened is the ' for Tom has corrupted the data being saved.
How can I fix this error.

I did think of Encoding Base 64 but then all previous data would not work.

Tom

oops Saving, sorry about that
 

sorex

Expert
Licensed User
Longtime User
you need to escape your DataToSave string.

B4X:
SQL.ExecNonQuery("UPDATE daytimes SET patient = '" & DataToSave.replace("'","\'") & "', modified = 1 " & Where)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you do not want to worry about escaping, you are better off using a parameterised query:
B4X:
SQL.ExecNonQuery2("UPDATE daytimes SET patient = ?, modified = ? " & Where), _
        Array As Object(DataToSave, 1))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…