I cannot get the code work. I want to use placeholder than a fixed value. When use fixed value it works but not placeholder. Please correct me!
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")