我正在使用个人查询来更新表中的值,在这种情况下,可以增加某些列的值。 例如,我会做类似的事情:
UPDATE statistica SET 1PF = 1PF + ? WHERE id_statistica = ?;
我的代码如下:
String sql = "UPDATE " + StatisticaTable.TABLE_NAME + " SET " + StatisticaTable._1PF + " = " + StatisticaTable._1PF + " + ?, " +
StatisticaTable._1PN + " = " + StatisticaTable._1PN + " + ?, " +
StatisticaTable._2PF + " = " + StatisticaTable._2PF + " + ?, " +
StatisticaTable._2PN + " = " + StatisticaTable._2PN + " + ?, " +
StatisticaTable._3PF + " = " + StatisticaTable._3PF + " + ?, " +
StatisticaTable._3PN + " = " + StatisticaTable._3PN + " + ?, " +
StatisticaTable.RD + " = " + StatisticaTable.RD + " + ?, " + StatisticaTable.RO + " = " + StatisticaTable.RO + " + ?, " +
StatisticaTable.PR + " = " + StatisticaTable.PR + " + ?, " + StatisticaTable.AS + " = " + StatisticaTable.AS + " + ?, " +
StatisticaTable.BK + " = " + StatisticaTable.BK + " + ?, " + StatisticaTable.FS + " = " + StatisticaTable.FS + " + ?, " +
StatisticaTable.PP + " = " + StatisticaTable.PP + " + ?, " + StatisticaTable.FP + " = " + StatisticaTable.FP + " + ? " +
"WHERE " + GiocatoreTable.ID_GIOCATORE + "= ? AND + " + StatisticaTable.ID_PARTITA + "= ?;";
String[] parameter = new String[] {String.valueOf(values.get1pf()), String.valueOf(values.get1pn()), String.valueOf(values.get2pf()), String.valueOf(values.get2pn()),
String.valueOf(values.get3pf()), String.valueOf(values.get3pn()), String.valueOf(values.getRD()), String.valueOf(values.getRO()), String.valueOf(values.getPR()),
String.valueOf(values.getAS()), String.valueOf(values.getBK()), String.valueOf(values.getFS()),
String.valueOf(values.getPP()), String.valueOf(values.getFP()), String.valueOf(values.getIDGiocatore()), String.valueOf(values.getIDPartita())};
_dbHelper.getWritableDatabase().execSQL(sql, parameter);
本质上代码就是这样......但是,尽管参数传递正确并且sql字符串以正确的方式形成,但是不会更新任何东西(使用两个execSQL rawQuery) 我不明白出了什么问题......
答案 0 :(得分:1)
如果你没有得到任何SQL异常,那么你可能应该关注WHERE语句。
"WHERE " + GiocatoreTable.ID_GIOCATORE + "= ? AND + " + StatisticaTable.ID_PARTITA + "= ?;";
SQLite有时会有点棘手,因为它只使用五种基本数据类型。 我注意到如果存储的数据库值和,WHERE语句可能会失败 搜索参数的类型不同。尝试转换ID_GIOCATORE参数 和ID_PARTITA参数到数据库中使用的本机类型。