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", "asfasf@gfasga.com");
    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?

Bart
  • 19,692
  • 7
  • 68
  • 77
Atef Ramadan
  • 105
  • 8
  • 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? – László Papp Apr 18 '14 at 04: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. – Atef Ramadan Apr 18 '14 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. – László Papp Apr 19 '14 at 03:06
  • thanks Laszlo i have fixed this by rebuilding the QT mysql driver. – Atef Ramadan Apr 19 '14 at 03:17

1 Answers1

0

Try to rebuild the SQL driver .

QMYSQL3 seems to be old.

László Papp
  • 51,870
  • 39
  • 111
  • 135