QSqlQuery and prepare/bindValue problem!
Hey all, I'm having a problem, using this:
Code:
QString SQL
("UPDATE mercaderias SET :1 = :4 WHERE Nombre=:3 AND Proveedor=:4");
switch(uno.column()) {
case 0:
columna="Nombre";
break;
case 1:
columna="Proveedor";
break;
case 2:
columna="Cantidad";
break;
case 3:
columna="Precio";
break;
}
peticion.prepare(SQL);
peticion.bindValue(":1",columna);
peticion.bindValue(":2",uno.data().toString());
peticion.bindValue(":3",ui->Tabla->model()->index(uno.row(),0).data().toString());
peticion.bindValue(":4",ui->Tabla->model()->index(uno.row(),2).data().toString());
if ( !peticion.exec() ) {
qDebug() << "Error al actualizar";
qDebug() << peticion.executedQuery();
qDebug() << peticion.lastError().text();
}
peticion.executedQuery() returns the values inside quotes (like 'value') instead of them being raw. What can I do to fix this?
Re: QSqlQuery and prepare/bindValue problem!
Don't convert them to strings with QVariant::toString(). All you are doing is converting the original QVariant returned by the data() method (with whatever type it contains) to a QString and then back to a QVariant with a string type.
Re: QSqlQuery and prepare/bindValue problem!
Line 19, using the QString directly, does not work not even if converted to a c_str()
Further ideas? Since the information is good, but does not solve the actual problem.
Re: QSqlQuery and prepare/bindValue problem!
Quote:
Line 19, using the QString directly, does not work not even if converted to a c_str()
And "does not work" means what, exactly? Won't compile? Creates malformed SQL? Doesn't return results when the query is executed?
Sort of hard to know what's going on when we aren't looking over your shoulder at your PC and you give vague replies.
There is no QString::c_str() method, so I don't know what you mean by this.