PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Doc/includes/sqlite3/createdb.py

http://unladen-swallow.googlecode.com/
Python | 28 lines | 22 code | 4 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
 4import sqlite3
 5import os
 6
 7DB_FILE = "mydb"
 8
 9if os.path.exists(DB_FILE):
10    os.remove(DB_FILE)
11
12con = sqlite3.connect(DB_FILE)
13cur = con.cursor()
14cur.execute("""
15        create table people
16        (
17          name_last      varchar(20),
18          age            integer
19        )
20        """)
21
22cur.execute("insert into people (name_last, age) values ('Yeltsin',   72)")
23cur.execute("insert into people (name_last, age) values ('Putin',     51)")
24
25con.commit()
26
27cur.close()
28con.close()