sqlite file creation - sqlite

I know this is the stupid question but i am so confused so please help me.
The question is when i use sqlite command line and make a database.
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 mydata.db
---> (now i terminate it using ;)
And now i craete tables and use .output filename and then select * from tb(table)
The file craeted nowhere!!
So please let me know where file craeted.
Or any other method to craete sqlite database file.
Thanks in advance.

What's wrong with this? It perfectly works and both mydatabase.db and foo_contents.txt exist.
C:\Users\··\Desktop>sqlite mydatabase.db
SQLite version 3.7.6.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo(bar text);
sqlite> begin transaction; insert into foo(bar) select 'a' union all select 'b';
sqlite> end transaction;
sqlite> .output '.\foo_contents.txt'
sqlite> select * from foo;
sqlite> .output stdout
sqlite> .q
C:\Users\··\Desktop>

Not sure about your trouble...
fpuga#ELNATH:/tmp$ sqlite3 database.sqlite
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /tmp/database.sqlite
sqlite> .exit
fpuga#ELNATH:/tmp$ ls *.sqlite
database.sqlite

Related

How to use Command Line to access an encrypted SQLite db file instead of DB Browser interface

Currently I can use DB Browser for SQLite to open an encrypted DB file with password on Mac.
The options as per image:
Raw key (start with 0x...)
SQLCipher 3 defaults
I would like to open this file using command line instead of DB Browser.
Tried follow commands but seems no luck so far.
sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> pragma key="0xMyKey";
ok
sqlite> .tables
Error: file is not a database
Appreciate the help in advance so that I can use command line to access or export sqlite db just like mysql (mysql -u ... & mysqldump).
Found the documentation via this link: https://www.zetetic.net/sqlcipher/sqlcipher-api/
sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> PRAGMA key = "x'{KEY_WITHOUT_0X}'"; // Replace {KEY_WITHOUT_0X} with your key without 0x!
ok
sqlite> PRAGMA cipher_page_size = 1024;
sqlite> PRAGMA kdf_iter = 64000;
sqlite> PRAGMA cipher_hmac_algorithm = HMAC_SHA1;
sqlite> PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;
sqlite> PRAGMA cipher_default_plaintext_header_size = 0;
sqlite>

why `.databases` attempts to write in sqlite3?

I am new to sqlite. I want to inspect existing read only database like below.
$ ll /nix/var/nix/db/db.sqlite
-rw-r--r-- 1 root root 30445568 Jan 9 15:41 /nix/var/nix/db/db.sqlite
$ sqlite3 /nix/var/nix/db/db.sqlite
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
sqlite> .databases
Error: attempt to write a readonly database
I don't get it. Do I need write access to simply query sqlite database? I need a few poiters here
I read in https://sqlite.org/wal.html about immutable query parameter. If I replace path with URI with that query parameter, then I can inspect the read-only database.
sqlite3 file:///nix/var/nix/db/db.sqlite?immutable=1
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
sqlite> .databases
main: /nix/var/nix/db/db.sqlite r/o
sqlite> .tables
DerivationOutputs Refs ValidPaths

sqlite not creating table in command line

I am new to SQLite and I have been trying to create a table in a database by importing a .csv file.
I type in the following commands:
sqlite>.mode csv
sqlite> .import testdata.csv testtable
No table is created and it returns the following line:
Usage: .import FILE TABLE
My machine is running Windows 10 and I have SQLite version 3.21
Quote the file name:
sqlite> .import "testdata.csv" testtable

Is there a way to find who is the user currently logged in the OS in sqlite3?

For example in DB2 there is a "user" that will give you who is logged in and performing the queries. And no, there is no "logging into DB2" I only login once to gain access to the whole OS (IBM i 7.1).
declare global temporary table XYZ ( DUMMY char(1))
Table XYZ created in QTEMP.
insert into XYZ values('1')
1 rows inserted in XYZ in QTEMP.
select user from XYZ
Output:
....+....1....+...
USER
"my-login-user-id-is-shown-here"
******** End of data ********
in sqlite3:
SQLite version 3.11.1 2016-03-03 16:17:53
Enter ".help" for usage hints.
sqlite> create temporary table XYZ (DUMMY char(1));
sqlite> insert into XYZ values('1')
...> ;
sqlite> select user from XYZ;
Error: no such column: user
sqlite>
Thanks in advance!
SQLite is a file-based database; it neither cares nor knows about OS users.
I tried this (running sqlite from the unix shell) and found it to be an acceptable solution, but I will like to be able to do the same from within the sqlite command shell.
% sqlite3 test.db "select * from NADA where UZER='$USER';"
-- Loading resources from /home/<my-userid>/.sqliterc
UZER DINERO
---------- ----------
<my-userid> 117.41

Encrypting sqlite database with SQLiteCrypt

I am rally struggling with finding solution to protect sqlite database with password. I am trying with SQLiteCrypt. I followed insttruction from a link! , but when i type;
sqlite3_open_v2("data.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
i am getting: Error: near "sqlite3_open_v2": syntax error.
Can someone help?
D:\>sqlite.exe data.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA lic = '77523-009-0000007-72328';
sqlite> PRAGMA rekey = 'ac23';
sqlite> .exit
You MUST exit first to see the effect!
D:\>sqlite.exe data.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from _MapPropertyA;
Error: file is encrypted or is not a database
DONE, your database file encrypted

Resources