Status Update
Comments
so...@gmail.com <so...@gmail.com> #2
Если alternativeTranslations с более чем одним элементом сразу преобразовать в строку всё отлично работает, но это было сложно понять и вызывает некоторые неудобства.
so...@gmail.com <so...@gmail.com> #3
При использовании:
@Update
fun updateWord(dictionaryWord: DictionaryWord)
Также всё отлично работает, но мне нужно исключить некоторые поля, чтобы они не перезаписывались.
@Update
fun updateWord(dictionaryWord: DictionaryWord)
Также всё отлично работает, но мне нужно исключить некоторые поля, чтобы они не перезаписывались.
da...@google.com <da...@google.com> #4
Проблема, которую вы описываете об использовании TypeConverter и List в качестве параметра, была недавно исправлена в Room 2.1.0, и фикс будет частью следующего бета релиза, см. : http://issuetracker.google.com/122066791
Description
Version used:
Devices/Android versions reproduced on:
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
Привет! Мне сложно верно изложить свои мысли на Английском языке, извините.
Я использую:
implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"
У меня есть объект внутри которого есть несколько полей разного типа и несколько: List<String>?
Для их преобразования я использую:
@TypeConverter
fun fromList(list: List<String>?): String? {
return if (list == null) null else "$list"
}
Выполняю следующий запрос:
@Query("UPDATE vocabulary SET transcription = :transcription, translation = :translation, alternativeTranslations = :alternativeTranslations WHERE wordName = :wordName")
fun updateWordBesideTimeAndCovers(wordName: String, transcription: String, translation: String, alternativeTranslations: List<String>)
проблема возникает при сохранении в бд "alternativeTranslations: List<String>" при наличии в списке больше одного элемента:
com.guralnya.myvocabulary E/SQLiteLog: (1) near "?": syntax error
com.guralnya.myvocabulary E/AndroidRuntime: FATAL EXCEPTION: Thread-8
Process: com.guralnya.myvocabulary, PID: 13498
android.database.sqlite.SQLiteException: near "?": syntax error (code 1 SQLITE_ERROR): , while compiling: UPDATE vocabulary SET transcription = ?, translation = ?, alternativeTranslations = ?,?,?,?,? WHERE wordName = ?
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1086)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.compileStatement(FrameworkSQLiteDatabase.java:64)
at androidx.room.RoomDatabase.compileStatement(RoomDatabase.java:249)
at com.guralnya.myvocabulary.domain.database.DictionaryDao_Impl.updateWordBesideTimeAndCovers(DictionaryDao_Impl.java:509)
at com.guralnya.myvocabulary.domain.web_service.DictionaryWebServiceImpl.getTranslate(DictionaryWebServiceImpl.kt:62)
at com.guralnya.myvocabulary.domain.web_service.DictionaryWebServiceImpl.loadTranslate(DictionaryWebServiceImpl.kt:11)
at com.guralnya.myvocabulary.domain.repositories.DictionaryRepositoryImpl.loadWord(DictionaryRepositoryImpl.kt:35)
at com.guralnya.myvocabulary.domain.repositories.DictionaryRepositoryImpl$getWord$1.run(DictionaryRepositoryImpl.kt:21)
at java.lang.Thread.run(Thread.java:764)
при одном элементе в списке таких проблем не возникает. Предполагаю что проблема заключается в том что при использовании запроса @Query("UPDATE ..."), @TypeConverters не вызывается.
При дебаге было выявлено следующее:
при наличии в списке более одного элемента выполнение обрывается на строчке:
SupportSQLiteStatement _stmt = __db.compileStatement(_sql); в классе: MyDao_Impl.java