我正在尝试将数据插入数据库,所有字段都将从product_full_node
开始插入。但是当我在更新时,所有内容都会更新。我的情况有点奇怪。
我有一个包含以下列的表:
Primary Key (Auto Incremented ) , nid , product_name, product_belongs_category,
product_status, product_rating, product_full_node,
private static final String CREATE_PRODUCT_DETAILS_TABLE = "CREATE TABLE "
+ PRODUCT_DETAILS_TABLE
+ "("
+ _NID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ PTID
+ " INTEGER ,"
+ NID
+ " INTEGER NOT NULL UNIQUE, "
+ PRODUCT_NAME
+ " TEXT, "
+ PRODUCT_BELONGS_CATEGORY
+ " TEXT, "
+ PRODUCT_STATUS
+ " INTEGER, "
+ PRODUCT_RATING
+ " INTEGER, "
+ PRODUCT_FULL_NODE + " TEXT);";
这是我的插入查询:
public long insertProductDetailsData(String nid, String tid,
String productName, String productBelongsCategory,
Integer productRating, String productJsonResponse,
String publishedStatus) {
SQLiteDatabase sqliteDB = dbHandler.getWritableDatabase();
ContentValues contentValues = new ContentValues();
Integer tidInteger = Integer.valueOf(tid);
Integer nidInteger = Integer.valueOf(nid);
Integer publishedStatusInteger = Integer.valueOf(publishedStatus);
contentValues.put(DatabaseHandler.PTID, tidInteger);
contentValues.put(DatabaseHandler.NID, nidInteger);
contentValues.put(DatabaseHandler.PRODUCT_NAME, productName);
contentValues.put(DatabaseHandler.PRODUCT_BELONGS_CATEGORY,
productBelongsCategory);
contentValues.put(DatabaseHandler.PRODUCT_STATUS,
publishedStatusInteger);
contentValues.put(DatabaseHandler.PRODUCT_RATING, productRating);
contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE,
"productJsonResponse");
long id = 0;
try {
id = sqliteDB.insert(DatabaseHandler.PRODUCT_DETAILS_TABLE, null,
contentValues);
dbHandler.close();
} catch (Exception e) {
e.printStackTrace();
}
return id;
}
public int updateProductDetailsData(String nid, String tid,
String productName, String productBelongsCategory,
Integer productRating, String productJsonResponse,
String publishedStatus) {
SQLiteDatabase sqliteDB = dbHandler.getWritableDatabase();
ContentValues contentValues = new ContentValues();
Integer tidInteger = Integer.valueOf(tid);
Integer publishedStatusInteger = Integer.valueOf(publishedStatus);
contentValues.put(DatabaseHandler.PTID, tidInteger);
contentValues.put(DatabaseHandler.PRODUCT_NAME, productName);
contentValues.put(DatabaseHandler.PRODUCT_BELONGS_CATEGORY,
productBelongsCategory);
contentValues.put(DatabaseHandler.PRODUCT_RATING, productRating);
contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE,
productJsonResponse);
contentValues.put(DatabaseHandler.PRODUCT_STATUS,
publishedStatusInteger);
String[] condition = { nid };
int id = sqliteDB.update(DatabaseHandler.PRODUCT_DETAILS_TABLE,
contentValues, DatabaseHandler.NID + " =? ", condition);
dbHandler.close();
return id;
}
答案 0 :(得分:1)
更改
contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, "productJsonResponse");
到
contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, productJsonResponse);