这是我创建的表:
public void onCreate(SQLiteDatabase db) {
String insertNewFormDetails = "create table if not exists " + TABLE_NAME + " ( " + BaseColumns._ID + " integer primary key autoincrement, "
+ NAME + " text not null, "
+ SCHOOL + " text not null, "
+ CURRENTDATE + " text not null, "
+ FORMTYPE + " text not null);";
// Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
db.execSQL(insertNewFormDetails);
}
所以现在这个主键具有自动增量。我如何实际获取该列的内容?
我现在正在为UPDATE
查询做什么。
DBAddForm dbOpener2 = new DBAddForm(this);
SQLiteDatabase sqliteDatabase2 = dbOpener2.getReadableDatabase();
ContentValues contentValues2 = new ContentValues();
String selectQuery = "SELECT * FROM " + "FormDetails";
SQLiteDatabase db = dbOpener2.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
contentValues2.put("school",school);
sqliteDatabase2.update("FormDetails", contentValues2, cursor.getString(0) + " = " +primaryKey , null);
} while (cursor.moveToNext());
}
但是,它现在所做的是更新第一列中的所有行。我只希望它在等于primaryKey
. 请指教?谢谢!我对所有的尝试感到非常困惑。