Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, January 2008
The best way to handle SQL views in Qt Model/View framework


Message 1 in thread

Hi everybody !

I'm back with my model/view programming problems :-)

This time my concerns are about the best way to handle SQL views.

My models are based on SQL databases (PostgreSQL). I have a normal SQL
table and a SQL view built upon this table with complex columns
calculations performed out using SQL stored procedures. Of course, this
SQL view is not editable.

Preliminary analysis shows me two ways to handle this :

First way:
I use the SQL table to set up a basic Qt model and I write a proxy model
that recreates the calculated columns. This proxy model uses a SQL query
in data() method to calculate appropriate values for each row of my basic
model.

pros: easy to implement, no problem to edit SQL table data

cons: I lost the database engine power in maintaining SQL view. Recreating
calculated columns is time expensive, even using optimized databases
stored procedures. I suppose this is because I need to run a SQL query for
each proxymodel row.

Second way :
I use the SQL view to set up my Qt model.

pros: fields calculations are peformed by SQL engine => displaying my data
in QTableView is very fast

cons: editing seems quite difficult to implement. I will have to write a
special procedure (using delegates ?) that runs a specific update query on
my SQL table. This query will be run each time I need to update a single
data. Should works but isn't satisfactory regarding the Modev/View
approach.

To make it short: Qt model based on SQL view is better for displaying
functionalities while Qt model based on SQL table is better for editing
functionalities. Ideally I would like to use a Qt model based on my SQL
view to display data **and** a Qt model based on my SQL table to edit
data. Of course these two models should be automatically sync (especially
concerning row order).

In your opinion what is the best solution regarding the Qt Model/View
framework ?

Thank you very much

jMax



Message 2 in thread

moebius@xxxxxxxxxx wrote:
> Hi everybody !
> 
> I'm back with my model/view programming problems :-)

Hi,

Did you have a look at:

http://labs.trolltech.com/page/Projects/QtJambi/JDBC

Its a bridge between jdbc and Qt. You'll find a datamodel there that 
allows you to both read and write into QTableView's.

-
Gunnar

> 
> This time my concerns are about the best way to handle SQL views.
> 
> My models are based on SQL databases (PostgreSQL). I have a normal SQL
> table and a SQL view built upon this table with complex columns
> calculations performed out using SQL stored procedures. Of course, this
> SQL view is not editable.
> 
> Preliminary analysis shows me two ways to handle this :
> 
> First way:
> I use the SQL table to set up a basic Qt model and I write a proxy model
> that recreates the calculated columns. This proxy model uses a SQL query
> in data() method to calculate appropriate values for each row of my basic
> model.
> 
> pros: easy to implement, no problem to edit SQL table data
> 
> cons: I lost the database engine power in maintaining SQL view. Recreating
> calculated columns is time expensive, even using optimized databases
> stored procedures. I suppose this is because I need to run a SQL query for
> each proxymodel row.
> 
> Second way :
> I use the SQL view to set up my Qt model.
> 
> pros: fields calculations are peformed by SQL engine => displaying my data
> in QTableView is very fast
> 
> cons: editing seems quite difficult to implement. I will have to write a
> special procedure (using delegates ?) that runs a specific update query on
> my SQL table. This query will be run each time I need to update a single
> data. Should works but isn't satisfactory regarding the Modev/View
> approach.
> 
> To make it short: Qt model based on SQL view is better for displaying
> functionalities while Qt model based on SQL table is better for editing
> functionalities. Ideally I would like to use a Qt model based on my SQL
> view to display data **and** a Qt model based on my SQL table to edit
> data. Of course these two models should be automatically sync (especially
> concerning row order).
> 
> In your opinion what is the best solution regarding the Qt Model/View
> framework ?
> 
> Thank you very much
> 
> jMax
> 
> 


Message 3 in thread

> moebius@xxxxxxxxxx wrote:
>> Hi everybody !
>>
>> I'm back with my model/view programming problems :-)
>
> Hi,
>
> Did you have a look at:
>
> http://labs.trolltech.com/page/Projects/QtJambi/JDBC
>
> Its a bridge between jdbc and Qt. You'll find a datamodel there that
> allows you to both read and write into QTableView's.
>
> -
> Gunnar
>

Hello !

Thanks for your response Gunnar. I know the Qt Jambi / JDBC project, but
it's not very helpful for my concerns. I don't have any problem to write
into QTableView. My question is about **SQL** views created using SQL
command
  CREATE VIEW
    AS SELECT...

I have already created complex SQL views using my database engine
(PostgreSQL) and these views can be used as tables from a Qt model point
of view. But they are read-only and I would like to avoid writing code in
my qt program to do the same (I'm a slightest effort partisan ;-) ).

Reconsidering the case shows me these concerns may be off-topic. The same
problem may occurs for all database-related applications who uses
read-only SQL views. But Qt is so powerful, people get into the habit it
knows how to solve all the problems ;-) !

Best regards,

jMax

>>
>> This time my concerns are about the best way to handle SQL views.
>>
>> My models are based on SQL databases (PostgreSQL). I have a normal SQL
>> table and a SQL view built upon this table with complex columns
>> calculations performed out using SQL stored procedures. Of course, this
>> SQL view is not editable.
>>
>> Preliminary analysis shows me two ways to handle this :
>>
>> First way:
>> I use the SQL table to set up a basic Qt model and I write a proxy model
>> that recreates the calculated columns. This proxy model uses a SQL query
>> in data() method to calculate appropriate values for each row of my
>> basic
>> model.
>>
>> pros: easy to implement, no problem to edit SQL table data
>>
>> cons: I lost the database engine power in maintaining SQL view.
>> Recreating
>> calculated columns is time expensive, even using optimized databases
>> stored procedures. I suppose this is because I need to run a SQL query
>> for
>> each proxymodel row.
>>
>> Second way :
>> I use the SQL view to set up my Qt model.
>>
>> pros: fields calculations are peformed by SQL engine => displaying my
>> data
>> in QTableView is very fast
>>
>> cons: editing seems quite difficult to implement. I will have to write a
>> special procedure (using delegates ?) that runs a specific update query
>> on
>> my SQL table. This query will be run each time I need to update a single
>> data. Should works but isn't satisfactory regarding the Modev/View
>> approach.
>>
>> To make it short: Qt model based on SQL view is better for displaying
>> functionalities while Qt model based on SQL table is better for editing
>> functionalities. Ideally I would like to use a Qt model based on my SQL
>> view to display data **and** a Qt model based on my SQL table to edit
>> data. Of course these two models should be automatically sync
>> (especially
>> concerning row order).
>>
>> In your opinion what is the best solution regarding the Qt Model/View
>> framework ?
>>
>> Thank you very much
>>
>> jMax
>>
>>
>
>