Results 1 to 5 of 5

Thread: Test for existence of SQLite db

  1. #1
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Test for existence of SQLite db

    Hey all --

    I'm very, very adverse to posting questions on technical forums mainly because I like to figure things out myself, but with the project I'm currently working on and the time constraints it presents, I must throw questions out and subject myself to the abuse I might endure as a result Trust me I've tried to figure this out...

    Is there any way with Qt's libraries to ping a SQLite database for it's existence prior to creating it? SQLite will try to create a db if it doesn't exist but I don't want that to happen -- it looks like there's ways to do it with their libraries but as of a few days ago I'd prefer to stay with the Qt ones...I'm trying to perform the following and the first line is the keystone...

    if (DB doesn't exist) then
    if (username/password is the default administrator pairing) then
    go to the Admin form for DB and user creation
    else
    display Not Authorized-type error message and kick 'em out
    end if
    else /* DB does exist */
    verify user credentials by querying DB
    If (not authorized) then
    display Not Authorized-type error message and kick 'em out
    else
    set up proper roles for this user
    end if
    end if


    If I've overlooked something in my searched, please be kind


    scott

    looks like I lost my formatting -- sorry!

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Test for existence of SQLite db

    Have a look at: QFile::exists()

  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: Test for existence of SQLite db

    I do a simple file existence check. If the file exists then I try to open it as an Sqlite DB and check that there are tables if there should be. Unfortunately a zero-byte file can be successfully opened but may not be a useful database.

    Another option is to read the first 16 bytes of the file. The well known 16-byte sequence that begins every SQLite database file is:
    0x53 0x51 0x4c 0x69 0x74 0x65 0x20 0x66 0x6f 0x72 0x6d 0x61 0x74 0x20 0x33 0x00
    That's "SQLITE3 format 3\0"

  4. The following user says thank you to ChrisW67 for this useful post:

    srazi (4th February 2011)

  5. #4
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Test for existence of SQLite db

    Thanks for the replies...I was thinking about the "file exists" approach but didn't want to go off in that direction without an outside opinion...The way this apps going to work even if it's not a real SQLite file I'll be able to handle it...I'll just shut the app down

    thanks again!


    -- scott

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Test for existence of SQLite db

    Quote Originally Posted by ChrisW67 View Post
    I do a simple file existence check. If the file exists then I try to open it as an Sqlite DB and check that there are tables if there should be. Unfortunately a zero-byte file can be successfully opened but may not be a useful database.
    This is exactly like I do it. As for the zero-byte file (or sqlite files that does not belong to my application) I also check after opening the database if it has the right structure using the table sqlite_master.

Similar Threads

  1. check IPAddress existence
    By navi1084 in forum Qt Programming
    Replies: 8
    Last Post: 16th May 2013, 21:26
  2. [Qt][SQLite] Two problems with SQLite.
    By Xandareva in forum Newbie
    Replies: 6
    Last Post: 6th April 2010, 23:06
  3. A.I. test. A.I. test.
    By Kumosan in forum General Discussion
    Replies: 3
    Last Post: 19th October 2007, 19:19

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.