I am practing using SQLite3 in Python. The version of Python is 2.7 And I am using mac os.
I cannot find any problem with my code... When I run it, I do not get any syntax error. My coding suppose to print out every element of database. It does not print anything at all.
import sqlite3
createDb = sqlite3.connect('sample.db')
queryCurs = createDb.cursor()
def createTable():
queryCurs.execute('''CREATE TABLE customers
(id INTEGER PRIMARY KEY, name TEXT, street TEXT, city TEXT, state TEXT, balance REAL)''')
def addCust(name, street, city, state, balance):
queryCurs.execute('''INSERT INTO customers (name, street, city, state, balance))
VALUES (?,?,?,?,?) ''',(name, street, city, state, balance))
def main():
createTable()
addCust('test1','123 mel','vancouver','bc', 10000000.00)
addCust('test2','145 joy','ottawa','on', 10000000.00)
addCust('test3','521 tick','toronto','on', 10000000.00)
addCust('test4','5832 tock','burnaby','bc', 10000000.00)
createDb.commit()
queryCurs.execute('SELECT * FROM customers')
for i in queryCurs:
print "\n"
for j in i:
print j
Can you tell me what I am doing wrong?
main()?