1

The following is the sql statement

QString  myQuery = "UPDATE myTable SET myAttr = :myAttr WHERE ID = 1";    

//m_query is a QSqlQuery object pointer
m_query->prepare(myQuery);
QString value = "some value";
m_query->bindValue(":myAttr", QVariant(value)) ;
m_query->exec();

But when I print the executedQuery, it shows the value for **myAttr = ?**

The execution doesn't incur any complain about the bindValue(). Anyone aware what's going on here? I am using QT5.2.1 MinGW_32bits Thanks in advance.

4
  • I'm not sure, but executedQuery won't show you query with bound value. Just a string with placeholder Commented Jul 3, 2014 at 22:08
  • 1
    @tema thanks for the reply. However, I have double checked the executedQuery in qt and it shows the following: In most cases this function returns the same string as lastQuery(). If a prepared query with placeholders is executed on a DBMS that does not support it, the preparation of this query is emulated. The placeholders in the original query are replaced with their bound values to form a new query. This function returns the modified query. It is mostly useful for debugging purposes. Commented Jul 3, 2014 at 22:24
  • 1
    The cited documentation part tells you clearly, that values in this string are replaced only if the DBMS (underlying database driver) doesn't support variable binding by itself. This means that if you're using MySQL, SQLite3, PostgreSQL, Oracle, etc., then this won't work for you. Qt is unable to show you the final SQL being executed, because database's driver hides it from Qt. Commented Jul 3, 2014 at 23:05
  • @Googie exactly right. However, I think the underlying database driver supports variable binding. It works perfectly in older version of QT. Commented Jul 4, 2014 at 22:01

1 Answer 1

1

I have solved the problem using the following:

change the  :myAttr to :MYATTR

and when you bind the value, follow the same format.

m_query->bindValue(":MYATTR", QVariant(value)) **strong text**

I think it is an issue for newer version of QTCreator.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.