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.
Related
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.
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
Here is my issue. I am using Titanium Appcelerator to build an app that accesses my database and other various things. I have two separate files. One being an et.sql file in readable format and the other et.sql file with a top line of SQLite format 3���# and the rest being ASCII or some text in an unreadable format.
var db = Ti.Database.install('et.sqlite','et');
var db = Ti.Database.open('et');
This produces an sql file that gets installed inside a folder that the app will use in the future.
When using this et.sql file with the header of SQLite format 3Ä# it is accepting it inside Titanium and the app builds with my code, the other file that is formatted it doesn't accept. It seems like it needs to be in sqlite format.
I am using SQLite Manager for Firefox to update my sqlite file with new tables, etc that in turn gets installed in Titanium that produces an sql file. Problem here is I can't seem to reproduce a sql file that is in sqlite format. The previous developer didn't leave any notes on how to do this and I've struggled to produce this file in a format that works. I've looked into using sqlite3 command line, but I've had no luck. How do I get titanium or sqlite for that matter to dump this file in sqlite format so that it can be used inside Titanium?
I am fairly new to sqlite so if I'm overseeing anything just point it out.
You can use the sqlite3 command-line tool to convert between text files containing SQL statements and SQLite database files:
sqlite3 newfile.sqlite < oldfile.sql
sqlite3 oldfile.sqlite .dump > newfile.sql
Very basic question, having a hard time finding an explanation online.
I have a file code.sql that can be run on two different databases, a.db3 and b.db3. I used sqlite a.db3 to open the database in sqlite3. How do I run code.sql on it?
Use the .read code.sql command, or call sqlite3 with the file as input: sqlite3 a.db3 < code.sql.
I am guessing that you are trying to use the sqlite3 command line tool that you can dowload from the sqlite.org website.
I recomend that you use, instead, sqlitestudio http://sqlitestudio.one.pl
This has a feature to execute SQL from a file on a database:
Use DB Browser for SQLite is a high quality, visual, open source tool to create, design, and edit database files compatible with SQLite.
You can download the DB Browser at SQLite https://sqlitebrowser.org/
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.