I am trying to update an 'integer' fields in SQLite database by adding 1 to it. So it is X = X+1
Following is my code
public synchronized void updateStatistics(List<String> correctWords,
List<String> facedWords, int wordListNumber, boolean flag) {
// TODO Auto-generated method stub
String[] tableLastNames= {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String tableName = "WordList_"+tableLastNames[wordListNumber];
if(flag)
{
//First update 'FacedWords' row
Toast.makeText(context, "Faced Words Length: "+facedWords.size(), Toast.LENGTH_LONG).show();
Toast.makeText(context, "Correct Words Length: "+correctWords.size(), Toast.LENGTH_LONG).show();
try
{
for(int i=0;i<facedWords.size();i++)
{
String query = "update "+ tableName+" set NumberOfTimesEnglishWordShowed=NumberOfTimesEnglishWordShowed+1 where EnglishWord = ' "+(facedWords.get(i)).trim()+"'";
database.execSQL(query);
}
for(int i=0;i<correctWords.size();i++)
{
String query = "update "+ tableName+" set NumberOfTimesEnglishWordCorrected=NumberOfTimesEnglishWordCorrected+1 where EnglishWord = ' "+(facedWords.get(i)).trim()+"'";
database.execSQL(query);
}
//Toast.makeText(context, "Updated Word: "+, duration)
}
catch(Exception e)
{
Toast.makeText(context, "Update error", Toast.LENGTH_LONG).show();
}
}
}
I am using SQLite database browser to see the things in my database, and I noticed the above code has updated nothing! There is no error as well! In case you need, following is the required part from the table
String createDatabaseQuery = "create table WordList_A(" +
"ID integer primary key autoincrement,"
+"NumberOfTimesEnglishWordShowed integer,"
+"NumberOfTimesEnglishWordCorrected integer,");";
The update query I used is similar to the MS SQL update query, so I am not sure whether that way is working with SQLite. Why my code is not updating anything?
' "+(facedWords.get(i)).trim()+"'on purpose? It seems wrong...