sqlitepysqlite

Accessing the dot cli commands from sqlite in pysqlite


I'm looking to access the sqlite dot commands in pysql, particularly the

.tables
.schema
.import 

commands. However, when I try:

>>> db.execute(".tables")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pysqlite3.dbapi2.OperationalError: near ".": syntax error

What is the syntax that allows this?

not a dupe explained in comment


Solution

  • As @Corion said in his comment, the sqlite3 dot commands are a feature of the sqlite3 command-line utility only, not the SQL dialect supported by SQLite3. Therefore if you want to get the effect of running these commands in your own program, you have to actually implement those yourself using the publically available SQLite3 functions.