equal
deleted
inserted
replaced
|
1 import sqlite3 |
|
2 |
|
3 class 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 |
|
13 con = sqlite3.connect(":memory:") |
|
14 con.create_aggregate("mysum", 1, MySum) |
|
15 cur = con.cursor() |
|
16 cur.execute("create table test(i)") |
|
17 cur.execute("insert into test(i) values (1)") |
|
18 cur.execute("insert into test(i) values (2)") |
|
19 cur.execute("select mysum(i) from test") |
|
20 print cur.fetchone()[0] |