【发布时间】:2015-08-12 05:19:31
【问题描述】:
有没有办法改变我的功能:
public categorie createCategoria(String categoria) {
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_NOME, categoria);
values.put(MySQLiteHelper.COLUMN_PREF, 0);
long insertId = database.insert(MySQLiteHelper.TABLE_CATEGORIE, null,
values);
Cursor cursor = database.query(MySQLiteHelper.TABLE_CATEGORIE,
allCategorieColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
categorie newCategoria = cursorToCategorie(cursor);
cursor.close();
return newCategoria;
}
这是一个原始插入,我想更改此函数以使其相应更新或插入。我想更改它,因为我已经在某些地方使用了此功能,但现在我需要选择是插入一行还是更新(或忽略插入)具有相同 COLUMN_NOME 的行。有人可以帮我做这个吗?
我的意思是,只有在没有另一个同名的行时,我才想插入一个新行(就像往常一样,你知道)。
【问题讨论】: