I'm trying to grasp SQLite to do some stuffs I want it to do, but it is sometimes too hash to me :)
So what i'm I wrong with this code??
#!/usr/bin/
# SQLite command to be used with the applications
import sqlite3 as sqlite
import os
class SqliteCommands:
def ___init__(self, parent):
self.parent = parent
# Create database
def onCreateDb(self):
conn = sqlite.connect("./databases/test.db")
cur = conn.cursor()
return (conn, cur)
#Create New Table
def onCreateTable(self, cur, t_name):
cur.execute("""CREATE TABLE IF NOT EXISTS %s(Date TEXT, Explanations TEXT, Deposit REAL, Withdraw REAL, Balance REAL)""" %(t_name,))
#Create Rows for the New table
def onInsertRows(self, cur, t_name, tuple_rows):
#add name to a tuple (unpack and pack the tuple)
names = list(tuple_rows)
names.insert(0, t_name)
rows = tuple(names)
print rows
cur.execute("""INSERT INTO %s VALUES(%s, %s, %f, %f, %f )""" %(rows))
x = SqliteCommands()
con, cur = x.onCreateDb()
x.onCreateTable(cur, "Steve")
t = ("03/02/2009", "Billing for electricity", 200.0, 230.0, 270.0)
x.onInsertRows(cur, "Steve", t)