/Doc/includes/sqlite3/adapter_point_2.py

http://unladen-swallow.googlecode.com/ · Python · 17 lines · 12 code · 5 blank · 0 comment · 0 complexity · fec06a51ff65994fc14b665c72795859 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 adapt_point(point):
  6. return "%f;%f" % (point.x, point.y)
  7. sqlite3.register_adapter(Point, adapt_point)
  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]