Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSqlError trying to insert a QByteArray in a postgres DB



  • Hello there,

    when trying the above I'm getting the following error:
    QSqlError("42601", "QPSQL: Unable to create query", "ERROR: syntax error at end of input\nLINE 1: EXECUTE \n ^\n(42601)")

                    db.transaction();
    		QSqlQuery query(db);
    		query.prepare("UPDATE "+par->get_name()+" SET ausgabe_name=':name_out', ausgabe_datei=':f_out' WHERE experimentid=':exp_id'");
    		query.bindValue(":name_out",output);
    		query.bindValue(":f_out",output_byte_array);
    		query.bindValue(":exp_id", ui->lineEdit_experiment_id->text());
    		query.exec();
    		qDebug()<<query.lastError();
    		db.commit();
    

    Thanks in advance



  • Figured it out. the ' around the placeholders were the problem so this seems to work:

                    db.transaction();
    		QSqlQuery query(db);
    		query.prepare("UPDATE "+par->get_name()+" SET ausgabe_name=:name_out, ausgabe_datei=:f_out WHERE experimentid=:exp_id");
    		query.bindValue(":name_out",output);
    		query.bindValue(":f_out",output_byte_array);
    		query.bindValue(":exp_id", ui->lineEdit_experiment_id->text());
    		query.exec();
    		qDebug()<<query.lastError();
    		db.commit();
    

Log in to reply