- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我不熟悉 Sqlite,因此正在使用数据库库 SugarORM,其文档位于 http://satyan.github.io/sugar/creation.html
它的大部分功能与sqlite中的相同,但使用更简单的命令。
public class ExerciseDB extends SugarRecord
{
@Column(name = "ex_recordId", unique = true, notNull = true)
private String ex_recordId;
private String ex_group;
private String ex_name;
private int ex_cal;
public ExerciseDB()
{
}
public ExerciseDB(String ex_recordId, String ex_group, String ex_name, int ex_cal)
{
this.ex_recordId = ex_recordId;
this.ex_group = ex_group;
this.ex_name = ex_name;
this.ex_cal = ex_cal;
}
ExerciseDB e0001= new ExerciseDB("ex0001", "Sports", "AAA", 190); save(e0001);
ExerciseDB e0002= new ExerciseDB("ex0002", "Sports", "BBB", 190); save(e0002);
请问如何查找“ex0001”记录?我尝试使用以下代码进行搜索:
ExerciseDB.find(ExerciseDB.class, key);
List<ExerciseDB> books = ExerciseDB.find(ExerciseDB.class, "ex_recordId = ?", key, null,null,null);
String gg = books.get(1).get_ex_group();
但是它报告
android.database.sqlite.SQLiteException: no such column: ex0001 (code 1): , while compiling: SELECT * FROM Ex_Records WHERE ex0001
List<Book> books = Book.find(Book.class, "author = ?", new String{author.getId()});
和
Book book = Book.findById(Books.class, 1);
Author author = book.author;
但不知道这个1
代表什么以及如何找到
public static <T> List<T> find(Class<T> type, String whereClause, String... whereArgs) {
return find(type, whereClause, whereArgs, null, null, null);
}
public static <T> List<T> find(Class<T> type, String whereClause, String[] whereArgs, String groupBy, String orderBy, String limit) {
SugarDb db = getSugarContext().getSugarDb();
SQLiteDatabase sqLiteDatabase = db.getDB();
T entity;
List<T> toRet = new ArrayList<T>();
Cursor c = sqLiteDatabase.query(NamingHelper.toSQLName(type), null, whereClause, whereArgs,
groupBy, null, orderBy, limit);
try {
while (c.moveToNext()) {
entity = type.getDeclaredConstructor().newInstance();
SugarRecord.inflate(c, entity);
toRet.add(entity);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
c.close();
}
return toRet;
}
基础应该和Sqlite差不多。。。有没有人可以根据上面的代码文档提供帮助?非常感谢!
最佳答案
我想您现在可能已经找到了答案,但对于那些遇到这个问题并想知道的人来说。
Sugar 格式化列名:“read”变为“READ”,isRead 变为“IS_READ”。所以你可以使用你的 SugarRecord.find()。您只需要弄清楚 sugar 如何格式化您的列名“ex_recordId”。我认为它将格式化为 EX_RECORD_ID 或 EXRECORD_ID。
关于Android:如何使用 SugarORM 搜索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28010470/
是否有一种编程方式来使用连接表进行选择? 我做了 SugarRecord.findWithQuery(Class, query) 的变通方法,但我很好奇更好的方法 最佳答案 还没有..不过我们应该尽快
我有一个图书类(class): public class Book extends SugarRecord { private String mBookName; private St
我正在使用 SugarORM 来管理好友列表 AndroidManifest.xml Friend.java public cl
在 Android 中有 3 个表扩展了 SugarRecord(SugarOrm Library)1.用户项2.账户项目3.社区项目 每个用户都有一个帐户,和一个表来保存用户的地址、电话、一些社交地
是否可以通过索引从 sugarORM 数据库中获取值?我在他们的文档中找不到这个。 最佳答案 如果你看一下reo ,有一行他们使用 findById 通过其索引获取值。像这样: Book book =
我下载了 SugarORM 源代码以将其用作库模块(因此我可以覆盖应用程序的“attachBaseContext”方法。 我已经看到问题SugarORM and multidex ,问题是我不知道
借助 Android 中的 SugarORM,我在 SQLite 数据库中创建了表。 public class ProjectPhotoData extends SugarRecord { publi
我注意到在 SugarORM 中,对象可以调用 object.save() 即使 save() 实际上并未直接在对象和所有对象中实现在类的顶部声明了注释@Table。 如果对象所做的只是使用注释,那么
我有这门课: public class ProfileData extends SugarRecord { @Expose public Data data; public ProfileData(D
我有一个应用程序,我正在使用 Sugar ORM library v1.5创建数据库。我发布了第一个版本的应用程序,现在我想向数据库添加另一个表,我在以前的版本上安装了新版本但它崩溃了。这是我遇到的错
我们可以在 SugarORM 网站上阅读 Note: Record indexes start at index 1. 和 Load Entity: Book book = Book.findById
我有一个扩展 SugarRecord 的对象,如下所示: public class SavedDraft extends SugarRecord { private String name; priv
我正在为我的 Android 应用程序使用 SugarORM。在我的项目中,我有几个表,我想知道是否有办法将它们连接到另一个具有来自多个表的列的类对象中? 如果是,那么示例将非常有帮助。 最佳答案 S
我是第一次使用 SugarORM,我有一个简短的问题。如何将一个实体设置为主键?例如,我需要这样的东西: public class Student{ @PrimaryKey priva
我怎样才能删除 Log.i("Sugar", this.getClass().getSimpleName() + " saved : " + this.id); 在 SugarReco
我正在处理使用 SugarORM 的 Android 项目。现在方法限制增加了很多,我必须激活 multidex 支持。但是现在我遇到了 SugarORM 的问题,它只创建 classes.dex 文
我不熟悉 Sqlite,因此正在使用数据库库 SugarORM,其文档位于 http://satyan.github.io/sugar/creation.html 它的大部分功能与sqlite中的相同
我不明白如何使用 SugarORM 来保存数组列表中的信息。 for (int i =0 ; i ordersGo = new ArrayList<>(); ordersGo.add(ne
我有两个类(class),库存和配方。我遇到的问题是我无法将项目添加到配方表中。我收到以下错误消息: java.lang.IllegalStateException: Caused by: andro
SugarORM ,在我看来,是最容易使用的 SQLite 库,并且被证明对像我这样的初级 Android 开发人员非常有帮助。 SugarORM 自动创建表并为每个扩展 SugarRecord 的
我是一名优秀的程序员,十分优秀!