我有一个奇怪的问题.我从服务器获取数据并将其插入表中.插入后,我使用两个表之间的内部联接查询该数据.
@H_301_7@这是我的查询:
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
我在某些设备上将光标计数设置为1,在某些设备上,我将光标计数设置为零.即使表格中有数据.
public Cursor rawQuery(String sQuery,String[] selectionArgs) { if(mDatabase == null) { mDatabase = getWritableDatabase(); } debug("Query "+sQuery); return mDatabase.rawQuery(sQuery,selectionArgs); }
游标类
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(); } }
这就是我所说的.
return new ExampleCursorLoader(mActivity,sQuery);
计数为1的设备是三星s3.三星是Grand.@H_301_7@有什么想法或建议吗?
解决方法
Device that gives count as 1 is Samsung s3. And zero is Samsung Grand.@H_301_7@ Have any thought or suggestion on this?
这种问题很难解释,因为它很可能不会抛出任何错误,只会显示不同的和不需要的结果.
您所能做的就是“改进查询”:
首先使用占位符而不是原始语句:
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 ...