Results 1 to 2 of 2

Thread: How to validate QSQLITE file?

  1. #1
    Join Date
    Aug 2009
    Posts
    56
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default How to validate QSQLITE file?

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "TEMP");
    2. db.setDatabaseName(dbName);
    3. if (db.open() && db.isOpenError()==false && db.isValid()==true)
    4. {
    5. // Opened
    6. }
    7. else
    8. {
    9. // Display error
    10. }
    To copy to clipboard, switch view to plain text mode 

    I'm letting the user pick a file on the harddrive to open as an SQLite database. But I can pick ANY file and it will always reach the opened block. How do I check that a file is a valid SQLite database file?

    Thanks

  2. #2
    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: How to validate QSQLITE file?

    Try to query a table from the expected schema or just retrieve the tables list. If you get an error then it is not an Sqlite DB. You will not get an error retrieving the table list if the file you opened is non-existent or zero sized. If a user mistypes the name of an existing file then Sqlite will just create it, which is both useful and annoying.

Similar Threads

  1. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  2. Can you specify a file engine?
    By skimber in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2008, 15:54
  3. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  4. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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.