Results 1 to 4 of 4

Thread: How to verify a QSqlRecord with PostgreSQL restrictions

  1. #1
    Join Date
    Jul 2008
    Location
    Spain
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to verify a QSqlRecord with PostgreSQL restrictions

    I have these connection:
    Qt Code:
    1. connect((const QObject *)my_model, SIGNAL(beforeUpdate(int, QSqlRecord &)), this, SLOT(My_verify_record(int, QSqlRecord &)));
    2. connect((const QObject *)my_model, SIGNAL(primeInsert(int, QSqlRecord &)), this, SLOT(My_verify_record(int, QSqlRecord &)));
    To copy to clipboard, switch view to plain text mode 

    This is my slot definition:
    Qt Code:
    1. void My_class::My_verify_record(int my_row, QSqlRecord &my_record)
    2. {
    3. for(int my_column = 0; my_column < my_record.count(); my_column++)
    4. {
    5. // Verify that current column content fulfills the field definition in PostgreSQL
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    For example, if one field is defined as "NOT NULL" in PostgreSQL, I need to detect this fact inside the loop to warn the user.
    Auryn
    Starting to learn the world of Qt

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to verify a QSqlRecord with PostgreSQL restrictions

    And what is the problem?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to verify a QSqlRecord with PostgreSQL restrictions

    Quote Originally Posted by Auryn View Post
    For example, if one field is defined as "NOT NULL" in PostgreSQL, I need to detect this fact inside the loop to warn the user.
    QSqlField provides some basing information, but you can query information_schema to get information about all constraints. The problem is that you will have to parse the contents of check_clause field from information_schema.check_constraints.

    You can validate a record by starting a transaction, inserting data and rolling the transaction back, but that's not an efficient solution.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to verify a QSqlRecord with PostgreSQL restrictions

    A much better is to implement static checks knowing the structure of the database.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.