I need to process data from a SQLite database using some Java code. The problem is that the database is retrieved from an external service and thus it is only available as an InputStream.
I would really like to avoid saving the db to the file system before starting to process the data, but I don't see a way of doing it.
I am currently using SqlJet, as it provides an option to create an in-memory database. However there seems to be no way to turn an InputStream / byte array into a database.
There's nothing forcing me to use SqlJet, it can be easily replaced by any other tool if it provides the needed functionality.
It can't be done as such. Perhaps Java supports some mechanism to create some form of virtual file that is presented locally (to the current process) as some physical file.
I can think of one way to work-around the limitation, but that may not be doable or acceptable within your context. You can change the service to return a dump of the database and load that in the receiver's in-memory database:
Here is a way to generate the dump:
# sqlite3
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo (i text);
sqlite> insert into foo values ('a');
sqlite> insert into foo values ('b');
sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE foo (i text);
INSERT INTO foo VALUES('a');
INSERT INTO foo VALUES('b');
COMMIT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With