Java编组参数计数不匹配,参数计数不匹配

I am using quite a lot of parameterized queries in my code for performance reasons. In short, some of them work, some don't.

I initialize the query during construction of my database wrapper like this:

QString querystring = QString("SELECT somevalue FROM sometable "

"WHERE one_feature = :one_feature AND other_feature = :other_feature ");

myquery = QSqlQuery(db);

myquery.setForwardOnly(true);

myquery.prepare(querystring);

myquery is a QSqlQuery member variable of my database wrapper. Later on, in the function that wants to use this query, I do something like

int db_wrapper::fetch_some_value (int arg1, int arg2) {

myquery.clear();

myquery.bindValue(":one_feature", arg1);

myquery.bindValue(":other_feature", arg2);

qDebug() << "Bound values: " << myquery.boundValues();

bool OK = myquery.exec();

if (!OK) {

int number = myquery.lastError().number();

qDebug() << "db error " << number;

qDebug() << "db error " << myquery.lastError().text();

#ifdef USE_EXCEPTIONS

throw "Could not fetch some_value!";

#endif

}

// process data...

}

I always get the same error message/output:

Bound values: QMap((":one_feature", QVariant(int, 1) ) ( ":other_feature" , QVariant(int, 1) ) )

db error -1

db error " Parameter count mismatch"

terminate called after throwing an instance of 'char const*'

The exception is not surprising, but the parameter count mismatch is. The call to boundValues actually shows the right values and all, still I get this error message. I have similar queries that work just fine.

I tried substituting positional bind values, renamed the placeholders, used ? and positional bind values, all to no avail. Does anyone have an idea what the problem might be?

I use Qt 4.7.3 and SQLite 3.7.4-2

解决方案

Usually this error means that the SELECT/UPDATE query itself is incorrect. You did not give the schema of the database so it's not possible to pinpoint which one. So one or more of somevalue, sometable, one_feature, or second_feature is not in the database/table.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值