我有一个从环境文件中读取的变量数据库。我正在尝试在游标执行语句中使用它,如下所示。
config={}
with open('environment.yml','r') as f:
config = yaml.safe_load(f)
db = config['database_name']
result = cur.execute("TRUNCATE TABLE {db}.my_table")
result = cur.executemany('INSERT INTO {db}.my_table\
(id, description,code)\
VALUES (?, ?, ?)',
list(tuple(row) for row in co.values))
我尝试过使用,但不确定这是否是在字符串中包含变量的正确方法。
queryString = f'''TRUNCATE TABLE {env_db}.smartselect_qc_ordercodes'''
result = cur.execute("TRUNCATE TABLE {db}.my_table")
result = cur.executemany('INSERT INTO {db}.my_table\
(id, description,code)\
VALUES (?, ?, ?)',
list(tuple(row) for row in co.values))
st = "TRUNCATE TABLE {db}.my_table".format(db=db)