Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. import sqlite3
  2.  
  3. conn = sqlite3.connect("mydatabase.db")
  4. #conn.row_factory = sqlite3.Row
  5. cursor = conn.cursor()
  6.  
  7. sql = "SELECT * FROM albums WHERE artist=?"
  8. cursor.execute(sql, [("Red")])
  9. print(cursor.fetchall()) # or use fetchone()
  10.  
  11. print("Here's a listing of all the records in the table:")
  12. for row in cursor.execute("SELECT rowid, * FROM albums ORDER BY artist"):
  13. print(row)
  14.  
  15. print("Results from a LIKE query:")
  16. sql = "SELECT * FROM albums WHERE title LIKE 'The%'"
  17. cursor.execute(sql)
  18.  
  19. print(cursor.fetchall())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement