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.
Related
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!
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 have a problem trying to connect to a database with a .db extension.
The problem is that the .db file has spaces in the name and it is something that I can not change, a file without spaces in the name works correctly.
Is there any way to connect?
The name of the file is File Access Monitor.DB
enter image description here
Make sure to put the full name of the file in spaces:
> sqlite3
sqlite> .open "File Access Monitor.DB"
Or if you're starting directly from the command line:
sqlite3 "File Access Monitor.DB"
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.
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).