Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- # connect function opens a connection to the SQLite database file,
- conn = sqlite3.connect('session.db')
- print(conn)
- # Output: <sqlite3.Connection object at 0x0000015A87671730>
- # Drop a table name Crypto if it exists already
- try:
- conn.execute('DROP TABLE IF EXISTS `Crypto` ')
- except Exception as e:
- raise(e)
- finally:
- print('Table dropped')
- # Create a new Table named as Crypto
- try:
- conn.execute('''
- CREATE TABLE Crypto
- (ID INTEGER PRIMARY KEY,
- NAME TEXT NOT NULL,
- Date datetime,
- Open Float DEFAULT 0,
- High Float DEFAULT 0,
- Low Float DEFAULT 0,
- Close Float DEFAULT 0);''')
- print ("Table created successfully");
- except Exception as e:
- print(str(e))
- print('Table Creation Failed!!!!!')
- finally:
- conn.close() # this closes the database connection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement