我正在尝试通过添加 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。为什么我的代码没有更新任何东西?