这是一个创建于 2506 天前的主题,其中的信息可能已经有所发展或是发生改变。
在可知参数情况下, 向 torndb 传递查询参数:
sql = 'select * from test where id=%s and name = %s '
row = conn.get(sql, 1,'admin')
# 需求 : 查询条件未知,如使用 dict
d = {
'name=': 'admin',
'id=': '1',
# .... 可能存在更多查询参数
}
where_str = '' # 这里可以拼接 d 的键名,生成 where 字符串
sql = 'select * from test ' + where_str
row = conn.get(sql, *args) # 这里的*args 怎么取到?
测试 将 d 的 value 放入 tuple 作为*args 传入,torndb 报错
2 条回复 • 2017-12-06 12:53:13 +08:00
|
|
1
wlxz 2017-12-03 08:17:57 +08:00
出发点为: 在不可知数 多查询条件下,怎么用 torndo 进行查询 自己研究了一下,用**kwargs 方式解决了,
|