2

I'm trying to save clipboard content into an sqlite database. Created database and tables.

I don't want it to create journal file in every clipboard change, so I tried to pass PRAGMA journal_mode = OFF; flag. But it's tricky to pass those commands in a one liner commands because sqlite only accepts two command like

sqlite3 clipboard_archive.db "insert into cb (cb_context) values ('clipboard');"

it works. I looked for Q&A sites, some advises echoing the commands in the following way.

echo "PRAGMA journal_mode = OFF;" | sqlite3 clipboard_archive.db "insert into cb (cb_context) values ('clipboard');"

But PRAGMA journal_mode = OFF; doesn't take effect in that way though it works within the sqlite3 command prompt.

What's wrong with my one liner script?

  • 3
    You should either put all of the commands in through echo or all of them as an argument to sqlite3. – chicks Oct 13 '17 at 2:29
  • @chicks "I believe I tried that but it didn't work in my attempt." you know it's a noob phenomenon. If you posted it as an answer, I'd have another option. – kenn Oct 13 '17 at 11:20
5

Not sure why you want to use SQLite if you don't want the journal (have you considered the much faster WAL mode if speed is a concern?) but you can give multiple commands separated by semicolons:

sqlite3 clipboard_archive.db "PRAGMA journal_mode = OFF; insert into cb (cb_context) values ('clipboard');"
  • I just had time to test it, it works, thanks. I am just a beginner in data storing. Thank you for the suggestion, I was not aware of WAL mode. I ll take a look at it. My concern was not speed, I didn't want hard disk to wear down. – kenn Oct 13 '17 at 11:13
2

derobert's answer doesn't seem to work with dot-commands, but you can use -cmd: sqlite3 tolls.sql3 -cmd ".mode csv" ".import tolls.csv tolls"

it accepts multiple -csv commands and executes them in order, before the final arg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.