android - 如何在android room数据库sql中使用replace?

标签 android android-room

    @Query("update bookmarks set bookmarks_path= replace(bookmarks_path,:oldPath,:newPath) where bookmarks_path like :oldPath || '%'")
    fun updateBookmarksPath(oldPath: String, newPath: String): Completable

我正在使用房间数据库,这是我的代码

运行时发现这段代码的格式不正确,android studio提示我:explosionexpected,got'replace'

像这样

enter image description here

我想要达到这样的效果

----路径------------------路径

/root/1/1--------------/stack/1/1

/root/name/1------/stack/name/1

/root/cls/1------------/stack/cls/1

/root/go/1------------/stack/go/1

/root/js/1------------/stack/js/1

最佳答案

REPLACE 都是 SQLite keyword并且,根据您的预期用途,字符串函数的名称:replace() 。 Room 注释处理器似乎拒绝您的查询字符串,因为它将 replace 视为关键字而不是函数名称。也许是一个错误?

一些快速实验表明,一个可能的解决方案是用反引号将 replace 括起来,以将 is 标记为名称(请参阅上面的关键字链接)。请尝试一下:

@Query("update bookmarks set bookmarks_path= `replace`(bookmarks_path,:oldPath,:newPath) where bookmarks_path like :oldPath || '%'")
fun updateBookmarksPath(oldPath: String, newPath: String): Completable

关于android - 如何在android room数据库sql中使用replace?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62468205/

相关文章:

android - 在没有用户参与的情况下自动向联系人发送 whatsapp 消息

java - Jetpack Navigation - 添加 nav_graph.xml 时如何处理依赖警告?

android - react-native运行android失败

java - 尝试将开发应用程序编译为生产环境时收到来自 Eclipse 的警告?

java - 我如何合并红绿色和蓝色位图以获得原始位图

java - 从位图android的边缘创建路径

android - Room Entity 的数据存储正确,但检索为 null

android - Room LiveData 观察器 (onChange) 触发多次但仅针对 INSERT

android - 在dao类中实现网络调用

android - Rxjava 3 + Retrofit2 - 多次插入数据库问题