0

我正在使用个人查询来更新表中的值,在这种情况下增加某些列的值。例如,我会做类似的事情:

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

本质上,代码是这样的......但没有更新任何东西(使用两个execSQL rawQuery),尽管参数传递正确并且sql字符串以正确的方式形成......我不明白什么是错的...... .

4

1 回答 1

1

好吧,如果您没有收到任何 SQL 异常,那么也许您应该关注 WHERE 语句。

"WHERE " + GiocatoreTable.ID_GIOCATORE + "= ? AND + " + StatisticaTable.ID_PARTITA + "= ?;";

SQLite 有时会有点棘手,因为它只使用五种基本数据类型。我注意到如果存储的数据库值和搜索参数的类型不同,WHERE 语句可能会失败。尝试将 ID_GIOCATORE 参数和 ID_PARTITA 参数转换为数据库中使用的本机类型。

http://www.sqlite.org/datatype3.html

于 2013-09-13T21:06:40.460 回答