简体   繁体   English

使用自定义查询和rawQuery或execSQL更新不起作用

[英]update using custom query and rawQuery or execSQL not working

I'm using a personal query to update values ​​in a table, in this case to increase the value of certain columns. 我正在使用个人查询来更新表中的值,在这种情况下要增加某些列的值。 For example, would I do something like: 例如,我会做类似的事情:

UPDATE statistica SET 1PF = 1PF + ? WHERE id_statistica = ?;

My code is as follows: 我的代码如下:

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

Essentially the code is this... But does not update anything (either using both execSQL rawQuery) in spite of the parameters are passed correctly and the sql string is formed in the right way ... I do not understand what is wrong ... 本质上,代码是这样的……但是尽管正确地传递了参数并且以正确的方式形成了sql字符串,但是却不更新任何内容(使用execSQL rawQuery都使用了两者)……我不明白是什么错误。 。

Well if you don't get any SQL Exception then perhaps you should focus on the WHERE statment. 好吧,如果您没有任何SQL异常,那么也许您应该关注WHERE语句。

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

SQLite can be a little tricky sometimes since it only use five basic datatypes. 有时SQLite可能会有些棘手,因为它仅使用五种基本数据类型。 I've noticed that WHERE statements can fail if the stored database value and the search parameter are of different types. 我注意到,如果存储的数据库值和搜索参数属于不同的类型,则WHERE语句可能会失败。 Try to convert the ID_GIOCATORE parameter and the ID_PARTITA parameter into the native type used in the database. 尝试将ID_GIOCATORE参数和ID_PARTITA参数转换为数据库中使用的本机类型。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM