Advertisement
paulogp

sqlite3

Aug 7th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # paulogp
  3. # sqlite3 example
  4.  
  5. import sqlite3
  6.  
  7. def main():
  8.     the_db = sqlite3.connect("test.db")
  9.    
  10.     the_db.execute("drop table if exists test")
  11.     the_db.row_factory = sqlite3.Row
  12.     the_db.execute("create table test (column_a text, column_b int)")
  13.     the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("one", 1))
  14.     the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("two", 2))
  15.     the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("three", 3))
  16.     the_db.commit()
  17.    
  18.     the_cursor = the_db.execute("select column_a, column_b from test order by column_a")
  19.     for the_row in the_cursor:
  20.         print(the_row["column_a"], the_row["column_b"])
  21.  
  22. if __name__ == "__main__": main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement