This may sound odd but I have 15 databases within different folders and I wish to update them all.
I have made a text file for me to easily copy the sql file that I need to import in to each root folder and load the DB, so I can just copy and paste each to CLI and then I can then type the following in to each one.
sqlite> .read backup.sql
and it imports the data I need it too...I then exit (CTRL + Z) and run the next one...
However, can I easily run something like
sqlite3 database.db > .read backup.sql
So I can effectively run the whole thing from one command line?
Related
So I have a series of thousands of .zip files that need to be opened.
They are password protected, but I have the passwords.
Trying to automate the opening of these. the deflate64 issue is causing a lot of pain.
Okay, So deflate64 is proprietary which is annoying as that stops you from using the normal zipfile library in python. As a workaround i typically make a subprocess call to 7zip or similar. So something like:
import subprocess, sys
subprocess.Popen(["7z", "e", f"{filename}", f"-o{destination}", "-y" "-p" password])
Then naturally just run that in a loop over your files. Depending on how they are laid out you might want to just glob everything in a directory or pipe them via stdin etc.
Often tasks like this are well suited to shell scripts so you might want to consider that, I'm not a windows user but i think something like the following script would work as well:
#echo off
set pass=[password]
set folder=[folder]
for /R "%folder%" %%I in ("*.zip") do (
"C:\somedirectory\7z.exe" x -p%pass% -y -o"%%~dpI" "%%~fI"
)
I am using this to extract data from sqlite database file, commands.txt are where I put my sqlite query:
sqlite3 base1.db < commands.txt > "base1.csv"
This works OK for one file, now I need to apply that commands to multiple .db files at once. This .db files are stored inside subfolders (they all have the same structure, so that sqlite command work OK for all)
I need to collect data from all .db files based on sqlite query in commands.txt into one .csv file, if possible?
When I execute this, I dont get result but empty file.
cd /D "C:\sqlite-tools-win32-x86"
for /R %%G in (*.db) do (
sqlite3 < commands.txt > "%%~dpnG.csv"
)
I understand I can save my queries etc in an .sql file and run it against a database from the cmd prompt like this:
$ sqlite3 main.db < queries.sql > results.txt
but how can I write my .sql file to print comments or the actual statements themselves so that the results file is self explanatory when viewed?
I have a file located at the following location on my computer:
D:\Pictures\Imported Catalogue\Ojulari-2
I want to be able to extract the data from the (corrupt file) database file into a text file with all the SQL commands needed to recreate the database.
I'm following instructions from the following link, but I seem to be stuck executing the right command line or should I say navigation the the location of the corrupt file using the command line provided (See below)
Link to instructions I am following: http://gerhardstrasse.wordpress.com/2010/08/19/recover-from-a-corrupt-adobe-lightroom-catalog-file/
Command line I am trying to execute:
echo .dump | ./sqlite3 ~/lightroom_catalog.lrcat > ~/lightroom_catalog.sql
Download the sqlite3 command-line shell, and put the .exe file in the same directory as the database.
Open a Windows command-line shell, and go to that directory:
D:
cd "\Pictures\Imported Catalogue\Ojulari-2"
Execute:
sqlite3 MyDatabaseFile .dump > MyDatabase.sql
Trying to convert an SqlCe database to SQLite, I export it to a .sql file. Now how would I use sqlite.exe to create a database from this .sql file?
Where to put the sql3.exe file?
What command syntax to use, in cmd prompt or in the sqlite.exe shell?
Use following command line:
sqlite3 -init dump.sql newsqlite.db ""
It will create new SQLite database file newsqlite.db by executing statements from dump.sql. Empty string "" is needed for sqlite3 to quit automatically.
If newsqlite.db file already existed with some data, import may fail unless you use IF NOT EXISTS for all table and index creation statements.
Put sqlite3.exe wherever you want, as long as you remember that place and you're able to start sqlite3 from there.
Applying a script to a database (maybe a newly-created one), in command prompt:
sqlite3.exe my-new-db.somesuffix < myscript.sql
Executing a script within interactive sqlite3 session:
sqlite3.exe my-new-db.somesuffix
....
.read myscript.sql
....
Both variants are valid and usable at times. (Note: if your .sql was generated for non-sqlite database, I'd expect that it will require some changes to work in sqlite3. And things like stored procedures and user-defined functions will be definitely lost).