Results 1 to 2 of 2

Thread: do you know how to check if a record exist in qt ?..

  1. #1

    Default do you know how to check if a record exist in qt ?..

    do you know how to check if a record exist in qt ?..

    what i would like to do is .. i listing all the members in a drop box which the names are from across 2 database tables ...

    so i would like to check if this record exist in the first table .. else check in table 2.. then proceed to do something..

    but i am stuck on how to check if a record exist in qt.. i am using sqlite.

  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: do you know how to check if a record exist in qt ?..

    You execute a query looking for the record and see if it returns any rows. There is nothing Qt-specific about this.
    Qt Code:
    1. bool ok;
    2. bool foundBoth = false;
    3. ok = q.exec("select 1 from table1 where field = value");
    4. if (ok && q.next()) {
    5. ok = q.exec("select 1 from table2 where field = value");
    6. if (ok && q.next()) {
    7. foundBoth = true;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    Use bound parameters if there is any chance the value can be supplied directly by the user or contain semicolons, quotes etc. Heck, just use bound parameters anyway.

Similar Threads

  1. How to check Table already exist or not
    By damodharan in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2010, 14:06
  2. Replies: 3
    Last Post: 26th March 2010, 05:32
  3. How to check if g++ exist in system.
    By sawerset in forum Newbie
    Replies: 2
    Last Post: 1st December 2008, 10:58
  4. qtdemo doesn't exist...
    By xyzt in forum Newbie
    Replies: 2
    Last Post: 24th March 2008, 06:37
  5. XML Database: eXist
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2007, 00:22

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.