[Qt-interest] Variants and Binds

Jason H scorp1us at yahoo.com
Thu Sep 24 02:54:22 CEST 2009


It does help, but where does the "to_char('2001-01-01', 'YYYY-MM-DD')" come from? I learned that was being done from from boundValues()



----- Original Message ----
From: Tony Rietwyk <tony.rietwyk at rightsoft.com.au>
To: qt-interest at trolltech.com
Sent: Wednesday, September 23, 2009 8:45:54 PM
Subject: Re: [Qt-interest] Variants and Binds

Jason wrote:

> I wish to add a new kind of class to QVariant, so that I can 
> use it in a SQL bind.
> 
> Specifically, I need to provide access to database 
> expressions. For  instance a QDate object is serialized to 
> to_char('2001-01-01', 'YYYY-MM-DD') when used in Oracle. I 
> need to provide a very similar thing in that I need 
> SEQUENCE.nextval (an expression, not a string) so that my 
> call is bindValue(":rowid", 
> Expression("TABLE_ID_SEQUENCE.nextval")); If I use a 
> QByteArray, I get "TABLE_ID_SEQUENCE.nextval", the string, 
> and that isn't a valid numeric record ID. 
> 
> So I need to know how I can create  a datatype that won't be quoted. 
> 
> Thanks!

Hi Jason, 

Even if you did add the extra type to QVariant, it would not work.  A SQL
expression can only be evaluated on the server, and you can only bind values
on the client.  

I think you can either: 

- Put the expression into the actual SQL statement, for example, insert into
tableName(fieldName1, fieldName2...) values (TABLE_ID_SEQUENCE.nextval,
:fieldName2...)

    Then just bind the other fields. 

- Or you need to explicitly select the value from the sequence first: 

    myQuery.exec("select TABLE_ID_SEQUENCE.nextval from dual");
    myQuery.next();
    int sequence = myQuery.value(0).toInt;

then bind that value just like the fields.  

Hope that helps, 

Tony.


_______________________________________________
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