我正在使用Sugar ORM,它实际上是一个用于SQL数据库操作的库。我的数据库有超过4000条记录,我想从中检索500条记录,比如第501至第1000条记录。
提取500条记录如下:
db_record_listing = Records.findWithQuery(Records.class, "Select * FROM Records ORDER BY recordId ASC WHERE qref_canton BETWEEN '" + s_start + "' AND '" + s_end + "'");
但是,错误logcat如下:
11-25 23:29:35.639: E/AndroidRuntime(28801): Caused by: android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: Select * FROM Records ORDER BY recordId ASC WHERE qref_canton BETWEEN '1' AND '500'
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
11-25 23:29:35.639: E/AndroidRuntime(28801): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
recordId
的那些记录,从而非常慢?如果是的话,是否会有一种更快的方法,系统只会检索那500条记录,而不是更多?答案 0 :(得分:0)
Select * FROM Records WHERE qref_canton BETWEEN '1' AND '500' ORDER BY recordId ASC