Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

SQL quotation for Symbian DBMS (See related posts)

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')" %\
  (e32db.format_time(timestamp),
   distance,
   comment.replace("'", "''") )

- 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)

One day, I wish to see an easy-to-use SQL abstraction layer for pys60.
An ORM(SQLObject or SQLAlchemy) is even better.

Comments on this post

madhoinz posts on Nov 20, 2007 at 15:45
float needs %e instead of %d

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts