/Doc/includes/sqlite3/createdb.py

http://unladen-swallow.googlecode.com/ · Python · 28 lines · 19 code · 7 blank · 2 comment · 1 complexity · a4eaba3c33793461f77f0ea536c791ed MD5 · raw file

  1. # Not referenced from the documentation, but builds the database file the other
  2. # code snippets expect.
  3. import sqlite3
  4. import os
  5. DB_FILE = "mydb"
  6. if os.path.exists(DB_FILE):
  7. os.remove(DB_FILE)
  8. con = sqlite3.connect(DB_FILE)
  9. cur = con.cursor()
  10. cur.execute("""
  11. create table people
  12. (
  13. name_last varchar(20),
  14. age integer
  15. )
  16. """)
  17. cur.execute("insert into people (name_last, age) values ('Yeltsin', 72)")
  18. cur.execute("insert into people (name_last, age) values ('Putin', 51)")
  19. con.commit()
  20. cur.close()
  21. con.close()