PageRenderTime 364ms CodeModel.GetById 212ms app.highlight 2ms RepoModel.GetById 149ms app.codeStats 0ms

/Doc/includes/sqlite3/mysumaggr.py

http://unladen-swallow.googlecode.com/
Python | 20 lines | 16 code | 4 blank | 0 comment | 0 complexity | 2d3c0e1c5d46bf969b13571edb67a8ed MD5 | raw file
 1import sqlite3
 2
 3class MySum:
 4    def __init__(self):
 5        self.count = 0
 6
 7    def step(self, value):
 8        self.count += value
 9
10    def finalize(self):
11        return self.count
12
13con = sqlite3.connect(":memory:")
14con.create_aggregate("mysum", 1, MySum)
15cur = con.cursor()
16cur.execute("create table test(i)")
17cur.execute("insert into test(i) values (1)")
18cur.execute("insert into test(i) values (2)")
19cur.execute("select mysum(i) from test")
20print cur.fetchone()[0]