Archived:How to use quotation in SQL in PySymbian
It's not always easy to remember how to use quotation in Symbian SQL database. Here's a simple reminder.
- date/time need to be quoted with # and formatted with e32db.format_time
- int/float need no quotation
- string need to be quoted with single quote and repeat the quote if it happen to be inside.
- binary can't be used. You may need to encode it (eg. base64)
Here's a simple example :
import e32db, time
timestamp = time.time()
distance = 10.5
comment = "I'm fine, thanks!"
# for date/time, int/float, and string respectively
sql = "INSERT INTO events VALUES (#%s#, %d, '%s')" %\
comment.replace("'", "''") )