简体   繁体   English

如何使用搜索和替换查询更新SQLite数据库?

[英]How to update an SQLite database with a search and replace query?

My SQL knowledge is very limited, specially about SQLite, although I believe this is will be some sort of generic query... Or maybe not because of the search and replace... 我的SQL知识非常有限,特别是关于SQLite,虽然我相信这将是某种通用查询...或者可能不是因为搜索和替换...

I have this music database in SQLite that has various fields of course but the important ones here the "media_item_id" and "content_url". 我在SQLite中有这个音乐数据库,当然有各种各样的领域,但重要的是“media_item_id”和“content_url”。

Here's an example of a "content_url": 这是“content_url”的示例:

file:///c:/users/nazgulled/music/band%20albums/devildriver/%5b2003%5d%20devildriver/08%20-%20what%20does%20it%20take%20(to%20be%20a%20man).mp3

I'm looking for a query that will search for entries like those, where "content_url" follows that pattern and replace it (the "content_url") with something else. 我正在寻找一个搜索类似条目的查询,其中“content_url”遵循该模式,并用其他东西替换它(“content_url”)。

For instance, a generic "content_url" can be this: 例如,通用的“content_url”可以是这样的:

file:///c:/users/nazgulled/music/band%20albums/BAND_NAME/ALBUM_NAME/SONG_NAME.mp3

And I want to replace all these entries with: 我想用以下内容替换所有这些条目:

file:///c:/users/nazgulled/music/bands/studio%20albums/BAND_NAME/ALBUM_NAME/SONG_NAME.mp3

How can I do it in one query? 我怎么能在一个查询中做到这一点?

PS: I'm using Firefox SQLite Manager (couldn't find a better and free alternative for Windows). PS:我正在使用Firefox SQLite Manager(找不到更好的免费替代Windows)。

You are probably looking for the replace function. 您可能正在寻找replace功能。

For example, 例如,

update table_name set 
  content_url = replace(content_url, 'band%20albums', 'bands/studio%20albums')
where
  content_url like '%nazgulled/music/band_20albums/%';

More documentation at http://sqlite.org/lang_corefunc.html http://sqlite.org/lang_corefunc.html上有更多文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM