sqlite3 current directory's tables can't be found - sqlite

I'm following a tutorial on SQlite but stumped at the first step. It's like this:
XXXX:~ YYYY$ cd Desktop/
XXXX:Desktop YYYY$ sqlite3 -init bootstrap.sql
SQLite version ...
Enter ".help" for usage hints.
sqlite> .tables
sqlite>
There should be a "Loading resources from boostrap.sql" according to the tutorial. I can't find any tables and the the file is still intact.

If sqlite3 does not output the "Loading resources from …" message, then the bootstrap.sql file was not found. This is probably because that file is not in the current directory.

Related

SQLite - Importing .csv data to database every day

So I need to import some .csv file every day in our firm. My idea was to write a .bat file and run it everyday automatically through Task Scheduler. The problem is that i can't succeed at writting .bat file correctly. It's working when I type physically in CMD (sqlite3) but don't do anything when I transform it to .bat file and run it.
CMD:
C:\WINDOWS\system32>sqlite3.exe
SQLite version 3.34.0 2020-12-01 16:14:00
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> ATTACH DATABASE "C:\...\database.db" AS "name";
sqlite> .mode csv
sqlite> .separator ;
sqlite> .headers on
sqlite> .import "\\\\path\\..." "dbname"
sqlite> SELECT * from "dbname"
The result is the way I want, so all the data is in the database correctly.
Do anyone has an idea how to transform this to a .bat file?
Create a text file for the sqlite script
The batch file will be something like sqlite3 ":memory:" ".read sqlite.script"
Et voilà! The first argument to sqlite3 is the database name, the following arguments are CLI "executables".
We found a solution that works! I created a .bat file with the next code:
#ECHO off
sqlite3.exe -cmd ".mode csv" -cmd ".separator ";"" -cmd ".import C:\\the path to the .csv file\\ myTable" C:\the path to the database
pause
and it works with the task scheduler.
Thanks everyone!

SQLite3 one-line command for exporting table to the .sql file

In my rails application, I need to export an existing table as .sql file with one-line command ideally
Does anyone have an idea how to do it?
This dumps hole database
db_file = 'db/development.sqlite3'
sh("sqlite3 #{db_file} saraksts > from_file/test.sql")
sqlite3 database.db ".dump table_name"
should do it.

Sqlite3: Location of the data base file in the file system

I am starting to get familiar with the sqlite. I am currently using SQLite version 3.13.0 2016-05-18.
I created a test data base called "test.db" as follows:
sqlite3 test.db
And then, I created a table called "employees" in the database as follow:
create table employees(id integer primary key, name text);
Then after I added the following entry to the table:
insert into employees(id, name) values(410,'test');
Everything works as expected. But, somehow I can not find where my test database file is located in the file system. Any idea where that .db file is located? I am in windows system.
I just realized that I had to save the .db file as follows:
.save test.db
And, then the .db file appeared in the same directory as SQLite database file is also a regular file.

Need help extracting data from a corrupt file

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

How to use sqlite3.exe to create database from exported .sql script

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

Resources