Reputation: 13
please help new to coding
I keep getting an error
in getSidsWithStatusX sip.execute(query) DatabaseError: ORA-00900: invalid SQL statement
def getSidsWithStatusX(startDate, statusX, endDate=None):
query = cfg.GET_STARTDATE_QUERY.format(startDate=startDate)
if (endDate):
query += cfg.GET_ENDDATE_QUERY.format(endDate=endDate)
query += cfg.GET_STATUSID_QUERY.format(statusX=statusX)
logger.debug(query)
sip = rdb.getCursor('sip')
sip.execute(query)
data = sip.fetchall()
sip.rollback()
sids = []
Im passing :
GET_STARTDATE_QUERY = """
select sid
from contact_requests
where entry_date > '{startDate:'%d-%b-%Y'}'
"""
GET_ENDDATE_QUERY = """
and entry_date < '{endDate:'%d-%b-%Y'}'
"""
GET_STATUSID_QUERY = """
and request_status_id = '{statusX:s}'
"""
Upvotes: 1
Views: 2642
Reputation: 781721
You shouldn't have quotes around the format specification in the format string. Those quotes are being copied into the result, so you end up with two sets of quotes, one from the quote before {
and after }
, and the other from the quotes around %d-%b-%Y
.
GET_STARTDATE_QUERY = """
select sid
from contact_requests
where entry_date > '{startDate:%d-%b-%Y}'
"""
Upvotes: 2