Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

SQLite SELECT with IN condition, arguments

Hey community, i have encountered an error and tried many solutions but none of them worked.

Problem: i would like to create an sqlite query selecting records which are selected by the in condition. I can give random number of arguments (1-6), and i solved that but the question marks don't get replaced by the arguments. Can you help?

Code: String[] argsArray = {"1","2","3","4","5","6"};

Cursor cursor = mDatabase.rawQuery("SELECT * FROM "+ RangeSQLiteHelper.RANGES_TABLE + " WHERE "+ RangeSQLiteHelper.COLUMN_POSITION_ID + " IN (" +makePlaceholders(pos.size()) +") ORDER BY RANDOM() LIMIT 1", argsArray);

malePlaceholders makes this -> ?,?,?,?,?,?

this is the SQLiteDirectCursorDriver: SELECT * FROM RANGES WHERE POSITION_ID IN (?,?,?,?,?,?) ORDER BY RANDOM() LIMIT 1