SQLite Android Inner join

I have one strange problem. I retrieve data from the server and paste it into tables. After insertion, I query this data using an internal join between two tables. here is my request:

Select 
    F._id, F.id, F.logo, F.total_like, F.distance, F.store_name, F.mob_no_1,
    F.mob_no_2, F.mob_no_3, F.tel_no_1, F.tel_no_2, F.tel_no_3, F.description,
    R.total_record, R.total_page, R.current_page 
from 
    FAVOURITE_STORES as F 
    INNER JOIN FAVOURITE_RECORDS as R on F.area_id = R.area_id 
where 
    F.area_id = 2 and 
    R.area_id = 2

I get the number of cursors as 1 on some devices, and on some devices I get the cursor count as zero. Even if the data is in the table.

here is my query select function

public Cursor rawQuery(String sQuery,String[] selectionArgs) {
        if(mDatabase == null) {
            mDatabase = getWritableDatabase();
        }
        debug("Query "+sQuery);
        return mDatabase.rawQuery(sQuery,selectionArgs);
    }

Cursor class

public class ExampleCursorLoader extends CursorLoader {
    private Activity mActivity;
    private String msQuery;
    private DBUtil mDbUtil;
    private String[] mSelectionArgs;

    public ExampleCursorLoader(Activity context, String query,String[] selectionArgs) {
        super(context);
        this.mActivity = context;
        this.msQuery = query;
        this.mSelectionArgs = selectionArgs;
        this.mDbUtil = DBUtil.getInstance(mActivity.getApplicationContext());
    }

    public ExampleCursorLoader(Activity context, String query) {
        this(context,query,null);
        debug(query);
    }
    public Cursor loadInBackground() {  
        debug("Loading in Background");
        Cursor cursor=null;
        cursor = mDbUtil.rawQuery(msQuery,mSelectionArgs);
        return cursor;
    }

    private void debug(String s) {
        Log.v("Adapter " , "Adapter " + s);
    }

    protected void onStartLoading() {
        forceLoad();
        debug("Started Loading");
    }

    protected void onStopLoading() {
        super.onStopLoading();
    }


}

and so I call him.

return new ExampleCursorLoader(mActivity,sQuery);

The device that counts 1 is Samsung s3. And zero - Samsung Grand. Are there any thoughts or suggestions on this?

+4
source share
2 answers

, 1, - Samsung s3. - Samsung Grand. - ?

, , , , .

, , " ":

, :

String query = "... where F.area_id = ? and R.area_id = ?";
String[] whereArgs = {"2", "2"};

AS, :

... from FAVOURITE_STORES F INNER JOIN FAVOURITE_RECORDS R on ...

, , ( rawQuery()).

+1

, WHERE :

 and R.area_id=2

FAVOURITE_STORES area_id = 2. INNER JOIN , FAVOURITE_RECORDS, area_id area_id FAVOURITE_STORES.

, SQLite-, .

0

Source: https://habr.com/ru/post/1537068/


All Articles