8👍
I encountered this problem too. I changed the %d to %s, and it is solved. Wish this is useful for you.
5👍
The problem is that you are not making substitutions properly in your select string. From docs:
def execute(self, query, args=None):
"""Execute a query.
query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.
Note: If args is a sequence, then %s must be used as the
parameter placeholder in the query. If a mapping is used,
%(key)s must be used as the placeholder.
Returns long integer rows affected, if any
"""
So, it should be:
cursor.execute("SELECT price FROM Items WHERE itemID = (
SELECT item_id FROM Purchases
WHERE purchaseID = ? AND customer_id = ?)",
(self.purchaseID, self.customer))
- Django: vps or shared hosting?
- How to add a default array of values to ArrayField?
- Python – pyodbc call stored procedure with parameter name
2👍
The reason is that you are using ‘%d’. When you use ‘%’ in SQL, the execute will interpret the ‘%’ as the format. You should write your statement like this:
cursor.execute("SELECT price FROM Items WHERE itemID = (
SELECT item_id FROM Purchases
WHERE purchaseID = %%d AND customer_id = %%d)",
[self.purchaseID, self.customer])
- How to call asynchronous function in Django?
- Can't fix "zipimport.ZipImportError: can't decompress data; zlib not available" when I type in "python3.6 get-pip.py"
- Django, phpmyadmin and mysql?
- Django: use render_to_response and set cookie
- Saving Django ModelForm with a ForeignKey
- How to access get request data in django rest framework
- How to send django objects to celery tasks?
- Why does JSON returned from the django rest framework have forward slashes in the response?
- Add dynamic field to django admin model form
1👍
Worked for me using double %%
"SELECT title, address from table t1, table t2 on t1.id=t2.id where t1.title like '%%Brink%%' "
👤Ram
0👍
from django.db import connection
print(connection.queries)
The code above should display all the requeries that are executed on the request.
Source:stackexchange.com