[Qt-interest] SQL abstraction layer (like SQLAlchemy) for Qt4?

Jason H scorp1us at yahoo.com
Mon Oct 19 20:14:28 CEST 2009


I wrote one, but forcommercial code. 

In reality, if you just use QVariantMaps, you can accomplish a lot.

dbSelect(QString table, QVariantMap whereClause) 
dbSelect(QString table, QStringList columns, QVariantMap whereClause) 
dbInsert(QString table, QVariantMap values) 
dbUpdate(QString table, QVariantMap values, VariantMap whereClause) 

dbInsertOrUpdate(QString table, QVariantMap values, VariantMap whereClause) 

dbOneRow(QString table, QVariantMap whereClause)
dbOneRow(QString table, QStringList columns, QVariantMap whereClause)
dbOneValue(QString table, QString column, QVariantMap whereClause)

The above are actually quite redimentary, when you use QSqlQuery::prepare() and  run-time create the queries.

I still have yet to come up with some way to express whereClauses as more than ANDed equivelence relations.
It should be a class that takes a series of criterion, and a relation between criterion.

typedef QList<Criterions> CriterionGroup;
CriterionGroup ands(And);
ands.addCriterion(QString columnName, Comparison comp, QVariant value) // addCriterion('age', GreaterThanOrEqual, 17)
CriterionGroup ors(Or);
ors.addCriterion(QString columnName, Comparison comp, QVariant value)
WhereClause wc.setRootCriterion(ands, And, ors)

But things get crazy complicated in the code base. True, you do get a better abstraction. And you can bettervisualize your query criterion. But I got this far and said f-it. And just went with QString-based where clauses if I needed to express anything other than anded equivalence because my timeline didn't allow for that uncommon use case. 







________________________________
From: Bastian Bense <bastibense at gmail.com>
To: qt-interest at trolltech.com
Sent: Mon, October 19, 2009 10:39:27 AM
Subject: [Qt-interest] SQL abstraction layer (like SQLAlchemy) for Qt4?

Hey everyone,

this might be a bit off-topic, but I was wondering if there is something like SQLAlchemy (for Python, http://www.sqlalchemy.org/features.html) for C++/Qt4.
Qt already offers a simple database abtraction layer (QSqlDatabase, etc.), but those classes still require you to write SQL statements to control queries.

SQLAlchemy for instance provides an object-based interface to the database. I'm sure something like that could be done using QObjects or at least a similar class that resembles the tables and records as object instances.

Any ideas? :)

-- 
Best regards,
Bastian

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091019/1d6eb346/attachment.html 


More information about the Qt-interest-old mailing list