Is there a way to lint SQLite commands contained within a .execute()
method call for a database connection object (from Python’s sqlite3
library) from within Visual Studio Code
? I’ve seen this done in Intellij IDEA
but this is not my preference IDE. I should also note that I am using Pylance as my linter.
I’ve tried searching the settings of Visual Studio Code, specifically under the Python Linter settings, but this has produced no leads.
2
Answers
You have to install mysql-connector-python package:
Then create a Python script to connect to the database, and I can give you a simple example which uses the select statement and print line by line:
You can use command
pip install cs50
in terminal to install cs50 package.Then you can use codes
db = cs50.SQL("sqlite:///file.db") # For SQLite, file.db must exist
to connect the SQLite.There exists
.execute
method as well.The example in the document of cs50 can help you better understand:
The syntax error display of SQL statements is not supported for Pylance. You can read this issue on github for the reason. At present, there are no similar extensions in the market to meet this requirement. You have to check the correctness of the SQL statements yourself.