PDA

View Full Version : Multi-table editable QSqlQueryModel



i92guboj
20th August 2013, 12:39
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:



setQuery("SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_cascos_y_accesorios WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_complementos WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_puertas_y_cajones WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_electrodomesticos WHERE presupuesto=?;");


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 :)

Lesiok
20th August 2013, 12:47
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 :

setQuery("SELECT fam,ref,desc,cant,pvp,incr,sub FROM presupuestados_cascos_y_accesorios, 1 AS from_t WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub, 2 AS from_t FROM presupuestados_complementos WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub, 3 AS from_t FROM presupuestados_puertas_y_cajones WHERE presupuesto=? UNION "
"SELECT fam,ref,desc,cant,pvp,incr,sub, 4 AS from_t FROM presupuestados_electrodomesticos WHERE presupuesto=?;");and use field from_t to detect db table.

i92guboj
20th August 2013, 13:04
And that's my "shame of the day" :)

It can't be any simpler.

Thank you so much. Case closed.