[Qt-interest] Variants and Binds
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Thu Sep 24 03:04:24 CEST 2009
I have no idea what the Qt Oracle driver does. It should be able to
transfer date/time values into the database without converting them to or
from string.
to_char is an Oracle function, and has nothing to do with Qt.
Tony.
> -----Original Message-----
> From: Jason H [mailto:scorp1us at yahoo.com]
> Sent: Thursday, 24 September 2009 10:54
> To: Tony Rietwyk; qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Variants and Binds
>
>
> 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.
More information about the Qt-interest-old
mailing list