[Interest] How to deal with database specific syntax

André Somers andre at familiesomers.nl
Thu Feb 12 09:30:56 CET 2015


Dmitriy Purgin schreef op 12-2-2015 om 08:04:
> Exactly, that's what I meant by "supporting the stored procedure call 
> syntax". Sorry, it was a bit vague. Anyway, in this case you're 
> implementing a single interface for an SP call backed by multiple 
> "syntax handlers" which is much easier than handling lots of syntactic 
> differences for any kind of operations one might want to do with a 
> database. It's not ideal, it has its drawbacks but it also has 
> advantages. Moreover, pmqt71 has explicitly stated that he/she doesn't 
> want to go the ORM way.

Normally in Qt, if you want to write db independent code, you have to 
create your queries using the QSqlDriver::sqlStatement method. Ignore 
the comment in the documentation that states "This class should not be 
used directly. Use QSqlDatabase instead.", as QSqlDatabase does not 
provide this API.

The basic problem is however that the Qt SQL drivers are really limited. 
They only support the basics of the DML and some TCL, but they don't do 
any more advanced things, including any DDL or indeed support for stored 
procedures. They also don't support functions you can use in SQL 
statements in database. So, there simply is no support for creating 
anything more advanced than a simple insert or select query.

A couple of years back, I wrote an extension to the Qt SQL drivers to 
add DDL support for a database agnostic application, and that extended 
the sqlStatement virtual method with many more features. It proved 
possible to do without modifying Qt itself, and it removed any database 
specific code I had in the application itself. Everything was abstracted 
into a new set of extended drivers. You may be able to do the same for 
accessing stored procedures in different database. If you are 
interested, I can point you to the code.

André






More information about the Interest mailing list