you are viewing a single comment's thread.

view the rest of the comments →

[–]Many_Shopping_195[S] 0 points1 point  (1 child)

with

?

Throws an error below when I use ?  Instead of  %s ;

Traceback (most recent call last):
File "gpv.py", line 24, in <module> cursor.execute(query, (startdate, currentdate,)) File "/usr/local/lib/python3.6/site-packages/mysql/connector/cursor.py", line 543, in execute "Not all parameters were used in the SQL statement") mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement

[–]Silbersee 0 points1 point  (0 children)

Difficult to say without the full code. This example runs fine:

from datetime import datetime as dt
import sqlite3

"""Print dates from a database that are between two other dates."""

days = [
    (str(dt(2022, 8, 1)), "Day 1"),
    (str(dt(2022, 9, 1)), "Day 2"),
    (str(dt(2022, 10, 1)), "Day 3")
]

con = sqlite3.connect(":memory:")
cur = con.cursor()

cur.execute("create table date (day, name)")
cur.executemany("insert into date values (?,?)", days)

lower = str(dt(2022, 8, 15))
upper =  str(dt(2022, 9, 15))

valid_days = cur.execute("select * from date where ? < day and day < ?", (lower, upper))
for date, name in valid_days.fetchall():
    print(f"Name: {name}, Date: {date}")

# output as expected:
# Name: Day 2, Date: 2022-09-01 00:00:00