• 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
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.
 
This is the weirdest thing programmer can encounter:
this was working previously, but I went a few weeks without working with it and now it just doesn't work anymore.
What is the table structure? Does it have id, is it an autoincrement, is it a primary key?
 
It did, yes.

It turns out I redid the entire database. It works now, but I have no idea what happened to my previous code. Hopefully it will keep working.

Thanks anyway.
 
You're welcome!
By the way, do you have any idea about how to use MySQL db in Android, but with ease of SQLite (flat file, no server to connect)? Because I prefer MySQL syntax.
 
Back
Top Bottom