/Doc/includes/sqlite3/shortcut_methods.py

http://unladen-swallow.googlecode.com/ · Python · 21 lines · 11 code · 6 blank · 4 comment · 1 complexity · 4dc077c8efa7882fa8a82ba8c463c9b1 MD5 · raw file

  1. import sqlite3
  2. persons = [
  3. ("Hugo", "Boss"),
  4. ("Calvin", "Klein")
  5. ]
  6. con = sqlite3.connect(":memory:")
  7. # Create the table
  8. con.execute("create table person(firstname, lastname)")
  9. # Fill the table
  10. con.executemany("insert into person(firstname, lastname) values (?, ?)", persons)
  11. # Print the table contents
  12. for row in con.execute("select firstname, lastname from person"):
  13. print row
  14. # Using a dummy WHERE clause to not let SQLite take the shortcut table deletes.
  15. print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows"