Python 使用动态表名/命名参数创建表
是否有一种方法可以使用命名样式或q-mark样式,如wayPython 使用动态表名/命名参数创建表,python,sql,sqlite,Python,Sql,Sqlite,是否有一种方法可以使用命名样式或q-mark样式,如way[这里提到了][1],使表创建动态化 def Table_Exists(connexion,table_name): cur = connexion.cursor() row = cur.execute("SELECT name FROM sqlite_master where type =:type_name and name =:table ",{'type_name':'table','tabl
[这里提到了][1]
,使表创建动态化
def Table_Exists(connexion,table_name):
cur = connexion.cursor()
row = cur.execute("SELECT name FROM sqlite_master where type =:type_name and name =:table ",{'type_name':'table','table':table_name}).fetchall()
if len(row)==0:
sys.stderr.write('No such table exists in the database.\n')
sys.stderr.write('Creating a new table in the database.\n')
cur.execute('''CREATE TABLE (?) (TradeDate text, Ticker text, Action text, Qty integer, Price real''',(table_name))
return False
else:
return True
我尝试使用这两种样式都会导致sqllite3。OperationalError绑定变量不是文本占位符:它们替换数据,而不是标识符或查询文本的某一部分(因为它们的内容是在语句解析完成后使用的)。所以你需要对这个进行连接