Error when use json_extract() on sqliteodbc - sqlite

I use sqliteodbc from http://www.ch-werner.de/sqliteodbc/
and this code in ms word
str_cnxn = "Driver={SQLite3 ODBC Driver};Database=" & db_path
Dim Cnxn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Cnxn.Open str_cnxn
rst.Open "Select *,json_extract(pdf_links, '$.root') as root from book where book_id=10", Cnxn, adOpenForwardOnly, adLockReadOnly
Debug.Print rst!book_name, rst!Root
rst.Close
I got this error
no such function:json_extract
Same SQL statement on same DB run successfully on SQLite Db Browser https://sqlitebrowser.org/

Do you understand that when you use SQLiteODBC and SQLite Db Browser you are using two completely different versions of SQLite?
The latest available SQLiteODBC version is grossly outdated. If you want to use JSON functions via SQLiteODBC, you need to compile it yourself. I have recently built a Windows version of SQLiteODBC from source. The installer is available from GitHub repo. You would need to uninstall the currently installed driver and install a new one (either the copy you compile yourself or my copy). Note, if you build the driver yourself, there is no guarantee it will work until you do it right. The build scripts included with the source are broken, and additional modifications needs to be done to include a recent copy of SQLite. My copy includes SQLite 3.39 and it has JSON functionality working properly.

Related

An up-to-date SQLite ODBC driver

Since one of my SQLite db file has been managed by the latest SQLite version (3.39.2), I am no longer able to access the tables through the ODBC driver. There is no error when connecting to the database, but the list of tables remains empty.
I have a suspicion that this is because it is seriously behind, since it's built on version 3.32.3.
Is there any other more recent ODBC driver for SQLite available out there?
I have played with the SQLiteODBC driver last year (I used it with Excel 2002 and 2016) and patched the official scripts to enable builds that include current SQLite release. The details are here.
I have just recompiled both x32 and x64 SQLiteODBC installers for Windows and uploaded them to my repo. You can install those or, if you wish, follow my docs and build the driver yourself (you would still need to use several patched scripts included in my repo).
Besides including the current SQLite release, I also enabled most of the extra extensions, which are not included in the official ODBC builds.

SQLiteStudio using upsert

I am using Sqlite 3.32.3. I imported data into a table (rover) with SQLiteStudio 3.2.1. I want to use UPSERT to update existing rows and insert new rows. As a test, I'm using the statement below to update a single existing row. It does not work in the SQLiteStudio sql editor but it does work in the native SQLite3 terminal interface. I'm using OSX 10.14.6. Is this a limitation of SQLiteStudio or am I missing something?
INSERT INTO rover ([Employee Number], DeleteDate)
VALUES ('97763','2020-06-24')
ON CONFLICT ([Employee Number])
DO UPDATE SET DeleteDate = excluded.DeleteDate;
The .version command you used was in terminal infertace and it is version used by terminal binary. SQLiteStudio in version 3.2.1 uses SQLite 3.22.0 on MacOS X, unfortunately (See menu SQLiteStudio -> About -> Environment tab).
That being said, fortunately, you can replace SQLite library file used by SQLtieStudio. Just take libsqlite3.0.dylib from your system (or if you maybe compiled your own) and replace the existin one in SQLiteStudio.app/Contents/Frameworks/. It's important that the new library has Loadable Extensions compile-time option enabled, cause SQLiteSTudio uses it.
SQLiteStudio 3.2.2 (to be released) will have up to date SQLite.

SQLITE file is encrypted or is not a database

