all Python 3sqlite3function
sqlite3.complete_statement()
utility functions
Checks whether a string looks like a finished SQL statement: it ends with a semicolon and has no unclosed quotes. It does not check the syntax.
Syntax
sqlite3.complete_statement(statement)
True does not mean the query is valid: complete_statement('junk;') is True too. A semicolon inside a string literal does not count: "SELECT 'a;" is False. It is meant for interactive input — deciding whether to read another line before execute(), as the python -m sqlite3 shell does.
Examples
import sqlite3
print(sqlite3.complete_statement('SELECT 1')) # → False
print(sqlite3.complete_statement('SELECT 1;')) # → True
print(sqlite3.complete_statement('мусор;')) # → True — синтаксис не проверяется
print(sqlite3.complete_statement("SELECT 'a;")) # → False — ; внутри кавычек
See also
Open in the full glossarydocs.python.orgReport an inaccuracy