[Qt-interest] QSqlQuery used with bindValue, returns QSqlError(-1, "", "") last error when query.exec() executes

Sean Harmer sean.harmer at maps-technology.com
Fri Aug 21 10:04:23 CEST 2009


Hi,

On Thursday 20 Aug 2009 20:28:30 S. Aguinaga wrote:
> Thanks you for the feedback, I truly appreciate it.
No problem.

> Got that, I didn't realize that replying to a previous post and changing
> the subject isn't enough to start a new thread.
>
> ok. So, I get the following when I use: qDebug() <<
> query.lastError();"QSqlError(-1, "", "") "
>
> so, the line: QDate::currentDate().toString("dd,mm,yyyy") is not going to
> be a QString? because if I type qDebug() <<
> QDate::currentDate().toString("dd,mm,yyyy"); it sends the String to the
> console.  
Yes, it will be a string but my point is that it is a string that contains 
commas which is what SQL uses as a delimiter for statements. So your date 
string will be interpreted by SQL as 3 columns of data not just one. This will 
lead to a mismatch between the number of columns you specify and the number of 
columns of data that your appear to provide in the query.

Looking at the QSqlQuery::bindValue() docs, it seems that you do not need to 
explicitly convert your QDate object to a string. Just wrap it in a QVariant 
and let Qt do the work for you. i.e. Just try:

QVariant v( QDate::currentDate() );
query.bindValue( ":CreateDate", v );

Qt should then take care of converting this to a form that your database can 
understand. If that does not work, then you need to find out what format your 
particular DB expects to be given a date in.

> Do you think I'm still missing the point here? I coud rewrite
> this to read:
>
> QString tmpString  = QDate::currentDate().toString("dd,mm,yyyy");
>
> >query.bindValue(":CreateDate", tmpString);
>
> I'm new to developing with SQL, how do I enable extra logging? and how do I
> do profiling of my db Server?
What type of database are you using? This is not directly related to Qt. You 
need to read the docs for your database server.

> Also, when I reply to a thread ... do I reply to you and copy the list? 
I think most people just reply to the list in the expectation that the author 
is reading the list.

Cheers,

Sean



More information about the Qt-interest-old mailing list