2

I'm trying to run this Qt code

QString serverName = "localhost";
QString dbName = "zfserver";
QString userName = "root";
QString passWord = "123456";

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setConnectOptions();

db.setHostName(serverName);
db.setDatabaseName(dbName);
db.setUserName(userName);
db.setPassword(passWord);

if(db.open())
{
    QSqlQuery query;
    query.prepare("INSERT INTO account (name, email, password, type) "
                  "VALUES (:name, :email, :password, :type)");
    query.bindValue(":name", "atef");
    query.bindValue(":email", "[email protected]");
    query.bindValue(":password", "123");
    query.bindValue(":type", "2");

    if (query.exec())
    {
        qDebug() << "OK";
    } else {
        qDebug() << "Error" << query.lastError().text();
    }

    db.close();
}

But I'm getting this error

Error "Using unsupported buffer type: 1701601889 (parameter: 1) QMYSQL3: Unable to bind value"

If I change the query without the bindValue it works. Is there a way to solve this?

4
  • 1) QT is a different project. Read the tagwiki. 2) What Qt version is this? 3) What platform is this? 4) What architecture is this? 5) Why are you using QMYSQL3?! 5) Have you checked the return value of prepare? 6) Have you tried to print out the last query? Commented Apr 18, 2014 at 4:52
  • I'm using QT Qt 5.2.1 with mingw windows 7, i just downloaded QT and installed it and trying it for first time i don't know how to use another version of QMYSQL3 its the default one, when i change the query to normal query without prepare and bindValue its excuting without errors. Commented Apr 18, 2014 at 15:18
  • Can you answer 5-6), please? Also, make sure you do not call addDatabase repeatedly as it should be called only once. Commented Apr 19, 2014 at 3:06
  • thanks Laszlo i have fixed this by rebuilding the QT mysql driver. Commented Apr 19, 2014 at 3:17

1 Answer 1

0

Try to rebuild the SQL driver .

QMYSQL3 seems to be old.

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.