Reputation: 61
I managed to bound integer values to this type of queries but I couldn't manage to bound QString.
I keep getting empty QVariant. However, in Sql server I get the value I wanted to get.
The procedure will output VARCHAR(max)
qDebug() << query.prepare("{call dbo.p_test(?)}");
query.bindValue(0, QString(""), QSql::Out);
qDebug() << query.exec();
qDebug() << query.boundValue(0);
I have tried binding:
''
""
QString()
QString("")
QVariant()
QVariant(QVariant::String)
How I should bind the value to be able to bound correctly?
I am using Qt 4.8.4
P.S. When doing it this way I can get the string value I wanted.
query.exec("DECLARE @r VARCHAR(MAX); EXEC dbo.p_test @r OUTPUT; SELECT @r");
query.first();
qDebug()<<query.value(0);
updates
Here how it gets really weirdo
QSql::Out
to QSql::InOut
.query.bindValue(0, QString("1234567"), QSql::InOut);
I checked for the value I had passed in sql server and it was
'1234567'
I checked the value I got from qDebug()<<query.boundValue(0)
and it was
QVariant(QString, "1234")
no matter that my procedure should return
'7654321'
CREATE PROCEDURE dbo.p_test
@rez varchar(max)
BEGIN
INSERT INTO test VALUES(@rez)
SET @rez = '7654321';
END;
Upvotes: 2
Views: 877
Reputation: 61
As mentioned in the comments
This bug is present in Qt4 and is fixed in Qt5 (hence my question): bugreports.qt.io/browse/QTBUG-18435 – jbh Mar 27 at 9:54
it is really a bug, no way to get around it in Qt4.
Qt4 is too buggy, I have found another 3 bugs today -_- unlucky me.
Upvotes: 1
Reputation: 4592
I think you have to properly format the output,
qDebug() << query.boundValue(0).toString();
or:
qDebug() << query.boundValue(0).toString().toUtf8().data();
if you have more than bounded values, then you can use QSqlQuery::boundValues()
with a list:
list.at(i).toString().toUtf8().data()
Upvotes: 1