/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

  1. import sqlite3
  2. class IterChars:
  3. def __init__(self):
  4. self.count = ord('a')
  5. def __iter__(self):
  6. return self
  7. def next(self):
  8. if self.count > ord('z'):
  9. raise StopIteration
  10. self.count += 1
  11. return (chr(self.count - 1),) # this is a 1-tuple
  12. con = sqlite3.connect(":memory:")
  13. cur = con.cursor()
  14. cur.execute("create table characters(c)")
  15. theIter = IterChars()
  16. cur.executemany("insert into characters(c) values (?)", theIter)
  17. cur.execute("select c from characters")
  18. print cur.fetchall()