I have a huge problem... I am developing desktop app with SQLite but during copy/paste process I lost a power and process was terminated so base was lost. However, I found a way to recover it but base is encrypted. When I try to open connection using conn.Open(); I get this error. If I try to open it with DB Browser for SQLite it asks me a SQLCipher encryption password so it seams to me that data is lost..
Is there any default password ?
Why did this happen and how to prevent it from happening again ?
What can I do ?
Thanks in advance.
Also check that SQLite version you're "connecting" with aligns with the DB file version.
For example, here's a DB file written by SQLite version 3+:
$ file foobar.db
foobar.db: SQLite 3.x database, last written using SQLite version 3027002
And here I also have 2 versions of sqlite:
$ sqlite -version
2.8.17
$ sqlite3 -version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0alt1
Obviously in hindsight, opening foobar.db with sqlite version 2 will fail, yielding the same error message:
$ sqlite foobar.db
Unable to open database "foobar.db": file is encrypted or is not a database
But all is good with the correct version:
$ sqlite3 foobar.db
SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
sqlite>
sqlite> .databases
main: /tmp/foobar.db
sqlite>
The error message is a catch-all, simply meaning that the file format was not recognized.
Ok, finally found a solution that works so posting the answer if anybody will have same trouble as I did..
First of all, use good recover software. For repairing the database I found 3 solutions that work without backup :
Open corrupted database using DB Browser an Export Database to SQL. Name it however you want. Then, create new database and import database from SQL.
There is software that repairs corrupted databases. Download one and use it to repair the database.
Download "sqlite3" from sqlite.org and in command line navigate to folder where "sqlite3" is unzipped. Then try to dump the entire database with .dump, and use those commands to create a new database:
sqlite3 corrupt_table_name.sqlite ".dump" | sqlite3 new.sqlite
I had the same error when I was trying to access a db dump in another system compared to compared to where it was obtained. When I tried to open on a dev machine, it threw the reported error in this thread:
$ sqlite3 db_dump.sqlite .tables
Error: file is encrypted or is not a database
This turned out to be due to the differences in the sqlite version between those systems. This dev system version was 3.6.20.
The version on the production system was 3.8.9. Once I had the sqlite3 upgraded to same version, I was able to access all its data. I am just showing below the tables are displayed as expected:
# sqlite3 -version
3.8.9
# sqlite3 db_dump.sqlite .tables
capture diskio transport
consumer filters processes
This error is rather misleading to begin with, though.
If you've interacted with the database at some point while specifying journal_mode = WAL, and then later try to use the database from a client that does not support WAL (< v3.7.0), this error can also come up.
As noted in the SQLite documentation under Backwards Compatibility, to resolve that without having to recreate the database, explicitly set the journal mode to DELETE:
PRAGMA journal_mode=DELETE;
Your database did not become encrypted (this is only one of the two options in the error message).
Your data recovery tool did not recover the correct data; what you have in the file is something else.
You have to restore the database file from the backup.
The issue is with sqlcipher version upgrade in my case, Whenever I update my pod it automatically upgrade the sqlcipher and the error occurred.
For a quick fix just manually add the SDK instead of Pod install. And for a proper solution use this link GitHub Solution

Unable to create query COPY PostgreSQL PQSQL driver

Well the thing is that when the program execute the query to copy a table to a file .CSV. Qt show me the next error.
"ERROR: syntax error at end of input
LINE 1: EXECUTE
Here are the code of the export action:
QSqlQuery qry;
qry.prepare("copy inventory to './inventory.csv'");
if(qry.exec()){
qDebug()<<"Succes";
}else{
qDebug()<<qry.lastError().text();
}
The version of qt is 5.4, used postgresql 9.3 and driver PQSQL working fine just can execute another's query very well like select.
Thanks.
You mentioned that you're using Qt's SQL interface and its PostgreSQL driver.
While Qt's PostgreSQL driver is built on top of PostgreSQL's standard client library libpq, as far as I can tell it does not offer support for lots of the functionality of libpq. In particular, there appears to be no way to access support for the COPY protocol, nor for LISTENing for asynchronous notifications.
You will have to:
libpq directly to COPY ... FROM STDIN
or use regular INSERT statements via Qt; or
Transfer the CSV input to the server, then use COPY ... FROM '/path/on/server' to read the input from a file on the server that the PostgreSQL database is running on, readable by the user the PostgreSQL database runs as.
(You could also submit a patch to Qt to add support for the COPY protocol, which shouldn't be too hard to implement, but is perhaps not the best choice if you're asking this.)
Using COPY needs superuser rights . Do not confuse with \COPY of
PostgreSQL
COPY TO requires absolute path to the output file. If 1st point is
considered, try removing the ./ in your output file name
You can refer to related posts:
post1
and
post2

how to upgrade the sqlite database without lost data?

I have an application in C# that uses System.Data.SQLite. In my case I use a recent version of SQL Lite database, by now I can see that the new versiĆ³n has released, and int sqlite.org webpage says that is recommended to upgrade the database.
My question is how to upgrade without lost the information in my actual database.
How can I chech the version of the data
Thanks.
EDIT: what I mean is when I create a new database with the sqlite3 library, I guess that the database file, my database.db has a version. When I update the sqlite3 library, I am update the sqlite3 command line, but the database file still has the version that had when I created it.
So if in the new versions for example add new features to the database, for example triggers, foreign keys and so on, if I am not wrong, this features must be in the database file, not in the sqlite3 library, because when I access to the database for example with entity framework, I don't use sqlite3 library, I use System.SQLite.Data library.
am I wrong? the datafile is never update and only the library can be updated?
Thanks.
Upgrading the SQLite library will not have any effect on your database file.
Changes like foreign keys do not affect the database file.
The last change that affected the file format was a long time ago.

Resources