[Qt-interest] problem with bindValue() in nested queries
Francesco Lamonica
alienpenguin at gmail.com
Tue Jan 3 13:08:08 CET 2012
Hi Sujan,
what do you mean with "sometimes" integers do not work? are there
specific issues you encountered? in the DB the id filed is an integer
and that i cannot change.
however i tried replacing the bindValue like
q2.bindValue(":myid",QString::number(myid));
but i keep getting the very same error message
thanks :)
On Tue, Jan 3, 2012 at 11:35 AM, Sujan Dasmahapatra <sdh at lmwindpower.com> wrote:
> Sometimes the interger variables don't work. Instead try using a QString it should work.
>
> Kind regards,
>
>
> Sujan Dasmahapatra
> Project Leader, Aero Group
> CE - Aero Group
>
> Tel +91 80 66470248
> Mob
> sdh at lmwindpower.com
>
>
> LM Wind Power Blades
> lmwindpower.com
>
> Together we capture the wind to power a cleaner world
>
>
> This e-mail and any attachments are confidential. If you are not the named or intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Any unauthorized disclosure, use or storage is prohibited and might be unlawful.
> -----Original Message-----
> From: qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com [mailto:qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com] On Behalf Of Francesco Lamonica
> Sent: Tuesday, January 03, 2012 2:33 PM
> To: Qt Interest List
> Subject: [Qt-interest] problem with bindValue() in nested queries
>
> Hi all,
> i have a piece of code like:
>
> QSqlQuery query,q2;
> query.prepare("select * from table1");
> query.exec();
> while (query.next()) {
> int myid = query.record().value("id").toInt();
>
> q2.prepare ("select * from table2 where id=:myid");
> q2.bindValue(":myid",myid);
> q2.exec(); // <--- this fail
>
> }
>
> the error i get is:
> QSqlError(-1, "QPSQL: Unable to create query", "ERROR: operator does
> not exist: integer =?
> LINE 1: SELECT * FROM table2 WHERE id=?
> ^
> HINT: No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
> ") for query ( "SELECT * FROM table2 WHERE id=?" )
>
> a few more points:
> *) i am sure that myid is correct: qDebug() prints it out correctly;
> *) if i change the query like: q2.prepare("select * from table2 where
> id="+QString::number(myid)); everything works
> *) if i execute the query outside the while loop it works (test done
> setting myid to some sensible number)
> *) "external" query does not use any kind of bound values
> *) qt is 4.7.4 on linux gentoo (amd64), db is postgresql 9.1.2 (same platform)
>
> any ideas?
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list