Android sugar database

  1. 定义了字段,但是select 查询不到该字段,也无法按照该字段排序
could use this func " public static List listAll(Class type, String orderBy) "
Caused by: android.database.sqlite.SQLiteException: no such column: updateTime (code 1): , while compiling: SELECT * FROM DATA ORDER BY updateTime desc
I have been define it,but haven't find this column,but the other could work,such as: dataid.
here is my class:
public class Data extends SugarRecord {
@unique
String dataid;
String userid;
String name;
String phone;
String age;
String isTest;
String creatTime;
String updateTime;
public Data(){}
}

solution:将能select到的字段dataid用timestamp赋值

2.通过 SugarContext.init(this);初始化数据库,
配合AndroidManifest.xml配置如下

<meta-data
    android:name="DATABASE"
    android:value="sugar_xxx.db" /> <!-- 数据库版本。通过数据库的版本决定是否对数据库进行更新 -->
<meta-data
    android:name="VERSION"
    android:value="1" /> <!-- 在处理数据库过程中,是否在Logcat显示日志 -->
<meta-data
    android:name="QUERY_LOG"
    android:value="true" /> <!-- 在操作数据库的类所在的包名 -->
<meta-data
    android:name="DOMAIN_PACKAGE_NAME"
    android:value="com.xxx.sugardatabase" />

获取app的database的路径,但是资源管理器无法访问database的路径,且复制为空失败。
Solution:获取方式,new对象SugarDb,并且获取该context的SQLiteDatabase,拷贝到可访问的地址即可如下;

db=new SugarDb(this);
mydb=db.getDB();
String mydbgetPath=mydb.getPath();
String new_path="/storage/emulated/0/Android/data/com.xxx/sugar_xxx.db";
FileUtils.CopySdcardFile(mydbgetPath,new_path);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值