PageRenderTime 183ms CodeModel.GetById 101ms app.highlight 2ms RepoModel.GetById 78ms app.codeStats 0ms

/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
 1import sqlite3
 2
 3class Point(object):
 4    def __init__(self, x, y):
 5        self.x, self.y = x, y
 6
 7def adapt_point(point):
 8    return "%f;%f" % (point.x, point.y)
 9
10sqlite3.register_adapter(Point, adapt_point)
11
12con = sqlite3.connect(":memory:")
13cur = con.cursor()
14
15p = Point(4.0, -3.2)
16cur.execute("select ?", (p,))
17print cur.fetchone()[0]