PDA

View Full Version : Query Size needed



baray98
17th July 2009, 18:24
background:

I am using QOBDC driver on my windows application and it is connected on MS SQL database.

My woe:

I use QTableView with QSqlTableModel to display the result of my query and I want to display the number of records returned from my query. When i use QSqlQuery::size() it will only give me -1 and if I use QSqlTableModel::rowCount() it will only give the rows in model's cache.

It seems like my driver doesn't support QSqlDriver::QuerySize, Is there any other way?

is there a QOBDC driver thats support query size?

baray98

caduel
17th July 2009, 18:55
If your driver does not support this, you can first execute a query selection "count(1)" for your query. Obviously, this is not as fast as if the driver or database could do that...

HTH

baray98
17th July 2009, 22:37
pardon my being newbie but can you elaborate on "execute count(1)" thingy I don't understand

wysota
17th July 2009, 22:51
It's about asking the database to return the number of rows in the table.

baray98
18th July 2009, 04:52
I don't think this is an easy task since my user will input the SQL statement and then i will display the result in a table. and the number of records return would be at the bottom

Is there any other way of knowing the sqlresult size?

Is there anything i should in MS SQL to support sqlresult size?

baray98

Lykurg
18th July 2009, 09:23
parse the string with the query and replace the content between SELECT and FROM with count(1), then you will get the number of rows for that particular query.