Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # paulogp
- # sqlite3 example
- import sqlite3
- def main():
- the_db = sqlite3.connect("test.db")
- the_db.execute("drop table if exists test")
- the_db.row_factory = sqlite3.Row
- the_db.execute("create table test (column_a text, column_b int)")
- the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("one", 1))
- the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("two", 2))
- the_db.execute("insert into test (column_a, column_b) values (?, ?)", ("three", 3))
- the_db.commit()
- the_cursor = the_db.execute("select column_a, column_b from test order by column_a")
- for the_row in the_cursor:
- print(the_row["column_a"], the_row["column_b"])
- if __name__ == "__main__": main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement