hanz hanz - 6 months ago 13
SQL Question

Reading from two tables in android application

I just want to ask about reading data from two tables, the main and the temp table.
the main table is 'translate' and the temp is 'translate2'.

is this lines of code do the job or not?

db = helper.getWritableDatabase();
cursor = db.rawQuery("SELECT LOWER(kata_indo) as kata_indo, LOWER (kata_tora) as kata_tora FROM translate WHERE LOWER(kata_indo) = ?", new String[] {temp[i]});
cursor = db.rawQuery("SELECT LOWER(kata_indo) as kata_indo, LOWER (kata_tora) as kata_tora FROM translate2 WHERE LOWER(kata_indo) = ?", new String[] {temp[i]});
int countRow = cursor.getCount();
cursor.moveToFirst();
String specialChar = "";


thanks in advance for your help

Answer

No, It doesn't. you have filled your cursor twice. Which means the data from translate table will be replaced after running the second rawquery method. So if you want data from both tables you must have two cursors.

 cursor = db.rawQuery("SELECT LOWER(kata_indo) as kata_indo, LOWER (kata_tora) as kata_tora FROM translate WHERE LOWER(kata_indo) = ?", new String[] {temp[i]});
 cursor2 = db.rawQuery("SELECT LOWER(kata_indo) as kata_indo, LOWER (kata_tora) as kata_tora FROM translate2 WHERE LOWER(kata_indo) = ?", new String[] {temp[i]});
Comments