PageRenderTime 873ms CodeModel.GetById 661ms app.highlight 2ms RepoModel.GetById 209ms app.codeStats 0ms

/Doc/includes/sqlite3/executemany_1.py

http://unladen-swallow.googlecode.com/
Python | 24 lines | 18 code | 6 blank | 0 comment | 1 complexity | 591c1ad6757d2a37a86398aedea32a8d MD5 | raw file
 1import sqlite3
 2
 3class IterChars:
 4    def __init__(self):
 5        self.count = ord('a')
 6
 7    def __iter__(self):
 8        return self
 9
10    def next(self):
11        if self.count > ord('z'):
12            raise StopIteration
13        self.count += 1
14        return (chr(self.count - 1),) # this is a 1-tuple
15
16con = sqlite3.connect(":memory:")
17cur = con.cursor()
18cur.execute("create table characters(c)")
19
20theIter = IterChars()
21cur.executemany("insert into characters(c) values (?)", theIter)
22
23cur.execute("select c from characters")
24print cur.fetchall()