0

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

1 Answer 1

1

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...)

Sign up to request clarification or add additional context in comments.

1 Comment

is there a way to do that in python?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.