[Qt-interest] qsqlquery anyone with any experience at all?

Scott Aron Bloom Scott.Bloom at onshorecs.com
Wed Sep 1 17:58:39 CEST 2010


-----Original Message-----
From: Roland Tollenaar [mailto:rwatollenaar at gmail.com] 
Sent: Wednesday, September 01, 2010 12:34 AM
To: Scott Aron Bloom
Cc: Qt-interest
Subject: Re: [Qt-interest] qsqlquery anyone with any experience at all?

Hi Scott,

> The .value( 0 ) is what of course converts the data to the qvariant...
Indeed, but good point.

>
> What kind of server are you connected too..
mssql 2005
--------
I have a very large db running a Qt client with 2005 server as well....
Its possible to get it running fast

----------

>That just seems awfully
> slow, and I haven't seen that before...
That gives me some hope....


>
> Is it possible that the server, or your query, is returning raw
strings,
> and you are converting them to other types??
I almost without exception convert to String using:

toString()

so ThisString=query.value(0).toString();
-------------

Well if all you got is strings, nothing else you can do :)
-------------
>
> Your datetimes can be very slow because of the string to date parsing
> that goes on...
there are not many datetimes. one or two.


What is interesting is that the data is retrieved from the database 
server in the while(query.next()) loop. I was always under the 
impression that all the data was retrieved on the exec call and then 
parsed  locally in the while loop. However that is definitely not the
case.

Regards,

Roland


-----------
That's normal, and frankly expected, the exec has the server compute the
recordset, but not waste the bandwidth to send the data back...

I would try, just for an example sake, to use QSqlQueryModel and
QTableView.. Does it seem overly slow...

----------------
QSettings settings(QCoreApplication::applicationDirPath() + "/mast.ini",
QSettings::IniFormat);
	QString MSTdbType=settings.value("MSTDB/Type", "no
Driver").toString();
	QString MSTdbHost=settings.value("MSTDB/Host", "No
Host").toString();
	QString MSTdbDatabaseName=settings.value("MSTDB/DatabaseName",
"No Name").toString();
	QString UserName=settings.value("MSTDB/UserName", "No
Name").toString();
	QString Password=settings.value("MSTDB/Password", "No
Name").toString();

	
	//Initiate database connection
	QSqlDatabase db =
QSqlDatabase::addDatabase(MSTdbType,"MASTDatabase");
     db.setHostName(MSTdbHost);
     db.setDatabaseName(MSTdbDatabaseName);
	db.setUserName(UserName);
	db.setPassword(Password);
     bool ok = db.open();
	if (!ok){
---------------
That's NOT how I usually connect to MS dbs...  It may work, but there
might be something messing things up...


I use a DSN method with a string as such (note, I have a generic DB
viewer that I wrote, with the setup in a ui file)

QSqlDatabas db =QSqlDatabase::addDatabase( fImpl->dbType->text() ); //
QODBC
QString dsn = QString( "DRIVER={SQL
Server};Server=%1\\%2;Database=%3;UID=%4;PWD=%5;" )
		.arg( fImpl->serverName->text() ) // my server name
		.arg( fImpl->instance->text() )   // the MS db instance
name
		.arg( fImpl->dbName->text() )     // the actual db name
in the isntance
		.arg( fImpl->adminUserName->text() )  // the DB's login
credentials
		.arg( fImpl->adminPassword->text() ); 

db.setDatabaseName( dsn );
if ( !db.open() )
{ 
   QMessageBox.....
}

return db.open();

Hope this helps

Scott










More information about the Qt-interest-old mailing list