Question

I am trying to insert the data into database, all the fields are getting inserted apart from product_full_node.But when i am doing in update everything is getting updated. My situation is little weird.

I have a table with following columns:

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);";

This is my insert query :

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;
}

This is my update:

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;
}
Was it helpful?

Solution

Change

contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, "productJsonResponse");

to

contentValues.put(DatabaseHandler.PRODUCT_FULL_NODE, productJsonResponse);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top