无法更新SQLite数据库中的Integer字段

时间:2013-08-12 07:13:39

标签: java android database eclipse sqlite

我试图通过向它添加1来更新SQLite数据库中的“整数”字段。所以它是X = X+1

以下是我的代码

  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();
            }

        }



    }

我使用SQLite数据库浏览器查看我的数据库中的内容,我注意到上面的代码没有更新!也没有错误!如果您需要,以下是表格中所需的部分

String createDatabaseQuery = "create table WordList_A(" +
                    "ID integer primary key autoincrement,"
                    +"NumberOfTimesEnglishWordShowed integer,"

                    +"NumberOfTimesEnglishWordCorrected integer,");";

我使用的更新查询类似于MS SQL更新查询,因此我不确定这种方式是否与SQLite一起使用。为什么我的代码没有更新任何内容?

1 个答案:

答案 0 :(得分:3)

我认为你的where子句中有额外的“空格”:

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

所以用以下代替:

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