PDA

View Full Version : Saving parts of an SQLITE database to a new file



zarkzervo
11th February 2010, 07:35
Scenario: The user has queried the database and found some interesting data within a timeframe (fuel_level) and wants to extract all data fields within the same timeframe to a file to send to his supervisors for deeper analysis (throttle, air preassure and so on)

Is there some simple method of "duplicating" the database and then fill it with relevant data to a new database file? Do I have to create the new database from scratch? I would hope that I at least could reuse the table structure and then, if necessary, fill the tables with data manually.

All examples I've found are addressing the connection to a database and retrieving/adding data.

This may be some "obscure" use of database as most people handle _one_ database or extract data for viewing, but I hope someone has had a similar problem and can confirm my fears or give me some ideas.

wysota
19th February 2010, 11:03
Unless SQLite contains such functionality embedded into itself (which I doubt it does), you have to do it manually.

ChrisW67
21st February 2010, 00:59
You could try the SQLite ATTACH DATABASE (http://www.sqlite.org/lang_attach.html) command to attach another (empty) database and then use basic SQL to move the data. Something like:


ATTACH DATABASE filename AS newdb;
CREATE TABLE newdb.tablename AS SELECT * FROM tablename WHERE timeframe conditions;
You may need the new table to have a different name.