Results 1 to 9 of 9

Thread: How to validate a form?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    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?

    Really, you have posted insufficient information. We are commenting on the code that you have posted, but then you say you do more checks further down the line, so our comments become useless. We don't know your form nor your database, so we are basically answering blind with generic information, so to speak.

    I would change your return value too, returning 0 (FALSE) for OK seems a little strange. Imagine the code calling your validation - if (!ValidateForm()) { // Form is OK } looks odd and is not self-documenting. Personally, I would probably create an enum and return something like VALIDATE_SUCCESS or something like that.

    Secondly, I would change the sql to a stored procedure, something like:

    Qt Code:
    1. CREATE PROCEDURE isInvoiceEntriesPresent
    2. AS
    3. SELECT COUNT(1) FROM tempinvoiceentries;
    To copy to clipboard, switch view to plain text mode 

    and then your query becomes more self-explanatory:

    Qt Code:
    1. query.exec("{call isInvoiceEntriesPresent}");
    To copy to clipboard, switch view to plain text mode 

    This also means you can change your method without having to recompile your code. Assume you are on a customers site with a problem, altering SQL is easier than having to do a full recompile and redeployment.

    Unless your interested in the content of the data fields (ie, non-null), use COUNT(1) as above instead of COUNT(*). The former will give you more performance as it doesn't have to retrieve all the database data. Another reason for stored procedures is that they are typically pre-compiled (depending on the underlying implementation), so don't need to be parsed and offer even more performance.

    etc...
    Last edited by squidge; 28th February 2011 at 14:22.

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

    homerun4711 (28th February 2011)

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.