Getting COLLATE LOCALIZED/UNICODE on non-Android SQLite - 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');

Related

How to import SQLite data into DuckDB?

How to import SQLite data into DuckDB? Or is it possible to query the SQLite data files directly from DuckDB? A presentation from author of DuckDB mentioned such a feature.
yes it is possible to scan SQLite db files directly by using the sqlite extension
You first will need to install and load it
INSTALL sqlite_scanner
LOAD sqlite_scanner
CALL sqlite_attach('your_sqlite_db.db');
Then you should be able to query the sqlite tables.

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.

How to export an sqlite database as queries

I have created and populated a database using SQLite Toolbox for Visual Studio but find it improper to commit a binary to my CVS.. I was thinking about exporting it as queries that I can then run to create the database with the data.
Unfortunately, I haven't found a way to achieve this from SQLite Toolbox but maybe there some functionality directly from SQLite or another tool I can use for this ?
You can export database as queries in sqlite3 using
sqlite3 your_database.db .dump > queries.sql
This queries.sql file can use for database restore.
To restore
sqlite3 new_database.db < queries.sql
which will create new_database.db

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.

Accessing .sqlite db from phpmyadmin? FF cookies

I'm trying to view my firefox cookies db (cookies.sqlite). Since I've never accessed dbs with anything other than phpmyadmin, I'm at a loss as to how to view the content of this sqlite file. There's localhost/sqlitemanager, but I'd rather stick to the phpmyadmin interface that I'm used to.
Any ideas how I can open/view this sqlite db the normal way in phpmyadmin? Is it possible?
Thanks in advance
P.S. I know that browser cookies are very commonly accessed/played with. If you know another tool that's more specific for this goal, please drop me an answer or suggest in the comments.
There are also several web interfaces for sqlite.
phpSQLiteAdmin
SQLiteManager
Simple SQLite Manager
SQLite Admin
WizSQLiteAdmin
ezSqliteAdmin
SQLiteWebAdmin
knoda
I have not yet tried any of them - in fact, I found this SO question while researching sqlite web front-ends for my own use. But I, too, come from a phpMyAdmin background, so the first one I plan to try is phpSQLiteAdmin.
I imagine there are various GUI programs that will hold your hand. However, I'm going to show you what I would do if I was interested in table moz_cookies in db cookies.sqlite.
$
$ sqlite3 cookies.sqlite
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER);
sqlite> select * from moz_cookies limit 1;
1248713741170186|PREF|ID=12d44375be9e7c86:U=d07dae1b87f4537c:LD=en:NR=100:TM=1248713740:LM=1254091506:FV=2:IG=3:S=Jdo_PXt92J5ojL6E|.google.com|/|1317163505|1255144201180851|0|0
sqlite>
You may want the sqlite3 CLI program. It is available on Unix and Windows.
SQLITE3(1) SQLITE3(1)
NAME
sqlite3 - A command line interface for SQLite version 3
SYNOPSIS
sqlite3 [options] [databasefile] [SQL]
SUMMARY
sqlite3 is a terminal-based front-end to the SQLite library that can
evaluate queries interactively and display the results in multiple for‐
mats. sqlite3 can also be used within shell scripts and other applica‐
tions to provide batch processing features.
DESCRIPTION
To start a sqlite3 interactive session, invoke the sqlite3 command and
optionally provide the name of a database file. If the database file
does not exist, it will be created. If the database file does exist,
it will be opened.
It has two categories of operations.
Commands intended directly for the interactive shell begin with .. Anything is an SQL query terminated as usual with ;.
Adminer is a PHPMyAdmin-like system that has support for MySQL, PostgreSQL, SQLite, MS SQL, Oracle, SimpleDB, Elasticsearch, MongoDB, etc.

Resources