Qt SQL prepare fails

隐身守侯 提交于 2020-01-02 10:15:28

问题


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?


回答1:


Try to rebuild the SQL driver .

QMYSQL3 seems to be old.



来源:https://stackoverflow.com/questions/23147057/qt-sql-prepare-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!