Results 1 to 4 of 4

Thread: sqlite database creation

  1. #1
    Join Date
    Feb 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default sqlite database creation

    i wrote following code....

    QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("new.db");

    but i couldn't find the database in that folder.....is it not creating the database or the code is wrong????please help..........

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: sqlite database creation

    Quote Originally Posted by dimantoku View Post
    but i couldn't find the database in that folder.....is it not creating the database or the code is wrong????
    Have you opened the database yet? If so, the database will be created in the current working directory for the running application since you have not specified a path. If you have not yet opened the database, it will not be created until it's opened.

    Hope that helps.

  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: sqlite database creation

    If memory serves, Sqlite file will not create the actual file until after you create tables in it.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: sqlite database creation

    Perhaps the QSqlDatabase driver for SQLITE has this behavior, but the sqlite3 command line program will create an empty database as long as you do something that opens the database:

    Qt Code:
    1. sqlite3 test.sqlite "select * from sqlite_master"
    To copy to clipboard, switch view to plain text mode 

    The above on a non-existent database will result in zero byte file being created.

Similar Threads

  1. Replies: 2
    Last Post: 16th February 2012, 00:27
  2. Sqlite Database
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2011, 14:07
  3. SQLITE ATTACH database
    By drescherjm in forum Qt Programming
    Replies: 8
    Last Post: 9th December 2009, 08:25
  4. database creation error appeared...
    By GreyGeek in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2007, 14:43
  5. [QT4][SQLITE] Database and query
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 12th July 2006, 23:16

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.