Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import sqlite3
  2. con = sqlite3.connect(':memory:')
  3.  
  4. cur = con.cursor()
  5.  
  6. cur.execute("create table platonic_ideal_of_a_grommet( id real, name text, color text, spindles real)")
  7. data = [
  8. (0, "economy", "red", 3),
  9. (1, "standard", "green", 5),
  10. (2, "deluxe", "blue", 7)
  11. ]
  12. cur.executemany("insert into platonic_ideal_of_a_grommet values (?, ?, ?, ?)", data)
  13.  
  14. cur.execute("create table possibly_flawed_manifestation_of_a_grommet( id real, ideal_id real, owner text, custom_engraving text)")
  15. data = [
  16. (0, 2, "Alice", "let this grommet symbolize our bond"),
  17. (1, 1, "Bob", "what even IS a grommet? Buying this just to find out"),
  18. (2, 2, "Carol", None)
  19. ]
  20. cur.executemany("insert into possibly_flawed_manifestation_of_a_grommet values (?, ?, ?, ?)", data)
  21.  
  22. #find all deluxe grommets with a custom engraving
  23. for row in cur.execute("select * from possibly_flawed_manifestation_of_a_grommet x join platonic_ideal_of_a_grommet y on x.ideal_id = y.id where x.custom_engraving is not null and y.name == 'deluxe'"):
  24. print(row)
  25.  
  26. #output: (0.0, 2.0, 'Alice', 'let this grommet symbolize our bond', 2.0, 'deluxe', 'blue', 7.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement