No such function: sqlcipher_export() - sqlite

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!

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 Brew Install SQLite3 FTS5 extension?

Is there an easy way to enable the FTS5 extension for SQLite3 installed with Brew? Some older posts say there should be an install option --with-fts5, however:
$ brew reinstall sqlite3 --with-fts5
...
Error: invalid option: --with-fts5
The fts3_tokenizer is not enabled. I assume there must be an easy way to install/enabled the extension with Brew without compiling from source outside of Brew.
$ sqlite3
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .dbconfig
defensive off
dqs_ddl on
dqs_dml on
enable_fkey off
enable_qpsg off
enable_trigger on
enable_view on
fts3_tokenizer off
legacy_alter_table off
legacy_file_format off
load_extension on
no_ckpt_on_close off
reset_database off
trigger_eqp off
trusted_schema on
writable_schema off
$ brew info sqlite3
sqlite: stable 3.35.5 (bottled) [keg-only]
Command-line interface for SQLite
https://sqlite.org/
/usr/local/Cellar/sqlite/3.35.5 (11 files, 4.2MB)
Built from source on 2021-05-18 at 08:54:33
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/sqlite.rb
...
Try to use CFLAGS environment:
CFLAGS="-DSQLITE_ENABLE_FTS5" brew reinstall sqlite
Edited:
Rebuild to enable fts5 is unnecessary. The sqlite 3.35.5 package is already fts5 module enabled.
$ brew fetch sqlite
...
$ tar xzf ~/Library/Caches/Homebrew/downloads/61d40ad2021e894bcf4c7475eea2dbbfee14c4426b1bbb1816c4055ad1c70b50--sqlite--3.35.5.catalina.bottle.tar.gz -O sqlite/3.35.5/lib/libsqlite3.0.dylib \
| strings - | grep '^fts5: 20\|trigram'
trigram
fts5: 2021-04-19 18:32:05 1b256d97b553a9611efca188a3d995a2fff712759044ba480f9a0c9e98fae886
I wrote you on the trac mailing list too but will post here too.
If you check https://sqlite.org/fts5.html there seems to be a option --enable-fts5 but it also seems disabled by the fault. That said they point to a " amalgamation" (there is a link to it in the page) where you can use this option if you compile the " amalgamation".
Markus
FTS5 is enabled. I was mistaken about the source of the problem I'm experiencing.
>>> import sqlite3
>>> import pprint
>>> db = sqlite3.connect(':memory:')
>>> cursor = db.execute('PRAGMA COMPILE_OPTIONS')
>>> pprint.pprint(cursor.fetchall())
[(u'BUG_COMPATIBLE_20160819',),
(u'COMPILER=clang-12.0.5',),
(u'DEFAULT_CACHE_SIZE=2000',),
(u'DEFAULT_CKPTFULLFSYNC',),
(u'DEFAULT_JOURNAL_SIZE_LIMIT=32768',),
(u'DEFAULT_PAGE_SIZE=4096',),
(u'DEFAULT_SYNCHRONOUS=2',),
(u'DEFAULT_WAL_SYNCHRONOUS=1',),
(u'ENABLE_API_ARMOR',),
(u'ENABLE_COLUMN_METADATA',),
(u'ENABLE_DBSTAT_VTAB',),
(u'ENABLE_FTS3',),
(u'ENABLE_FTS3_PARENTHESIS',),
(u'ENABLE_FTS3_TOKENIZER',),
(u'ENABLE_FTS4',),
(u'ENABLE_FTS5',),
(u'ENABLE_JSON1',),
(u'ENABLE_LOCKING_STYLE=1',),
(u'ENABLE_PREUPDATE_HOOK',),
(u'ENABLE_RTREE',),
(u'ENABLE_SESSION',),
(u'ENABLE_SNAPSHOT',),
(u'ENABLE_SQLLOG',),
(u'ENABLE_STMT_SCANSTATUS',),
(u'ENABLE_UNKNOWN_SQL_FUNCTION',),
(u'ENABLE_UPDATE_DELETE_LIMIT',),
(u'HAS_CODEC_RESTRICTED',),
(u'HAVE_ISNAN',),
(u'MAX_LENGTH=2147483645',),
(u'MAX_MMAP_SIZE=1073741824',),
(u'MAX_VARIABLE_NUMBER=500000',),
(u'OMIT_AUTORESET',),
(u'OMIT_LOAD_EXTENSION',),
(u'STMTJRNL_SPILL=131072',),
(u'THREADSAFE=2',),
(u'USE_URI',)]

Local Perl DBI module, Can't locate object method "connect"

