2024-04-27 05:02:09 发布
网友
我有一个列表,其中包含要从数据库表中检索的列的名称。 我的问题是如何让光标选择列表中指定的列。在将nameList包含在select语句中之前,是否必须将其转换为字符串变量?谢谢
nameList = ['A','B','C','D',...] with sqlite3.connect(db_fileName) as conn: cursor = conn.cursor() cursor.execute(""" select * from table """)
nameList = ["'A(pct)'",'B','C','D',...] with sqlite3.connect(db_fileName) as conn: cursor = conn.cursor() cursor.execute(""" select {} from table """.format(", ".join(nameList)))
{只要您能确保您的输入^被清理,就可以避免攻击:
... qry = "select {} from table;" qry.format( ','.join(nameList) ) cursor.execute(qry)
如果您使用的是非常旧的Python版本,请执行以下操作:
{只要您能确保您的输入^被清理,就可以避免攻击:
如果您使用的是非常旧的Python版本,请执行以下操作:
^{pr2}$相关问题 更多 >
编程相关推荐