我在 Mac OS 10.7.5 上运行 Android Studio。我正在编写查询的应用程序是一个数据库,我一直遇到查询无法正常工作并使用相同的确切查询产生 0 结果的问题。我已经在 Firefox 的 SQLite 管理器中测试了查询,它产生了我正在寻找的结果。
这个问题也不是每次都会发生。我会带着它工作回家,但它不会,反之亦然。为了尝试调试,我硬编码了一个有效的查询,但仍然没有结果。但是,当代码工作时,硬编码查询和我的其他查询方法没有问题。
由于此错误,我尝试更改构建设置以使用 Preferences / Compiler / Use External Build 下的外部构建:
10:56:27 PM Deprecated make implementation
Old implementation of "Make" feature is enabled for this project.
It has been deprecated and will be removed soon.
Please enable newer 'external build' feature in Settings | Compiler.
在事件日志中,这使它工作了一段时间,然后错误返回。我也尝试过更新 Android Studio,它也修复了一次,但问题又回来了。任何帮助或建议将不胜感激。如果您可能需要更多信息,请告诉我。
public class DBAccess extends SQLiteOpenHelper {
private SQLiteDatabase database;
public static String TABLE_PATH = "";
public static final String COLUMN_ROWID = "rowid";
public static final String COLUMN_LASTNAME = "lastname";
public static final String COLUMN_FIRSTNAME = "firstname";
private static final String DATABASE_NAME = "employeedb.sqlite";
private static final String TABLE_EMPLOYEE = "employee";
private static final int DATABASE_VERSION = 1;
// Database creation SQL statement
private static final String DATABASE_CREATE_SQL = "create table "
+ TABLE_EMPLOYEE + "("
+ COLUMN_ROWID + " text, "
+ COLUMN_LASTNAME + " text, "
+ COLUMN_FIRSTNAME + " text"
+ ");";
public DBAccess(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
TABLE_PATH = context.getDatabasePath(Constants.databaseName).toString();
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_CREATE_SQL);
}catch (SQLException e) {}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_EMPLOYEE);
onCreate(db);
}
public void open() throws SQLException {
database = getWritableDatabase();
}
public void close() {
database.close();
}
public ArrayList<Person> searchSQLWithPrefix(String prefix, String[] params) {
ArrayList<Person> results = new ArrayList<Person>();
Cursor cursor = database.rawQuery("SELECT lastname, firstname FROM employee " +
"WHERE UPPER(lastname) like UPPER('Smith') OR UPPER(firstname) like " +
"UPPER('Smith') ORDER BY firstname, lastname LIMIT 1000", null);
//Cursor cursor = database.rawQuery(prefix, params);
if (cursor != null) {
return setPeople(cursor);
}
cursor.close();
return results;
}
public ArrayList<Person> setPeople(Cursor cursor) {
ArrayList<Person> results = new ArrayList<Person>();
Log.e("Test", "Cursor Count: " + cursor.getCount());
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
Person p = new Person( cursor, cursor.getPosition() );
results.add( p );
}
return results;
}
}