0

I'm executing an SQLite query:

String selectQuery = "SELECT hotel.cityName, hotel.hotelName, hotel.roomName, hotel.roomCode, hotel.roomType, hotel.maxPax FROM hotel WHERE ( hotel.cityName = 'Adelaide' OR hotel.cityName = 'Brisbane' OR hotel.cityName = 'Canberra' ) AND hotel.maxPax < 200 AND hotel.maxPax >= 100 AND ( hotel.roomType = 'Boardroom' )"

against a database table called "hotel" created from XML, with the following headings (according to DDMS):

id (INT)
cityName (TEXT)
hotelName (TEXT)
roomCode (TEXT)
roomName (TEXT)
roomType (TEXT)
maxPax (INT)

Each time I run the query:

    SQLiteDatabase db = this.getWritableDatabase ( );
    Cursor cursor = db.rawQuery ( selectQuery, null );

cursor.getCount() returns 0.

I have checked the actual data, and this query should definitely return data. Why does cursor.getCount() return 0?

3 Answers 3

1

Your Java code looks fine, I am guessing the problem is with your SQL. When I have such problems, I often re-create the DB contents in Firefox's SQLite Manager or SQLite Browser and then take the query and start removing things from the WHERE clase until I get results.

Sign up to request clarification or add additional context in comments.

1 Comment

Thx for the help. Managed to get it working using Firefox's SQLite Manager (excellent resource!). It was a stupid typo on my part :(
0

Try to use the 'query' method (Android Developers)

db.query("hotel", null, "(cityName = ? OR cityName = ? OR cityName = ?) AND maxPax < 200 AND maxPax >= 100 AND roomType = ?", new String[] {"Adelaide", "Brisbane", "Canberra", "Boardroom"}, null, null, null);

If it doesn't work, extract the database and test the query.

Comments

0

Try assign your database variable to a SQLiteOpenHelper. I don't really know if a rather arbitrary this would have getWritableDatabase() method.

SQLiteOpenHelper helper = new SQLiteOpenHelper()
SQLiteDatabase db = helper.getWritableDatabase();

2 Comments

Sorry, forgot to put the quotes around the String :( the actual selectQuery does have quotes around it, I'll amend the question.
@user2313303 changed my answer.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.