Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import sqlite3
  2. conn = sqlite3.connect('example.db')
  3.  
  4. c = conn.cursor()
  5.  
  6. # Create table
  7. try:
  8.     c.execute('''CREATE TABLE studenthelper
  9.             ( subject text)''')
  10.  
  11. # Insert a row of data
  12.     c.execute("INSERT INTO studenthelper VALUES ('mathematics')")
  13.     c.execute("INSERT INTO studenthelper VALUES ('matan')")
  14.     c.execute("INSERT INTO studenthelper VALUES ('history')")
  15.  
  16. # Save (commit) the changes
  17.     conn.commit()
  18. except:
  19.     print("it's fine, db ")
  20.  
  21. c.execute('''CREATE TABLE subjects
  22.             ( subject text, theme text)''')
  23. try:
  24.     c.execute("INSERT INTO subjects VALUES ('mathematics ,theme1')")
  25.     c.execute("INSERT INTO subjects VALUES ('mathematics ,theme2')")
  26.     c.execute("INSERT INTO subjects VALUES ('mathematics ,theme3')")
  27.     c.execute("INSERT INTO subjects VALUES ('matan ,theme1')")
  28.     c.execute("INSERT INTO subjects VALUES ('matan ,theme2')")
  29.     c.execute("INSERT INTO subjects VALUES ('matan ,theme3')")
  30.     c.execute("INSERT INTO subjects VALUES ('history ,theme1')")
  31.     c.execute("INSERT INTO subjects VALUES ('history ,theme2')")
  32.  
  33. except:
  34.     print("subjects is exit")
  35.  
  36.    
  37. #t = ('mathematics',)
  38. #c.execute('SELECT * FROM subjects WHERE symbol=?', t)
  39. #print(c.fetchone())
  40.  
  41. # We can also close the connection if we are done with it.
  42. # Just be sure any changes have been committed or they will be lost.
  43. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement