import sqlite3 as sql

class Tables(object):
    def __init__(self):
        print "Class created!"
        
    def CreateDb(self, dbname):
        self.conn = sql.connect("?", (dbname, ))
        self.cur = self.conn.cursor()
        
    def CreateNewTable(self, tablename):#, tablename
        self.cur.execute("CREATE TABLE IF NOT EXISTS ?(id INTEGER, name TEXT)", (tablename, ))
        listed = [(1, "Mary"), (2, "Martha"), (3, "Jesca"), (4, "Don")]
        for i in listed:
            self.cur.execute("INSERT INTO test(id, name) VALUES(?, ?)", i)
        print self.cur.execute("SELECT * FROM test").fetchall()
        
    def DropTable(self, tablename):
        self.cur.execute("DROP TABLE ?", (tablename, ))
        
        


test = Tables()
test.CreateDb("test.cb")
test.CreateNewTable("testing")

Is there a question here?

Also, do you not need to perform a conn.commit() in sqlite after transactions? I know that for postgres it's a req

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.