I've installed DBI module via cpan. CPAN has been configured to use local directory, so I have ~/perl5 and ~/.cpan directories. The module apparently is in ~/.cpan/build/DBI-1.642-0, which in fact does have DBI.pm file there.
However, when I execute the following command as a test, the command suggests there is no "connect" object:
$ perl -e 'use lib qw( .cpan/build/DBI-1.642-0/ ); DBI->connect("dbi:SQLite:dbname=foo.sqlite","","");'
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at -e line 1.
Environment: Debian-based distribution, perl 5.26.2 .
Note on possible duplicates:
Can't locate object method via package subclassing DBI Asks about module subclassing, not what I'm doing
Addendum: From the discussion in the comments, it's clear that a lot of users focus on just use DBI statement. As I've mentioned in the comments:
The whole goal is to make use of DBI module installed via cpan. Prior to installing DBD::SQLite neither use lib nor use DBI were giving a working solution. So the suggestion use DBI by itself was not useful.
Please note, I have tried both use DBI and use lib qw() methods prior to asking the question. The use DBI line by itself was not effective without installing DBD::SQLite module as mentioned in my answer.
Converted from a command line script to an actual program, your code looks like this:
use lib qw( .cpan/build/DBI-1.642-0/ );
DBI->connect("dbi:SQLite:dbname=foo.sqlite","","");
And the error message you get is:
Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI"?) at -e line 1.
That error is pretty clear.
(perhaps you forgot to load "DBI"?)
The problem here is that you are missing the line of code which actually loads the DBI module. You need to add this:
use DBI;
Your use lib qw( .cpan/build/DBI-1.642-0/ ) line is very strange. You're asking Perl to load the module from the temporary build directory that was used during the installation. That's not the version that you want to use at all. When cpan has finished its work, you will have a version of DBI installed in your standard Perl library directories that you will be able to access without the need for any use lib code.
I'll also add that if you're using the system-installed version of Perl, there's no need to use cpan to install the most popular modules. You can use your distribution's repository of pre-built packages. For example apt get install libdbi-perl (on Debian and similar) or dnf install perl-DBI (on Red Hat).
In your answer, you have silently added the missing use DBI statement and you claim that installing DBD::SQLite solved your problem. That may have solved a different problem that you had, but it didn't solve the problem in your original question.
Issue with perl -e has been resolved, since apparently SQLite was not installed. I had to open cpan shell and run install DBD::SQLite. Now, the command-line works properly:
$ $ perl -e 'use DBI; my $db = DBI->connect( "dbi:SQLite:dbname=foo.sqlite","","" );my $stmt = qq(CREATE TABLE foo(a int, b text); ); $db->do($stmt)'
$ sqlite3 foo.sqlite
SQLite version 3.23.1 2018-04-10 17:39:29
Enter ".help" for usage hints.
sqlite> .tables
foo
sqlite> .schema foo
CREATE TABLE foo(a int, b text);
sqlite>
As for the module itself, it has been installed in ~/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DBD/ directory.
Based on Berserk's answer, the following also works for explicitly calling the :
$ perl -e 'use lib qw( /home/user/perl5/x86_64-linux-gnu-thread-multi/DBD ); use DBI; my $db = DBI->connect( "dbi:SQLite:dbname=foo.sqlite","","" );my $stmt = qq(CREATE TABLE foo(a int, b text); ); $db->do($stmt)'
To ensure this uses the library declaration from use lib qw() explicitly, I've also cleared the #inc array in some of my tests.

To Capture the Error in Sybase IQ SQL Execution using dbisqlc inside ksh shell Script

I have a shell script as below through which I'm connecting Sybase IQ through dbisqlc.
I would like to capture if there Error is any Error occurs during the Script Execution. I coded like below. But eventhough if there is any failure in SQL Execution , the Return Count in always 0.
dbisqlc -c "uid=UID;pwd=PWD;eng=DEV;links=tcpip(host=XXXX;port=XXX)" -q Query.sql OutputDumpFile
RC=`echo $?`
if [ $RC != 0 ]
then
echo "ERROR: Error in DB Query Execution"
fi
Please help how to capture the SQL Error in UNIX for Sybase IQ
According to this documentation, dbisql is recommended over dbisqlc:
It is recommended that you use the Interactive SQL utility (accessed
by using the dbisql command or by choosing Start » Programs » SQL
Anywhere 11 » Interactive SQL) where possible because the dbisqlc
utility does not support all the features that Interactive SQL does
It goes on to say:
Only the dbisql utility has the ability to provide exit codes from a
SQL script.
So based on that, it seems to me that dbisqlc does not convey information via exit codes.

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.

Resources