I have total 4 records in ecare table, where 2 records
status is sent = 1, and other 2 records status is
I have tried to re-create your database, is this right, what is the problem, seems to work.
CREATE TABLE ecare (_id INTEGER PRIMARY KEY,h_id INTEGER ,no INTEGER);
CREATE TABLE pweb (_id INTEGER PRIMARY KEY,h_id INTEGER ,sent INTEGER);
sqlite> insert into ecare values(1, 10,1);
sqlite> insert into ecare values(2, 20,2);
sqlite> insert into ecare values(3, 30,3);
sqlite> insert into ecare values(4, 40,4);
sqlite>
sqlite> insert into pweb values(1, 10,1);
sqlite> insert into pweb values(2, 20,1);
sqlite> insert into pweb values(3, 30,0);
sqlite> insert into pweb values(4, 40,0);
sqlite> select * from ecare;
1|10|1
2|20|2
3|30|3
4|40|4
sqlite> select * from pweb;
1|10|1
2|20|1
3|30|0
4|40|0
sqlite> SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0';
0|3|30|3|3
0|4|40|4|4
sqlite>
Your missing startManagingCursor()
method.
Cursor cursor = db.rawQuery(sql, null);
cursor.getCount();
startManagingCursor(cursor);//the important line
cursor.moveToFirst();
if(cursor.getCount() == 0)
{
//error no records
}
else
{
for(int i=0;i<cursor.getCount();i++)
{
records.add(cursor.getString(0));
adapter.add(aString);
cursor.moveToNext();
}
cursor.moveToFirst();
}
NOTE:
startManagingCursor()
is deprecated because it does operations on the main thread which can freeze up the UI and deliver a poor user experience. You should use a CursorLoader
with a LoaderManager
instead.
I would try:
String sql = "SELECT p.sent,e.*, e.no _id
FROM ecare e, pweb p
WHERE e.h_id=p.h_id
AND e.sent = '0' ";