Results 1 to 3 of 3

Thread: Multi-table editable QSqlQueryModel

  1. #1
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Multi-table editable QSqlQueryModel

    Hello.

    I am trying to subclass an editable QSqlQueryModel.

    The thing would be simple enough, even for me, if it wasn't because I am taking data from many tables, using a query like this one:

    Qt Code:
    1. setQuery("SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_cascos_y_accesorios WHERE presupuesto=? UNION "
    2. "SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_complementos WHERE presupuesto=? UNION "
    3. "SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_puertas_y_cajones WHERE presupuesto=? UNION "
    4. "SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_electrodomesticos WHERE presupuesto=?;");
    To copy to clipboard, switch view to plain text mode 

    So, when it came the time to reimplement QSqlQueryModel::setData() I realized that, for this to be doable, I would need a way to know from which table a given row/record came from.

    What I want to ask is: is there any way to reference the table a given row came from using the model? Or should I just resort to something hackish like querying all my tables for matches?

    Thank you beforehand for any insight

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multi-table editable QSqlQueryModel

    If you perform this query in the console database that can You identify a table from which is a specific record? No.
    Maybe modify query something like this :
    Qt Code:
    1. setQuery("SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_cascos_y_accesorios, 1 AS from_t WHERE presupuesto=? UNION "
    2. "SELECT fam,ref,desc,cant,pvp,incr,sub, 2 AS from_t FROM presupuestados_complementos WHERE presupuesto=? UNION "
    3. "SELECT fam,ref,desc,cant,pvp,incr,sub, 3 AS from_t FROM presupuestados_puertas_y_cajones WHERE presupuesto=? UNION "
    4. "SELECT fam,ref,desc,cant,pvp,incr,sub, 4 AS from_t FROM presupuestados_electrodomesticos WHERE presupuesto=?;");
    To copy to clipboard, switch view to plain text mode 
    and use field from_t to detect db table.
    Last edited by Lesiok; 20th August 2013 at 12:51.

  3. #3
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multi-table editable QSqlQueryModel

    And that's my "shame of the day"

    It can't be any simpler.

    Thank you so much. Case closed.

Similar Threads

  1. Replies: 3
    Last Post: 3rd October 2011, 09:08
  2. Editable table header
    By bbarran in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2010, 11:26
  3. Replies: 1
    Last Post: 15th June 2009, 19:37
  4. Editable table header
    By cmaxb in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2006, 13:12
  5. make each row of table widget not editable??
    By darpan in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2006, 11: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.