thommankutty
9/5/2017 - 4:33 AM

Setting up a database

Setting up a database

"""
This is a script written to learn the sqlite3 module in python
"""

# import modules
import sqlite3

# establish connection
conn = sqlite3.connect('example.db')

# create cursor object
c = conn.cursor()

# execute the cursor
c.execute('''
			CREATE TABLE IF NOT EXISTS stocks
			 (date TEXT, trans TEXT, symbol TEXT, rty REAL, price REAL)
			''')

# insert data into the table
c.execute('''
			INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)
			''')


# commit the connection
conn.commit()

# close the connection
conn.close()