Advertisement
wiley_pastebin

1.3 SQL2

Nov 18th, 2019
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.52 KB | None | 0 0
  1. # Creates OR opens a file called mydb WITH a SQLite3 DB
  2. db = sqlite3.CONNECT('data/mydb')
  3. # GET a cursor object cursor = db.cursor()
  4. # CHECK IF TABLE users does NOT exist AND CREATE it
  5. cursor.EXECUTE('''CREATE TABLE IF NOT EXISTS users(id INTEGER   PRIMARY KEY, name TEXT,  phone TEXT, email TEXT unique, password TEXT)''')
  6. # Commit the CHANGE
  7. db.commit()
  8. # Catch the exception
  9. EXCEPT Exception AS e:
  10. # Roll back any CHANGE IF something goes wrong
  11. db.ROLLBACK()
  12. raise e
  13. finally:
  14. # Close the db connection
  15. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement