接受用户在sqlite查询中输入的条件

zfycwa2u  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(298)

是否可以接受用户输入的介于{}和{}之间的日期条件?
例如,不必硬编码两个日期,而是希望提示我在文本框中插入两个日期——或者其他什么。

a = """
SELECT SUM(
CASE WHEN dates.dates BETWEEN '2020-06-20' AND '2020-06-24' <----
AND employee_area = 'afd.56'
AND employee_shift = 'day'
AND wkday_num IN ('1','2','3','4')
THEN employees.day ELSE 0 END) AS b
FROM dates, employees
"""
wrrgggsh

wrrgggsh1#

试着传球 ? 作为参数,可以执行多次:

a = """
SELECT SUM(
CASE WHEN dates.dates BETWEEN ? AND ?
AND employee_area = 'afd.56'
AND employee_shift = 'day'
AND wkday_num IN ('1','2','3','4')
THEN employees.day ELSE 0 END) AS b
FROM dates, employees
"""
vars = (date1,date2)
cursor = cnxn.execute(a, vars)

相关问题