/Doc/includes/sqlite3/adapter_point_1.py

http://unladen-swallow.googlecode.com/ · Python · 16 lines · 12 code · 4 blank · 0 comment · 1 complexity · bb7c68aead6dfbc28f2279d19a387d3c MD5 · raw file

  1. import sqlite3
  2. class Point(object):
  3. def __init__(self, x, y):
  4. self.x, self.y = x, y
  5. def __conform__(self, protocol):
  6. if protocol is sqlite3.PrepareProtocol:
  7. return "%f;%f" % (self.x, self.y)
  8. con = sqlite3.connect(":memory:")
  9. cur = con.cursor()
  10. p = Point(4.0, -3.2)
  11. cur.execute("select ?", (p,))
  12. print cur.fetchone()[0]