SQLite Android内连接
发布时间:2020-12-12 18:53:40 所属栏目:百科 来源:网络整理
导读:我有一个奇怪的问题.我从服务器获取数据并将其插入表中.插入后,我使用两个表之间的内部联接查询该数据. 这是我的查询: 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
我有一个奇怪的问题.我从服务器获取数据并将其插入表中.插入后,我使用两个表之间的内部联接查询该数据.
这是我的查询: 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. 解决方法
这种问题很难解释,因为它很可能不会抛出任何错误,只会显示不同的和不需要的结果. 您所能做的就是“改进查询”: 首先使用占位符而不是原始语句: 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()的用法). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |