I have the following function :
def test_prod(interval1, interval2):
with connection.cursor() as cursor:
sql = 'SELECT COUNT(*) ' \
'FROM `use` ' \
'WHERE `usepcd` = 2 ' \
'AND year(`uw_datetime_end`) = year(now()) ' \
'AND uw_datetime_end >= CURDATE() - INTERVAL WEEKDAY(CURDATE()) day - INTERVAL %i week ' \
'AND uw_datetime_end < CURDATE() - INTERVAL WEEKDAY(CURDATE()) day - INTERVAL %i week ' \
% interval1 \
% interval2
cursor.execute(sql)
row = cursor.fetchall()
print(row)
return row
I tried to use the function with two integers (for the two INTERVAL %i week
statements)
stock = test_prod(1,0)
But when I do it tells me :
TypeError: not enough arguments for format string
I tried to change the %i for %s, but it didn't change anything,I tried to put commas around the parameters of the function, but nothing worked, what am I doing wrong ?
Thank you