Luke
Luke

Reputation: 492

Android query vs rawQuery results

When I run either of the queries below with a normal 13 digit barcode a result is returned from my database perfectly fine. However when I run the exact same code with an 8 digit barcode the result is not found in the second query even though it exists in the DB. To me the queries look identical. What could be going wrong?

return mDb.rawQuery("SELECT * FROM `products` WHERE bcode = '"+bcode+"'", null);

return mDb.query(DATABASE_PRODUCT_TABLE,new String[] { KEY_ROWID, KEY_NAME, KEY_BCODE,KEY_USEBY_DAYS}, KEY_BCODE + " = " + bcode, null, null,null, null, null);

Upvotes: 1

Views: 1626

Answers (1)

Philip Sheard
Philip Sheard

Reputation: 5825

Does the 8-digit barcode have leading zeroes, by any chance? Because WHERE clause in the second example is wrong.

Upvotes: 1

Related Questions