zzzbbx
zzzbbx

Reputation: 10141

Error with .output in sqlite3

I'm getting the following error

conn = sqlite3.connect('./mydb.db')
c = conn.cursor()
c.execute('.output ./mytable.sql')
conn.close()

c.execute('.output ./mytable.sql') sqlite3.OperationalError: near ".": syntax error

Upvotes: 0

Views: 464

Answers (1)

fleed
fleed

Reputation: 680

That's because .output is a command for the command line sqlite tool. It is not a valid SQL command. Hence it cannot be used when you are using sqlite through a library, only interactively through the command prompt.

None of the shell commands listed at https://www.sqlite.org/cli.html can work as they are something totally separate from the sqlite itself. You can think of them as if they were part of a GUI program - it would not make sense to be able to access something in a GUI program through the library.

What you have to do is fetch the data yourself and parse it yourself and output in the way you want. Another option is to call the sqlite shell and pass the commands you want it to execute. Something like:

sqlite3 < '.output FILE \n SELECT * FROM TABLE'

(this is untested...)

Upvotes: 1

Related Questions