Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
wekncdr
Posts: 9
Registered: ‎09-28-2012
My Device: Developer

sql prepared statement with percentage

Hi all, I would like to execute this query with a percentage sign in it:

 

SELECT name FROM fruits WHERE name LIKE "app%'

In C++, I implemented the prepared statement like this:

 

QString q("SELECT name FROM fruits WHERE name LIKE ':name%'");
QVariantMap bindings;
bindings[":name"] = QString("%1").arg(input); // input = "app"
sqldataaccess->execute(q, bindings);

But during runtime, SqlDataAccess fails with:

 

 / Parameter count mismatch

 I also tried to implement it like this:

 

QString q("SELECT name FROM fruits WHERE name LIKE ?");
QVariantList bindings;
bindings << "'"+input+"%'"; // input = "app"
sqldataaccess->execute(q, bindings);

But SqlDataAccess returned zero results. It should be correctly returning some rows.

 

Does anyone have a clue how to implement this kind of prepared statement?

Developer
scrudrv
Posts: 46
Registered: ‎11-23-2010
My Device: Q10

Re: sql prepared statement with percentage

This one should work:

 

QString q("SELECT name FROM fruits WHERE name LIKE :name");
QVariantMap bindings;
bindings[":name"] = QString("%1").arg(input+"%");
sqldataaccess->execute(q, bindings);

 As you can see I removed single quotes and percentage in sql string and added percentage in the bindings.

 

ps: I understand its quite a late reply, but I just was doing same "percentage" thing in my project, thought it might be usefull for someone else.