Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import sqlite3
  2.  
  3. # connect function opens a connection to the SQLite database file,
  4. conn = sqlite3.connect('session.db')
  5. print(conn)
  6. # Output: <sqlite3.Connection object at 0x0000015A87671730>
  7.  
  8. # Drop a table name Crypto if it exists already
  9. try:
  10. conn.execute('DROP TABLE IF EXISTS `Crypto` ')
  11. except Exception as e:
  12. raise(e)
  13. finally:
  14. print('Table dropped')
  15.  
  16.  
  17. # Create a new Table named as Crypto
  18. try:
  19. conn.execute('''
  20. CREATE TABLE Crypto
  21. (ID INTEGER PRIMARY KEY,
  22. NAME TEXT NOT NULL,
  23. Date datetime,
  24. Open Float DEFAULT 0,
  25. High Float DEFAULT 0,
  26. Low Float DEFAULT 0,
  27. Close Float DEFAULT 0);''')
  28. print ("Table created successfully");
  29. except Exception as e:
  30. print(str(e))
  31. print('Table Creation Failed!!!!!')
  32. finally:
  33. conn.close() # this closes the database connection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement