TypeConverter not working when updating List in Room Database

后端 未结 2 658
终归单人心
终归单人心 2021-01-20 17:15

My query is showing a syntax error in the DAO_Impl build for some reason. I tried a rebuild but it still errors when conducting the following query:

Query:



        
2条回答
  •  我在风中等你
    2021-01-20 18:02

    So by the suggestion from Jeel Vankhede, I changed the MutableList to an ArrayList and the UPDATE query works. The difference in the Impl build :

    MutableList:

    @Override
      public void test(int tkID, List test) {
        StringBuilder _stringBuilder = StringUtil.newStringBuilder();
        _stringBuilder.append("UPDATE TasksTable SET test = ");
        final int _inputSize = test.size();
        StringUtil.appendPlaceholders(_stringBuilder, _inputSize);
        _stringBuilder.append(" WHERE taskID = ");
        _stringBuilder.append("?");
        final String _sql = _stringBuilder.toString();
        SupportSQLiteStatement _stmt = __db.compileStatement(_sql);
    

    ArrayList:

    @Override
      public void test(int tkID, ArrayList test) {
        final SupportSQLiteStatement _stmt = __preparedStmtOfTest.acquire();
        __db.beginTransaction();
        try {
          int _argIndex = 1;
          final String _tmp;
          _tmp = Converters.listBooleanToString(test);
          if (_tmp == null) {
            _stmt.bindNull(_argIndex);
          } else {
            _stmt.bindString(_argIndex, _tmp);
          }
          _argIndex = 2;
          _stmt.bindLong(_argIndex, tkID);
          _stmt.executeUpdateDelete();
          __db.setTransactionSuccessful();
        } finally {
          __db.endTransaction();
          __preparedStmtOfTest.release(_stmt);
        }
      }
    

    As you can see, the ArrayList uses the converter while the MutableList does not. Not sure why this is??

提交回复
热议问题