0

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?

3
  • 2
    Is the leading space in ' "+(facedWords.get(i)).trim()+"' on purpose? It seems wrong... Commented Aug 12, 2013 at 7:17
  • @Heuster: Great! This is it! Thank you! Since you found the issue first, I would like to mark your answer as the answer. Please be kind enough to provide your answer as an Answer Commented Aug 12, 2013 at 7:21
  • 2
    Tnx, but just mark the other answer as accepted. It's not a competition :) Commented Aug 12, 2013 at 7:23

1 Answer 1

3

I think you have extra "space" in your where clause :

where EnglishWord = ' "+(facedWords.get(i)).trim()+"'"

so replace it with :

where EnglishWord = '"+(facedWords.get(i)).trim()+"'"
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, Thanks a lot for the answer. It works! I already gave you a +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.