code
con = sqlite3.connect('db.sqlite3')
cur = con.cursor()
sql = 'SELECT id FROM ?WHERE source_id = ?'
cur.execute(sql, ('article_table', 41945,))
one = cur.fetchone()
con.close()
report errors
sqlite3.OperationalError: near "?": syntax error
reason
sqlite3 placeholder (?) Cannot be used for column or table names.
Placeholders are used to insert or retrieve values of data from the database in order to prevent SQL injection.
Solution:
con = sqlite3.connect('db.sqlite3')
cur = con.cursor()
sql = 'SELECT id FROM article_table WHERE source_id = ?'
cur.execute(sql, (41945,))
one = cur.fetchone()
con.close()
Read More:
- Python: Django exception when executing migrate operation: django.db.utils.OperationalError: (1051, “Unknown table’xxx’”)
- Python syntax error except exception, e: ^ syntax error: invalid syntax
- Python Use sqlalchemy Error: pymssql.ProgrammingError: (102, b“Incorrect syntax near ‘(‘.DB-Lib error
- [Solved] Django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
- [Solved] Python operate Kafka error: SyntaxError: invalid syntax
- [Solved] DLL load failed while importing _sqlite3: the specified module could not be found.
- Python_Syntax error: unexpected character after line continuation character
- Python Error: bash syntax error near unexpected token `newline’
- [Solved] Failed to install PIP for MacOS, prompt: syntax error: invalid syntax
- Pychar: How to Fix using SQLite to report an error: java.lang.ClassNotFoundException
- [Solved] PIP Install tensorflow error: syntax error: invalid syntax
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed
- [Solved] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- Linux installs Python and upgrades Python
- Python Error: pip install mysql-connector-python failed
- Python classes that connect to the database
- [Solved] Python Error: tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.