Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import sqlite3
  2.  
  3. conn = sqlite3.connect("phenvar.db")
  4.  
  5. def createTables(conn):
  6. c = conn.cursor()
  7.  
  8. c.execute('''CREATE TABLE IF NOT EXISTS publications (id INTEGER PRIMARY KEY, title TEXT, abstract TEXT, FOREIGN KEY (id) REFERENCES snps (rsid))''')
  9. c.execute('''CREATE TABLE IF NOT EXISTS snps (rsid INTEGER PRIMARY KEY, publication_id INTEGER, FOREIGN KEY (publication_id) REFERENCES publications (id))''')
  10.  
  11. def addSnpsRow(conn, rsid, publication_id):
  12. c = conn.cursor()
  13.  
  14. c.execute("INSERT INTO snps VALUES (?, ?)", (rsid, publication_id))
  15.  
  16. def addPublicationsRow(conn, id, title, abstract):
  17. c = conn.cursor()
  18.  
  19. c.execute("INSERT INTO publications VALUES (?, ?, ?)", (id, title, abstract))
  20.  
  21.  
  22.  
  23. createTables(conn)
  24. #addSnpsRow(conn, 1234, 9000)
  25. #addPublicationsRow(conn, 9000, "Jon farts a lot", "In this paper we examine just what went wrong in Jon's ass to cause such a problematic existence.")
  26. addSnpsRow(conn, 2222, 2)
  27. addSnpsRow(conn, 3333, 3)
  28. addSnpsRow(conn, 4444, 4)
  29. addSnpsRow(conn, 5555, 5)
  30.  
  31. addPublicationsRow(conn, 2, "title2", "abstract2")
  32. addPublicationsRow(conn, 3, "title3", "abstract3")
  33. addPublicationsRow(conn, 4, "title4", "abstract4")
  34. addPublicationsRow(conn, 5, "title5", "abstract5")
  35.  
  36.  
  37. conn.commit()
  38. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement