Results 1 to 3 of 3

Thread: Saving parts of an SQLITE database to a new file

  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Saving parts of an SQLITE database to a new file

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving parts of an SQLITE database to a new file

    Unless SQLite contains such functionality embedded into itself (which I doubt it does), you have to do it manually.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Saving parts of an SQLITE database to a new file

    You could try the SQLite ATTACH DATABASE command to attach another (empty) database and then use basic SQL to move the data. Something like:
    Qt Code:
    1. ATTACH DATABASE filename AS newdb;
    2. CREATE TABLE newdb.tablename AS SELECT * FROM tablename WHERE timeframe conditions;
    To copy to clipboard, switch view to plain text mode 
    You may need the new table to have a different name.

Similar Threads

  1. Problem saving txtfile contents to database
    By cutie.monkey in forum Qt Programming
    Replies: 0
    Last Post: 6th January 2010, 07:11
  2. SQLITE ATTACH database
    By drescherjm in forum Qt Programming
    Replies: 8
    Last Post: 9th December 2009, 07:25
  3. QFile - file read parts of the buffer
    By eugen_Qt in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 14:52
  4. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38
  5. [QT4][SQLITE] Database and query
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 12th July 2006, 22:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.