• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Simple SQLite insertion operation not working

theJuls

Lurker
Apr 17, 2014
3
0
I know this is a very very very basic question, but I am losing my mind with this!

It is as simple as the title of the thread: for some reason I am not able to insert entries in the database. For the record, this was working previously, but I went a few weeks without working with it and now it just doesn't work anymore.

Here is the code where I insert the new row:
Code:
//this is the code where I try to insert the data

    dbAdapter.open();
    dbAdapter.EnterCreateHistory(DatabaseAdapter.WALKER_HISTORY_TABLE, "fdfsf", "fdfsf1", "fdfsf", "fdfsf", "fdfsf");
    dbAdapter.EnterCreateHistory(DatabaseAdapter.WALKER_HISTORY_TABLE, "fdfsf1", "fdfsf2", "fdfsf1", "fdfsf1", "fdfsf1");
    dbAdapter.EnterCreateHistory(DatabaseAdapter.WALKER_HISTORY_TABLE, "fdfsf1", "fdfsf3", "fdfsf1", "fdfsf1", "fdfsf1");
    dbAdapter.EnterCreateHistory(DatabaseAdapter.WALKER_HISTORY_TABLE, "fdfsf1", "fdfsf4", "fdfsf1", "fdfsf1", "fdfsf1");
    dbAdapter.EnterCreateHistory(DatabaseAdapter.WALKER_HISTORY_TABLE, "fdfsf1", "fdfsf5", "fdfsf1", "fdfsf1", "fdfsf1");

    Cursor walkerHistory = dbAdapter.getAllData(DatabaseAdapter.WALKER_HISTORY_TABLE);
 //here I check if the data is being inserted, 
//but the number of columns always comes back as 0
    Toast.makeText(getApplicationContext(), "Number of rows inserted:  "+walkerHistory.getCount(), Toast.LENGTH_SHORT).show();

Now here is the code inside my DatabaseAdapter to insert the new row:

Code:
public void EnterCreateHistory(String tableName, String recommendationDate, String recommendation, String activityDate, String activity, String analyses){
    ContentValues values= new ContentValues();

    values.put(RECOMMENDATION_DATE,recommendationDate);
    values.put(RECOMMENDATION,recommendation);
    values.put(ACTIVITY_DATE,activityDate);
    values.put(ACTIVITY, activity);
    values.put(MONITOR,analyses);

    long rowid=db.insert(tableName, null, values);
    rowid1=rowid;
    Log.d(TAG, "IDD"+rowid1);

}

The thing is, I am not getting any exceptions or anything. It's just that my number of inserted rows always comes out as 0.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones