SQLite Android内连接
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了SQLite Android内连接,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2200字,纯文字阅读大概需要4分钟。
内容图文
我有一个奇怪的问题.我从服务器获取数据并将其插入表中.插入后,我使用两个表之间的内部联接查询该数据.
这是我的查询:
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.
有什么想法或建议吗?
解决方法:
Device that gives count as 1 is Samsung s3. And zero is Samsung Grand.
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 ...
从您提供的代码看起来是正确的(查询和rawQuery()的用法).
内容总结
以上是互联网集市为您收集整理的SQLite Android内连接全部内容,希望文章能够帮你解决SQLite Android内连接所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。