Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- conn = sqlite3.connect('example.db')
- c = conn.cursor()
- # Create table
- try:
- c.execute('''CREATE TABLE studenthelper
- ( subject text)''')
- # Insert a row of data
- c.execute("INSERT INTO studenthelper VALUES ('mathematics')")
- c.execute("INSERT INTO studenthelper VALUES ('matan')")
- c.execute("INSERT INTO studenthelper VALUES ('history')")
- # Save (commit) the changes
- conn.commit()
- except:
- print("it's fine, db ")
- c.execute('''CREATE TABLE subjects
- ( subject text, theme text)''')
- try:
- c.execute("INSERT INTO subjects VALUES ('mathematics ,theme1')")
- c.execute("INSERT INTO subjects VALUES ('mathematics ,theme2')")
- c.execute("INSERT INTO subjects VALUES ('mathematics ,theme3')")
- c.execute("INSERT INTO subjects VALUES ('matan ,theme1')")
- c.execute("INSERT INTO subjects VALUES ('matan ,theme2')")
- c.execute("INSERT INTO subjects VALUES ('matan ,theme3')")
- c.execute("INSERT INTO subjects VALUES ('history ,theme1')")
- c.execute("INSERT INTO subjects VALUES ('history ,theme2')")
- except:
- print("subjects is exit")
- #t = ('mathematics',)
- #c.execute('SELECT * FROM subjects WHERE symbol=?', t)
- #print(c.fetchone())
- # We can also close the connection if we are done with it.
- # Just be sure any changes have been committed or they will be lost.
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement