diff options
author | Kali Kaneko <kali@futeisha.org> | 2013-02-04 19:20:12 +0900 |
---|---|---|
committer | Kali Kaneko <kali@futeisha.org> | 2013-02-04 19:20:12 +0900 |
commit | 4189e53a881e52de0945375a72b8748143c5bd13 (patch) | |
tree | 23ed8e0600dc3c62da7a95e50f778c79a9be1e75 /doc/includes/sqlite3/shortcut_methods.py |
initial commit
Diffstat (limited to 'doc/includes/sqlite3/shortcut_methods.py')
-rw-r--r-- | doc/includes/sqlite3/shortcut_methods.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/includes/sqlite3/shortcut_methods.py b/doc/includes/sqlite3/shortcut_methods.py new file mode 100644 index 0000000..fcfc631 --- /dev/null +++ b/doc/includes/sqlite3/shortcut_methods.py @@ -0,0 +1,21 @@ +from pysqlite2 import dbapi2 as sqlite3 + +persons = [ + ("Hugo", "Boss"), + ("Calvin", "Klein") + ] + +con = sqlite3.connect(":memory:") + +# Create the table +con.execute("create table person(firstname, lastname)") + +# Fill the table +con.executemany("insert into person(firstname, lastname) values (?, ?)", persons) + +# Print the table contents +for row in con.execute("select firstname, lastname from person"): + print row + +# Using a dummy WHERE clause to not let SQLite take the shortcut table deletes. +print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows" |