Reputation: 1064
I am trying to insert a character into a column of a table. Instead, the decimal code of the character is inserted. How can I insert the character?
Details:
QString insertSql;
insertSql
.append("INSERT INTO ")
.append(" table ")
.append(" (direction) ")
.append("VALUES (?)");
QSqlQuery update;
update.prepare(insertSql);
update.bindValue(0, 'F');
bool ex = update.exec();
qDebug() << update.lastError().type() << endl;
qDebug() << update.lastError().databaseText() << endl;
qDebug() << update.lastError().driverText() << endl;
If the direction attribute in the table is varchar, I get string '70' (decimal code of the character) inserted, if the attribute 'char' is then an error is produced, that the type is too short to store the value.
Ideas?
Upvotes: 1
Views: 363
Reputation: 2917
In the call to bindValue
, the second argument is a QVariant, but QVariant doesn't have a constructor accepting a char. Your char probably is converted to an int as this is a standard conversion, and not QChar. Your QVariant is an integer type and converted to a string during bindValue
.
You can try explicitly using QChar :
update.bindValue(0, QChar('F'));
Upvotes: 2