Executing raw SQL against SQLite with Django results in `DatabaseError: near “?”: syntax error`

后端 未结 2 1637
既然无缘
既然无缘 2021-01-22 05:31

For example, when I use cursor.execute() as documented:

>>> from django.db import connection
>>> cur = connection.cursor()
>>         


        
相关标签:
2条回答
  • 2021-01-22 05:41

    You can't substitute metadata in parameterized queries.

    0 讨论(0)
  • 2021-01-22 05:46

    You cannot use parameters in SQL statements in place of identifiers (column or table names). You can only use them in place of single values.

    Instead, you must use dynamic SQL to construct the entire SQL string and send that, unparameterized, to the database (being extra careful to avoid injection if the table name originates outside your code).

    0 讨论(0)
提交回复
热议问题