SQLiteStudio using upsert - sqlite

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.

Related

Get previous input on sqlite CLI tool

I'd like to access my previous inputs on the sqlite CLI tool. In bash it works with the arrow up-key but in after running sqlite3 and pressing that key I'm just getting ^[[A. How can I fix this? Which key lets me use my previous typed commands?
Thank you in advance.
Your sqlite3 binary was not built with support for readline.
Either get one that does. Or you can wrap it with readline via rlwrap.
rlwrap sqlite3

Getting COLLATE LOCALIZED/UNICODE on non-Android SQLite

I wanted to use SQLiteAssetHelper to create the SQLite database on my computer to use in an Android application. Unfortunately, I need an index using COLLATE LOCALIZED, which isn't built-in to standard SQLite. What is the simplest way to get sqlite3.dll with COLLATE LOCALIZED support?
You need to download ICU extension for SQLite (it's just a single C file to be compiled), then load it into SQLite with:
SELECT load_extension('C:\path\to\icu_extension.dll');
Then you can use a newly created SQL function to create collations:
SELECT icu_load_collation('en_US', 'LOCALIZED');

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.

Sqlite: Are SQLITE_ENABLE_STAT3 tables created when upgrading?

Consider an SQLite database created with the SQLITE_ENABLE_STAT2 flag set. After updating my software, the new SQLite version seems to use another flag; SQLITE_ENABLE_STAT3.
Will these stat3 optimizations be available when opening and old database created with stat2? Or is it perhaps necessary to run the ANALYZE command?
The ANALYZE command is necessary.

How to export SQLite to JSON?

Is there any way to get a SQLite view on a JSON file?
Thanks
On recent versions of SQLite, this is built in. The following:
sqlite3> .mode json
sqlite3> .once out.json
sqlite3> SELECT * from foo;
writes the table foo to out.json.
Or, directly from the command line:
sqlite3 db.sqlite3 '.mode json' '.once out.json' 'select * from foo'
.once, which writes the output of the next SQL command to the indicated file, has been in SQLite since 3.8.5 in 2014.
The .mode json is newer though, added in 3.33.0 in 2020-08. It comes with ubuntu 20.10 but older operating systems are unlikely to have that feature in their built-in SQLite version.
SQLiteStudio (sqlitestudio.pl) can export from sqlite3 database to JSON. SQLiteStudio is C++ Qt-based, open source GPLv3 licensed, Linux/macOS/Windows application with a git repository here: 'pawelsalawa/sqlitestudio'.
There are certainly ways to do this. For example, you could write a custom program that parses the JSON input via your favorite JSON processor and then generate the equivalent SQL statements to create tables, insert the rows, etc. and then import that into a SQLite capable tool (DB Browser for SQLite) to generate the actual SQLite db file.
I suspect you will be hard pressed to find a general purpose tool to accomplish this, as the content of the JSON input could vary widely, and in fact may not map well into a relational database at all.

Resources