数据未插入SqLite数据库中,但行数增加

时间:2018-07-31 05:37:14

标签: android android-sqlite auto-increment

当我尝试在sqlite表中插入数据时,插入的数据没有插入,但主键增加,行数也增加。不知道确切的问题是什么。请有人帮助解决问题。我将在此处添加我的代码。请有人帮我

我在这里添加到数据库

  mylistDataBaseModel = new MyListDataBaseModel();

                mylistDataBaseModel.setItemId(0);
                mylistDataBaseModel.setItemName("");
                mylistDataBaseModel.setItemPrice(0.0);
                mylistDataBaseModel.setItemGst(0.0);
                mylistDataBaseModel.setCategoryId(0);
                mylistDataBaseModel.setItemCategoryName("");
                mylistDataBaseModel.setItemPicture("");
                mylistDataBaseModel.setItemcount(0);
                mylistDataBaseModel.setListName(createList.getText().toString().trim());
                mylistDataBaseModel.setListItemcount(0);
                mylistDataBaseModel.setItemisAdded(0);

             //   Log.d("==============", "====" + createList.getText().toString().trim());
                 sqLiteDatabase = sqlLiteController.getWritableDatabase();
                  SqliteController.addMyListNameToDataBase(sqLiteDatabase, mylistDataBaseModel);
                 sqlLiteController.close();

数据库中的名称是

public static void addMyListNameToDataBase(SQLiteDatabase sqLiteDatabase, MyListDataBaseModel model) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN__ITEM_ID, model.getItemId());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_NAME, model.getItemName());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_PRICE, model.getItemPrice());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_GST, model.getItemGst());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM__CATEGORY_ID, model.getCategoryId());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_CATEGORY_DESCRIPTION, model.getItemCategoryName());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_PICTURE, model.getItemPicture());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_COUNT_ID, model.getItemcount());
    Log.d("==============", "====" + model.getListName());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_MY_LIST_NAME, model.getListName());

    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_MY_LIST_COUNT, model.getListItemcount());
    contentValues.put(SqliteItemsDataBase.NewUSerInfo.COLUMN_ITEM_IS_ADDED, model.getItemisAdded());


    sqLiteDatabase.insert(SqliteItemsDataBase.NewUSerInfo.MYLIST_TABLE, null, contentValues);
    System.out.println("Cart Summary one row has been inserted");
    UserNotification.notify(Constants.NOTIFICATION_MY_LIST_ITEM_ADDED, null);

}

这是我从表格方法获取数据

 public static ArrayList<MyListDataBaseModel> getMyListData(SQLiteDatabase db) {
    ArrayList<MyListDataBaseModel> allMyLists = new ArrayList<>();

    Cursor cursor = db.rawQuery("select * from " + SqliteItemsDataBase.NewUSerInfo.MYLIST_TABLE, null);
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {

                int localId = cursor.getInt(0);
                Log.d("list","====localId====="+localId);
                int itemId = cursor.getInt(1);
                Log.d("list","====itemId====="+itemId);
                String itemName = cursor.getString(2);
                Log.d("list","====itemName====="+itemName);
                Double itemPrice = cursor.getDouble(3);
                Log.d("list","====itemPrice====="+itemPrice);
                Double itemGst = cursor.getDouble(4);
                Log.d("list","====itemGst====="+itemGst);
                int categoryId = cursor.getInt(5);
                Log.d("list","====categoryId====="+categoryId);
                String catName = cursor.getString(6);
                Log.d("list","====catName====="+catName);
                String itemPicture = cursor.getString(7);
                Log.d("list","====itemPicture====="+itemPicture);
                int itemsCount = cursor.getInt(8);
                Log.d("list","====itemsCount====="+itemsCount);
                String listName = cursor.getString(9);
                Log.d("list","====listName====="+listName);
                int listItemCount = cursor.getInt(10);
                Log.d("list","====listItemCount====="+listItemCount);
                int itemIsAdded = cursor.getInt(11);
                Log.d("list","====itemIsAdded====="+itemIsAdded);


                allMyLists.add(new MyListDataBaseModel(localId, itemId, itemName, itemPrice,
                        itemGst, categoryId, catName, itemPicture, itemsCount, listName, listItemCount, itemIsAdded));

            } while (cursor.moveToNext());
        }
    }
    cursor.close();
    return allMyLists;
}

1 个答案:

答案 0 :(得分:0)

我犯了一个错误,我得到的数据带有其他一些列ID而不是受尊重的列ID。那是我的错误