簡體   English   中英

如何在android房間數據庫sql中使用replace?

[英]How to use replace in android room database sql?

    @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提示我:expression expected, got'replace'

像這樣

在此處輸入圖像描述

我想達到這樣的效果

-----路徑--------路徑

/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 關鍵字,又是字符串 function 的名稱: replace() Room 注釋處理器似乎拒絕您的查詢字符串,因為它將replace視為關鍵字而不是 function 名稱。 也許是一個錯誤?

一些快速實驗表明,一種可能的解決方案是在反引號中包圍replace以將其標記為名稱(參見上面的關鍵字鏈接)。 請試一試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM