0

I have some sqlite scripts with some sqlite commands like:

  • .headers ON
  • .mode CSV etc.

Is there anyway of running this script in SqliteDB using Sqlite interface for C++, instead of redirecting the file to sqlite using sqlite command line shell?

Thanks

2
  • Do you want the result to be the same as running through the shell, or do you want to run them using the API to handle output somehow? Commented May 14, 2013 at 6:32
  • I need to write the output to a csv file. Commented May 14, 2013 at 6:58

1 Answer 1

1

If you actually need the output, than it's by far easiest to just run the script through the command-line shell (it has -batch argument to suppress all output except the actual results).

The .-commands are implemented in the shell, not the API. Because the API does not do output and the commands you mention are for controlling the output. If you really wanted to run the scripts with the API, you'd need to do the output yourself and either hardcode the format you want or interpret the .-commands yourself.

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

2 Comments

Thanks for your answer and if so, how to input the script file using the API?
@DuliniAtapattu: You cannot input the script using the API. If you really want to do it with API (you don't have to, the command-line shell is much easier) you have to read it, split it to commands, create statement (sqlite3_stmt) for each and step it through. Or, better, embed the commands in the code.

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.