久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

替換 SQLite DB 中的路徑字符串導致意外違反唯一約

Replace path string in SQLite DB causes unexpected violated unique constraint(替換 SQLite DB 中的路徑字符串導致意外違反唯一約束)
本文介紹了替換 SQLite DB 中的路徑字符串導致意外違反唯一約束的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我不確定我是否在 SQLite 中發現了錯誤,或者我是否只是沒有正確使用它.我將相對文件路徑(正如您從 UNIX 文件系統中知道的那樣)存儲在數據庫中.為安全起見,我已將該列標記為唯一.

I'm not sure whether I've found a bug in SQLite or whether I'm simply not using it correctly. I'm storing relative file paths (as you know them from UNIX file systems) in a DB. For safety I've marked the column to be unique.

下面是一個不言自明的示例,其中最后一個命令意外失敗并違反了 UNIQUE 約束.我的目標是將路徑為a"的目錄重命名為d"

Below is a self-explanatory example where the last command unexpectedly fails with a violated UNIQUE constraint. My goal is to rename the directory with path "a" to "d"

CREATE TABLE test (db_id INTEGER PRIMARY KEY, path TEXT UNIQUE);
INSERT INTO test (path) VALUES ('a');
INSERT INTO test (path) VALUES ('a/d/a');
INSERT INTO test (path) VALUES ('a/d');
INSERT INTO test (path) VALUES ('a/d/c');
INSERT INTO test (path) VALUES ('a/a');
INSERT INTO test (path) VALUES ('a/c');
INSERT INTO test (path) VALUES ('a/a/a');
UPDATE test SET path = 'd' WHERE db_id = 1;
UPDATE test SET path = replace(path, 'a/', 'd/') WHERE path GLOB 'a/*'

歡迎提出任何想法.我使用的是 SQLite v2.6.0.

Any ideas are welcome. I'm using SQlite v2.6.0.

推薦答案

INSERT INTO test (path) VALUES ('a/d/a');
INSERT INTO test (path) VALUES ('a/a/a');

d/替換a/后,兩個值都是d/d/a.

After replacing a/ with d/, both values are d/d/a.

如果只想更改字符串開頭的a/,則不能使用replace():

If you want to change only an a/ at the start of the string, you cannot use replace():

UPDATE test
SET path = 'd/' || substr(path, 3)
WHERE path GLOB 'a/*';

這篇關于替換 SQLite DB 中的路徑字符串導致意外違反唯一約束的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
Dynamically creating a placeholder to insert many column values for a row in SQLite table(動態創建占位符以在 SQLite 表中為一行插入多個列值)
Convert multiple sub-queries to on join(將多個子查詢轉換為 on join)
How do I get the minute difference between 2 times in T SQL?(如何獲得 T SQL 中 2 次之間的微小差異?)
主站蜘蛛池模板: 羞羞视频在线观看网站 | 亚洲成人av一区二区 | 成人福利电影 | 精品99久久 | 韩国欧洲一级毛片 | 超碰人人插| 日韩免费一区二区 | 日韩精品一区二区三区在线播放 | 国产精品一区二区三区久久 | 亚洲444kkkk在线观看最新 | 无码日韩精品一区二区免费 | 欧美精品乱码99久久影院 | 99久久99 | avhd101在线成人播放 | 久久久久久久久久久久久9999 | 免费一二区 | 免费的网站www | 草草影院ccyy | 亚洲高清视频在线观看 | 91av导航 | 久久精品亚洲精品国产欧美 | 91精品国产综合久久久久久丝袜 | 欧美三级视频在线观看 | 91黄色免费看 | caoporn地址| 国产a视频 | 99免费在线观看视频 | 欧美一区二区三区在线 | 日韩av一二三区 | 亚洲九色| 日本a在线| 成人激情视频免费在线观看 | 国产成人a亚洲精品 | 天天综合网永久 | 老头搡老女人毛片视频在线看 | 久久av一区| 免费精品久久久久久中文字幕 | 久草视频在线播放 | 日韩人体在线 | 亚洲二区视频 | 精品一区二区三区免费视频 |