How to import SQLite data into DuckDB? - sqlite

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.

Related

Importing csv data into db database (sqlite)

What is the best way of importing csv data into a db database?
I am using sqlite.
Do I need to go through an intermediate step of converting to SQL? Cheers
You can use any sqlite gui tool like Sqlite studio to import data.

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

Creating Sqlite3 database using in-memory option

I am using latest Sqlite version 3.8.3.1 on Ubuntu host.
Here i am trying to create in-memory database in using c program and the option explained in the following link: http://www.sqlite.org/inmemorydb.html
Here database is created using following function call:
sqlite3_open("file::memory:?cache=shared", &db);
Here database file file::memory:?cache=shared is created on hard drive locally.
Here why sqlite3 is creating database file on the hard drive for in-memory option?
Let me know if i am doing something wrong?
URI filenames work only with sqlite3_open_v2.
You can make use of this to create database on RAM.
It's the in-memory implementation supported by python
import sqlite3
con = sqlite3.connect(':memory:')

How can I convert my Access database (.accdb) to SQLite?

How can I convert my Access database (.accdb) to an SQLite database(.sqlite)?
May be you can use several step algoritm:
1. Export (convert) Access table or query to Excel file
2. Save Excel file as CSV file.
3. Use any SQLLite manager (for example, phpLiteAdmin) to import data from CSV file to exist SQLLite table.
Except Android and IOS, that use SQLLite, there are still webhostings, that use no more database engine, except for SQLLite.
1) If you want to convert a structure of db you shoud use any DB-modeling tools:
create new model from existing Access Database
generate sql scripte for creating SQLite database
use this script in SQL helper
2) If you want to import data from Access Database to your android app. I think you can do case #1, migrate all data from Access Database to temporary SQLite database, save it to asset folder and rewrite from asset to internal SQLite database during first app. start

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