Results 1 to 5 of 5

Thread: How to find that, i am creating database first time

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to find that, i am creating database first time

    Hi...I am building a qt(4.5.3) application which uses sqlite database. My sample code is

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

    Here db.open() function opens my database, creates new databas(sample) if didnt existed.
    Any how it returning db handle. But my issue is, if i am creating database first time i need to create some tables. If database already existed then need to read those tables. If i am using db.open() function it returning a valid db handle but how can i know that my database is created just now are it has been created before. please give me a solution.( i am new to qt)

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to find that, i am creating database first time

    use CREATE TABLE IF NOT EXISTS statement when tables are being created.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find that, i am creating database first time

    I use this solution in my cae...let me explain exactly what i am looking for..
    case 1:
    1) user starts the application. user will see a login screen(user id , password)
    If user is allready using application( not launching first time ) then login credentials can be compared with the existing values which are all ready stored in a table( say table name LOGINTB) for authentication. simply i will try to read the table values in my db.

    case 2:
    2) My problem is here...
    If user launching my application first time he wont get login screen. he has to get a screen which asks user to create user id and password and some personal details. But in order show this screen i have know there is nothing such table called LOGINTB in my db.
    we can create that table if not existed but how can i spot table not existed before..bacause i need to show other than login screen if user launching my app first time

    I hope you understand my prob. Please reply me if you require any further information.

  4. #4
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find that, i am creating database first time

    a typo mistake ..
    I use this solution in my cae/-->I cannot use this solution in my case
    please read my explination above

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to find that, i am creating database first time

    try to check if database is opened using QSqlDatabase::isOpen or QSqlDatabase::isValid and if database is not valid/opened then show dialog and create database.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. problem creating a mysql database
    By TonyB in forum Qt Programming
    Replies: 10
    Last Post: 23rd July 2010, 15:39
  2. Qt and VC++ instalation problem
    By gui.br in forum Installation and Deployment
    Replies: 6
    Last Post: 21st July 2009, 07:13
  3. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  4. How to find out scene update time
    By nileshsince1980 in forum Qt Programming
    Replies: 5
    Last Post: 20th September 2007, 09:46
  5. How to find the presence of scroll bars at run time
    By anju123 in forum Qt Programming
    Replies: 8
    Last Post: 28th July 2007, 20:30

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
  •  
Qt is a trademark of The Qt Company.