[Qt-interest] Database abstraction with QSqlQueryModel

Jason H scorp1us at yahoo.com
Tue Aug 24 23:52:51 CEST 2010


I have in the past written my own.
The heart of it is QMap<QString, QVariant>which is used for keys, values, and 
where conditions (equivalence only)
Select queries return QList<QMap<QString, QVariant> >, however only when you can 
cache the whole result set.

Sometimes, I wonder it is more trouble than it is worth, but ultimately, I am 
100% abstracted from the database (when I use it).
I still end up doing raw queries, but these tend to be very portable.

This kind of tuple-based interface is very liberating. Unfortunately it works 
out better in python with anonymous objects, which C++ doesn't do so well...
You can't do QMap((QString("column1"), QVariant("data1")), (QString("column2"), 
QVariant("data2"));
So you end up doing 
QVariantMap where;
where["column1"]="data1";
where["column2"]="data2";

QVariantMap set;
where["column1"]="data11";
where["column2"]="data22";

db.update(set, where);




----- Original Message ----
From: Neville Dastur <qt at dastur.me.uk>
To: QT Mailing LIST <qt-interest at trolltech.com>
Sent: Tue, August 24, 2010 2:11:08 PM
Subject: [Qt-interest] Database abstraction with QSqlQueryModel

Just checking I've got this right and not missing something.

The QSqlQueryModel doesn't seem to support full database abstraction. So 
what I mean by this is parameters etc. QSqlQuery on which it is based 
has bindValue(), but this is not implemented in QSqlQueryModel and so I 
have to code my own quoting and escaping of of data values? Also can't 
seem to find a way to use QSqlQuery to generate a sql statement that I 
can then pass to QSqlQueryModel.

Is this right, before I post an item on Qt bug tracker.

Thanks

Neville
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest



      



More information about the Qt-interest-old mailing list