Results 1 to 9 of 9

Thread: How to validate a form?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: How to validate a form?

    Applications return an error code in which 0 is 'The operation completed successfully' and other values are pre-defined error codes. If your function only returns SUCCESS or FAILURE (like the code snippet), then the closest match to these would be TRUE and FALSE. You could typedef these values as follows:

    Qt Code:
    1. typedef enum {FAILURE = 0, SUCCESS = !FAILURE} ErrorStatus;
    To copy to clipboard, switch view to plain text mode 

    COUNT(*) will retrieve all rows matching your condition (in your case, all rows, as you have no limits placed, so it will become slower over time and not scale well). It will then validate that the rows actually contain data. I'm sure when you created your schema that some fields you used the "NOT NULL" restriction to ensure they had data.

    COUNT(1) doesn't care if the rows contain data or not, only that they exist.

    Since your code only requires that at least one row exists, you could take it further:

    Qt Code:
    1. SELECT COUNT(1) FROM tempinvoiceentries LIMIT 1
    To copy to clipboard, switch view to plain text mode 

    This will always take the same amount of time to execute regardless of how many entries are in your table.

  2. The following user says thank you to squidge for this useful post:

    homerun4711 (28th February 2011)

  3. #2
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: How to validate a form?

    Thanks for the good information, I will rewrite some stuff now. I have a feeling that CREATE PROCEDURE will become a good friend of mine

Similar Threads

  1. How to validate QSQLITE file?
    By rakkar in forum Newbie
    Replies: 1
    Last Post: 24th September 2009, 01:05
  2. Validate a value of lineEdit
    By edgar in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2009, 18:22
  3. How to validate XML against DTD?
    By emental86 in forum Qt Programming
    Replies: 2
    Last Post: 29th April 2009, 13:11
  4. validate database connection
    By hoshy in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2009, 13:14
  5. Validate Data in QDialog
    By jcraig in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2007, 15:49

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.