Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用动态表名/命名参数创建表_Python_Sql_Sqlite - Fatal编程技术网

Python 使用动态表名/命名参数创建表

Python 使用动态表名/命名参数创建表,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

是否有一种方法可以使用命名样式或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','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

绑定变量不是文本占位符:它们替换数据,而不是标识符或查询文本的某一部分(因为它们的内容是在语句解析完成后使用的)。所以你需要对这个进行连接