SQLite error for creating database - sqlite

SQLite version 3.8.0.2 2013-09-03 17:11:13
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> $sqlite3 DatabaseName.db;
Error: near "$sqlite3": syntax error
sqlite> DatabaseName.db;
Error: near "DatabaseName": syntax error
sqlite> sqlite3 DatabaseName.db;
Error: near "sqlite3": syntax error
sqlite>
I am trying to create a database in SQLite. I am getting the error as above. Please help

sqlite3 DatabaseName.db is what you'd use at the command line, not once you've already started the shell. Running that at command line will open it in the shell with the empty database already open.
When your prompt is sqlite>, you're already in the shell.
Here are some docs: http://sqlite.org/sqlite.html

Related

How can I quit sqlite from a command batch file?

I am trying to create a sealed command for my build pipeline which inserts data and quits.
So far I have created my data files
things-to-import-001.sql and 002 etc, which contains all the INSERT statements I'd like to run, with a file per table.
I have created a command file to run them
-- import-all.sql
.read ./things-to-import-001.sql
.read ./things-to-import-002.sql
.quit
However when I run my command
sqlite3 -init ./import-all.sql ./database.sqlite
..the data is inserted, but the program remains running and shows the sqlite> prompt, despite the .quit command. I have also tried using .exit 0.
From the sqlite3 --help
-init FILENAME read/process named file
Docs: https://www.sqlite.org/cli.html#reading_sql_from_a_file
How can I tell sqlite to exit once my inserts have finished?
I have managed to find a dirty workaround for this issue.
I have updated my import file to include a bad command, and executed using -bail to quit on first error.
-- import-all.sql
.read ./things-to-import-001.sql
.read ./things-to-import-002.sql
.fakeErrorToQuitWithBail
Then you can execute with
sqlite3 -init import-all.sql -bail
and it should quit with
Error: unknown command or invalid arguments: "fakeErrorToQuitWithBail". Enter ".help" for help
Try using ".exit" at the place of ".quit". For some reason SQLite dont doccumented this commands.
https://www.tutorialspoint.com/sqlite/sqlite_commands.htm

How to load Northwind into SQLite3 -- Error 'File is not a database'

I am trying to load the Northwind.Sqlite3.create.sql hosted on https://github.com/jpwhite3/northwind-SQLite3 into SQLite3 on Ubuntu.
I have tried using: sqlite3 Northwind.Sqlite3.create.sql to import the database.
However when I try to view the data using SELECT * FROM CUSTOMERS; I get an error saying Error: file is not a database
Any suggestions as to how to open the database file and use it?
That's just a text file full of DDL statements, not a sqlite3 database. You'd have to import it into a database with something like
sqlite3 mydatabase.db < Northwind.Sqlite3.create.sql

Why am I getting: database is locked, in an SQLite3 script?

I'm getting an error when running an SQLite script.
--drop use table before replacing it
DROP TABLE IF EXISTS db.use;
--Create the use table in the saved database
CREATE TABLE db.use AS SELECT * FROM use2; -- this is the line that generates the error: Error: near line 145: database is locked
Are these two statements run asynchronously or something? I don't understand what's causing the error, but I'm wondering if it has to do with that.
Might there be a way to run the script in a lock-step manner, i.e. non-asynchronously?
This is how I was running the command: sqlite3 --init script_name.sql dbname.db, and elsewhere in the script I had an ATTACH statement reading the same database dbname.db. Essentially reading the same file twice.
The way I solved this was by executing the script in the sqlite3 shell:
sqlite3> .read script_name.sql
Have you tried to add a commit statement after the drop statement?
I think that would make sure the create table statement run after the drop statement is totally done.

No such function: sqlcipher_export()

i using start terminal
-macbook:sqlTest user1$ sqlite3 sqlTest.sqlite
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.sqlite' AS encrypted KEY 'testkey';
sqlite> SELECT sqlcipher_export('encrypted');
Error: no such function: sqlcipher_export
sqlite>
what makes no such function: sqlcipher_export?
As answered on the mailing list:
The first step is to build the sqlcipher command line tool, as described here:
http://sqlcipher.net/introduction/
Once you have done this, you should run the command like this:
$ ./sqlcipher sqlTest.sqlite
or
$ /full/path/to/sqlcipher/sqlcipher sqlTest.sqlite
On unix systems, if you don't provide an explicit path for a command, the system will look for the program in $PATH. On OSX, the system ships with a sqlite3 command, so you've probably been using that instead of the version compiled with SQLCipher. Please let us know if that resolves the problem. Thanks!

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