0

Maybe this is a simple problem, but I am just not seeing it :)

In my database, I have two fields named NoRide and NoAttempt.

In one row I have NoRide = 40 and NoAttempt = 40.

I have no issues when I query directly in the database using:

SELECT * FROM MyTable WHERE NoRide = NoAttempt

However in Android, I wrap this exact line in a rawQuery statement, and I get no results. Similarly if I do things like

rawQuery("SELECT * FROM MyTable WHERE NoRide - NoAttempt != '0'", null);

I also get no data, when this query works fine in the database query.

Is there something different with rawQuery in android that I am missing?

4
  • i think its gives error when you try to print data using Cursor.. Apr 1, 2012 at 16:30
  • How so exactly? I'm not getting any errors, just no values.
    – ADK
    Apr 1, 2012 at 17:00
  • How are you determining that you get no results?
    – Barak
    Apr 1, 2012 at 17:14
  • If I change the equation to say "SELECT * FROM MyTable WHERE NoRide = '40'" I am successfully pulling the cursor count as 1. The same if I substitute NoAttempt = '40', so I know both have the proper data.
    – ADK
    Apr 1, 2012 at 17:28

2 Answers 2

1

I don't know what's happening with the first part of your question (NoRide=NoAttempt), but I have an idea about the second issue.

Try removing the single quote from the 0... the database probably thinks you're trying to compare an int to a string. Lise so:

rawQuery("SELECT * FROM MyTable WHERE NoRide - NoAttempt != 0", null); 
1
  • Bingo, actually that did it, and I use that to achieve the same result.
    – ADK
    Apr 1, 2012 at 21:16
0

Try this

rawQuery("SELECT NoRide, NoAttempt FROM MyTable 
WHERE IFNULL(NoRide,0) - IFNULL(NoAttempt,0) <> 0", NULL);
1
  • No dice...same result (0 value).
    – ADK
    Apr 1, 2012 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.