Var*_*unt 0 python database sqlite executemany
好的,所以我有一个函数可以根据插件的输入选择sqlite数据库中的某些行.当只涉及一个语句时,我得到了插件来选择和获取行,但由于我想为此添加一些灵活性,我尝试在遇到列表或元组时使用executemany.然而,尽管我已经摆弄和改变了所有的东西,但仍然无法使其工作,因为sqlite语句将字符串中的每个字符视为绑定,或者因为元组中的绑定太多.这是我到目前为止的代码:
def readoffset(self,offset):
vartype = type(name)
print(vartype)
if vartype == int:
self.memcursor.execute('''select all id,matbefore,matafter,name,date
from main as main where id = ?''',[offset])
undolist = self.memcursor.fetchall()
print(undolist)
return(undolist)
elif vartype == tuple or list:
print(vartype)
self.memcursor.executemany('''select all id,matbefore,matafter,name,date
from main as main where name = (?)''', [offset])
undolist = self.memcursor.fetchall()
return(undolist)
Run Code Online (Sandbox Code Playgroud)
请看http://www.python.org/dev/peps/pep-0249/
将此方法用于产生一个或多个结果集的操作构成未定义的行为,并且允许实现
因此,executemany可用于INSERT和UPDATE,但不能用于SELECT
您可以尝试以下代码:
elif isinstance(offset, (tuple, list)):
offsets=', '.join(offset)
self.memcursor.execute('''select all id,matbefore,matafter,name,date
from main as main where name IN (?)''', [offsets])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2775 次 |
| 最近记录: |