0

使用DB Browser for SQLite,您现在可以成功地从具有 IUNICODE 排序顺序错误的数据库中导出表,但这是使用 DB Browser 的 GUI 的手动过程。我使用了 DB Browser,因为如果你尝试使用 sqlite3 从 bash 或 sqlite 控制台导出表,你会得到:

Error: no such collation sequence: IUNICODE

由于 DB Browser 似乎没有命令行选项(这是正确的吗?),我正在寻找另一种方法,以便我可以自动导出表,最好使用 bash 脚本。

根据下面 CL 的回复……做了以下事情:

sqlite3 /home/lpc123/data/MM.DB "SELECT sql FROM sqlite_master WHERE type='table' AND name='Songs';" 

...生成了一长串表定义:

CREATE TABLE Songs (ID INTEGER PRIMARY KEY AUTOINCREMENT,Artist TEXT COLLATE IUNICODE,IDAlbum INTEGER,Album TEXT COLLATE IUNICODE,AlbumArtist TEXT COLLATE IUNICODE,DiscNumber TEXT COLLATE IUNICODE,TrackNumber TEXT COLLATE IUNICODE,SongTitle TEXT COLLATE IUNICODE,SongPath TEXT COLLATE IUNICODE,Extension TEXT(5),Year INTEGER,Genre TEXT COLLATE IUNICODE,FileLength INTEGER,SongLength INTEGER,IDMedia INTEGER,CacheStatus INTEGER,CacheName TEXT COLLATE IUNICODE,Rating INTEGER,Bitrate INTEGER,Seekable INTEGER,Broadcast INTEGER,PreviewState INTEGER,PreviewName TEXT COLLATE IUNICODE,PreviewStartTime INTEGER,PreviewLength INTEGER,Author TEXT COLLATE IUNICODE,SamplingFrequency INTEGER,Stereo INTEGER,VBR INTEGER,BPM INTEGER,SignType INTEGER,SignPart1 INTEGER,SignPart2 INTEGER,SignPart3 INTEGER,SignPart4 INTEGER,PlayCounter INTEGER,LastTimePlayed REAL,AudioCDTrack INTEGER,FileModified REAL,TrackModified REAL,MaxSample REAL,NormalizeTrack REAL,NormalizeAlbum REAL,Custom1 TEXT COLLATE IUNICODE,Custom2 TEXT COLLATE IUNICODE,Custom3 TEXT COLLATE IUNICODE,Custom4 TEXT COLLATE IUNICODE,Custom5 TEXT COLLATE IUNICODE,DateAdded REAL,OrigFileLength INTEGER,PreGap INTEGER,PostGap INTEGER,TotalSamples INTEGER,PlaybackPos INTEGER,GaplessBytes INTEGER,IDFolder INTEGER,IDEpisode INTEGER,TrackType INTEGER,Copyright TEXT COLLATE IUNICODE,Publisher TEXT COLLATE IUNICODE,Encoder TEXT COLLATE IUNICODE,Lyricist TEXT COLLATE IUNICODE,Conductor TEXT COLLATE IUNICODE,Remixer TEXT COLLATE IUNICODE,InvolvedPeople TEXT COLLATE IUNICODE,OrigTitle TEXT COLLATE IUNICODE,OrigArtist TEXT COLLATE IUNICODE,OrigLyricist TEXT COLLATE IUNICODE,GroupDesc TEXT COLLATE IUNICODE,SubTitle TEXT COLLATE IUNICODE,ISRC TEXT COLLATE IUNICODE,InitialKey TEXT COLLATE IUNICODE,Language TEXT COLLATE IUNICODE,WebCommercial TEXT COLLATE IUNICODE,WebCopyright TEXT COLLATE IUNICODE,WebFilepage TEXT COLLATE IUNICODE,WebArtist TEXT COLLATE IUNICODE,WebSource TEXT COLLATE IUNICODE,WebRadio TEXT COLLATE IUNICODE,WebPayment TEXT COLLATE IUNICODE,WebPublisher TEXT COLLATE IUNICODE,WebUser TEXT COLLATE IUNICODE,OrigYear INTEGER,Tempo TEXT COLLATE IUNICODE,Mood TEXT COLLATE IUNICODE,Occasion TEXT COLLATE IUNICODE,Quality TEXT COLLATE IUNICODE,Lyrics TEXT COLLATE IUNICODE,Comment TEXT COLLATE IUNICODE, StartTime INTEGER, StopTime INTEGER, SkipCount INTEGER, VideoWidth INTEGER, VideoHeight INTEGER, FrameRate INTEGER, ContainerType INTEGER, StreamCount INTEGER, StreamInfo TEXT, EpisodeNumber TEXT COLLATE IUNICODE, SeasonNumber TEXT COLLATE IUNICODE, Actors TEXT COLLATE IUNICODE, Producer TEXT COLLATE IUNICODE, ParentalRating TEXT COLLATE IUNICODE, ArtworkModified REAL)

从该字符串中删除了“COLLATE IUNICODE”的所有实例:

CREATE TABLE Songs (ID INTEGER PRIMARY KEY AUTOINCREMENT,Artist TEXT ,IDAlbum INTEGER,Album TEXT ,AlbumArtist TEXT ,DiscNumber TEXT ,TrackNumber TEXT ,SongTitle TEXT ,SongPath TEXT ,Extension TEXT(5),Year INTEGER,Genre TEXT ,FileLength INTEGER,SongLength INTEGER,IDMedia INTEGER,CacheStatus INTEGER,CacheName TEXT ,Rating INTEGER,Bitrate INTEGER,Seekable INTEGER,Broadcast INTEGER,PreviewState INTEGER,PreviewName TEXT ,PreviewStartTime INTEGER,PreviewLength INTEGER,Author TEXT ,SamplingFrequency INTEGER,Stereo INTEGER,VBR INTEGER,BPM INTEGER,SignType INTEGER,SignPart1 INTEGER,SignPart2 INTEGER,SignPart3 INTEGER,SignPart4 INTEGER,PlayCounter INTEGER,LastTimePlayed REAL,AudioCDTrack INTEGER,FileModified REAL,TrackModified REAL,MaxSample REAL,NormalizeTrack REAL,NormalizeAlbum REAL,Custom1 TEXT ,Custom2 TEXT ,Custom3 TEXT ,Custom4 TEXT ,Custom5 TEXT ,DateAdded REAL,OrigFileLength INTEGER,PreGap INTEGER,PostGap INTEGER,TotalSamples INTEGER,PlaybackPos INTEGER,GaplessBytes INTEGER,IDFolder INTEGER,IDEpisode INTEGER,TrackType INTEGER,Copyright TEXT ,Publisher TEXT ,Encoder TEXT ,Lyricist TEXT ,Conductor TEXT ,Remixer TEXT ,InvolvedPeople TEXT ,OrigTitle TEXT ,OrigArtist TEXT ,OrigLyricist TEXT ,GroupDesc TEXT ,SubTitle TEXT ,ISRC TEXT ,InitialKey TEXT ,Language TEXT ,WebCommercial TEXT ,WebCopyright TEXT ,WebFilepage TEXT ,WebArtist TEXT ,WebSource TEXT ,WebRadio TEXT ,WebPayment TEXT ,WebPublisher TEXT ,WebUser TEXT ,OrigYear INTEGER,Tempo TEXT ,Mood TEXT ,Occasion TEXT ,Quality TEXT ,Lyrics TEXT ,Comment TEXT , StartTime INTEGER, StopTime INTEGER, SkipCount INTEGER, VideoWidth INTEGER, VideoHeight INTEGER, FrameRate INTEGER, ContainerType INTEGER, StreamCount INTEGER, StreamInfo TEXT, EpisodeNumber TEXT , SeasonNumber TEXT , Actors TEXT , Producer TEXT , ParentalRating TEXT , ArtworkModified REAL)

使用 PRAGMA writable_schema=1 启用对 sqlite_master 的写访问:

sqlite3 /home/lpc123/data/MM.DB "PRAGMA writable_schema=1;"

这是事情发生故障或先前命令未执行的地方):

将您的新表定义写入其中

UPDATE sqlite_master SET sql='...' WHERE type='table' AND name='MonkeyTable'; 我认为这意味着:

sqlite3 /home/lpc123/data/MM.DB "UPDATE sqlite_master SET sql='CREATE TABLE Songs (ID INTEGER PRIMARY KEY AUTOINCREMENT,Artist TEXT ,IDAlbum INTEGER,Album TEXT ,AlbumArtist TEXT ,DiscNumber TEXT ,TrackNumber TEXT ,SongTitle TEXT ,SongPath TEXT ,Extension TEXT(5),Year INTEGER,Genre TEXT ,FileLength INTEGER,SongLength INTEGER,IDMedia INTEGER,CacheStatus INTEGER,CacheName TEXT ,Rating INTEGER,Bitrate INTEGER,Seekable INTEGER,Broadcast INTEGER,PreviewState INTEGER,PreviewName TEXT ,PreviewStartTime INTEGER,PreviewLength INTEGER,Author TEXT ,SamplingFrequency INTEGER,Stereo INTEGER,VBR INTEGER,BPM INTEGER,SignType INTEGER,SignPart1 INTEGER,SignPart2 INTEGER,SignPart3 INTEGER,SignPart4 INTEGER,PlayCounter INTEGER,LastTimePlayed REAL,AudioCDTrack INTEGER,FileModified REAL,TrackModified REAL,MaxSample REAL,NormalizeTrack REAL,NormalizeAlbum REAL,Custom1 TEXT ,Custom2 TEXT ,Custom3 TEXT ,Custom4 TEXT ,Custom5 TEXT ,DateAdded REAL,OrigFileLength INTEGER,PreGap INTEGER,PostGap INTEGER,TotalSamples INTEGER,PlaybackPos INTEGER,GaplessBytes INTEGER,IDFolder INTEGER,IDEpisode INTEGER,TrackType INTEGER,Copyright TEXT ,Publisher TEXT ,Encoder TEXT ,Lyricist TEXT ,Conductor TEXT ,Remixer TEXT ,InvolvedPeople TEXT ,OrigTitle TEXT ,OrigArtist TEXT ,OrigLyricist TEXT ,GroupDesc TEXT ,SubTitle TEXT ,ISRC TEXT ,InitialKey TEXT ,Language TEXT ,WebCommercial TEXT ,WebCopyright TEXT ,WebFilepage TEXT ,WebArtist TEXT ,WebSource TEXT ,WebRadio TEXT ,WebPayment TEXT ,WebPublisher TEXT ,WebUser TEXT ,OrigYear INTEGER,Tempo TEXT ,Mood TEXT ,Occasion TEXT ,Quality TEXT ,Lyrics TEXT ,Comment TEXT , StartTime INTEGER, StopTime INTEGER, SkipCount INTEGER, VideoWidth INTEGER, VideoHeight INTEGER, FrameRate INTEGER, ContainerType INTEGER, StreamCount INTEGER, StreamInfo TEXT, EpisodeNumber TEXT , SeasonNumber TEXT , Actors TEXT , Producer TEXT , ParentalRating TEXT , ArtworkModified REAL)' WHERE type='table' AND name='Songs';"

这导致了这个错误:

Error: table sqlite_master may not be modified

我想也许关于创建表的部分不属于,所以我这次又试了一次,没有 CREATE TABLE 部分:

sqlite3 /home/lpc123/data/MM.DB "UPDATE sqlite_master SET sql='TABLE Songs (ID INTEGER PRIMARY KEY AUTOINCREMENT,Artist TEXT ,IDAlbum INTEGER,Album TEXT ,AlbumArtist TEXT ,DiscNumber TEXT ,TrackNumber TEXT ,SongTitle TEXT ,SongPath TEXT ,Extension TEXT(5),Year INTEGER,Genre TEXT ,FileLength INTEGER,SongLength INTEGER,IDMedia INTEGER,CacheStatus INTEGER,CacheName TEXT ,Rating INTEGER,Bitrate INTEGER,Seekable INTEGER,Broadcast INTEGER,PreviewState INTEGER,PreviewName TEXT ,PreviewStartTime INTEGER,PreviewLength INTEGER,Author TEXT ,SamplingFrequency INTEGER,Stereo INTEGER,VBR INTEGER,BPM INTEGER,SignType INTEGER,SignPart1 INTEGER,SignPart2 INTEGER,SignPart3 INTEGER,SignPart4 INTEGER,PlayCounter INTEGER,LastTimePlayed REAL,AudioCDTrack INTEGER,FileModified REAL,TrackModified REAL,MaxSample REAL,NormalizeTrack REAL,NormalizeAlbum REAL,Custom1 TEXT ,Custom2 TEXT ,Custom3 TEXT ,Custom4 TEXT ,Custom5 TEXT ,DateAdded REAL,OrigFileLength INTEGER,PreGap INTEGER,PostGap INTEGER,TotalSamples INTEGER,PlaybackPos INTEGER,GaplessBytes INTEGER,IDFolder INTEGER,IDEpisode INTEGER,TrackType INTEGER,Copyright TEXT ,Publisher TEXT ,Encoder TEXT ,Lyricist TEXT ,Conductor TEXT ,Remixer TEXT ,InvolvedPeople TEXT ,OrigTitle TEXT ,OrigArtist TEXT ,OrigLyricist TEXT ,GroupDesc TEXT ,SubTitle TEXT ,ISRC TEXT ,InitialKey TEXT ,Language TEXT ,WebCommercial TEXT ,WebCopyright TEXT ,WebFilepage TEXT ,WebArtist TEXT ,WebSource TEXT ,WebRadio TEXT ,WebPayment TEXT ,WebPublisher TEXT ,WebUser TEXT ,OrigYear INTEGER,Tempo TEXT ,Mood TEXT ,Occasion TEXT ,Quality TEXT ,Lyrics TEXT ,Comment TEXT , StartTime INTEGER, StopTime INTEGER, SkipCount INTEGER, VideoWidth INTEGER, VideoHeight INTEGER, FrameRate INTEGER, ContainerType INTEGER, StreamCount INTEGER, StreamInfo TEXT, EpisodeNumber TEXT , SeasonNumber TEXT , Actors TEXT , Producer TEXT , ParentalRating TEXT , ArtworkModified REAL)' WHERE type='table' AND name='Songs';"

那也没有用。

4

3 回答 3

1

您可以修改数据库以删除对该排序规则的所有引用。

阅读表定义:

SELECT sql FROM sqlite_master WHERE type='table' AND name='MonkeyTable';

从字符串中删除,然后使用PRAGMA writable_schema=1COLLATE IUNICODE启用写访问;并将您的新表定义写入其中:sqlite_master

UPDATE sqlite_master SET sql='...' WHERE type='table' AND name='MonkeyTable';

如果您确实想以交互方式执行此操作,则必须在同一会话中执行这两个语句:

sqlite3 mm.db "PRAGMA writable_schema=1; UPDATE sqlite_master ..."

之后,重新打开数据库并运行REINDEX(因为更改排序规则会使所有索引内容无效)。

于 2017-11-03T14:37:55.883 回答
1

MediaMonkey 用户的工作解决方案:

1.) 从这里下载适用于 Windows 的“命令行 SQLite 工具包”:https ://sqlite.org/download.html (存档实际上被调用sqlite-tools-win32-x86-3330000.zip并且不存在 64 位,32 位工作正常。)

2.) 解压 ZIP 文件,您至少需要该文件sqlite3.exe

3.) 始终创建 MM.DB 的副本,切勿将原始副本用于以下步骤!

4.)CopyOfMM.DB在 CMD 窗口中打开你的sqlite3.exe CopyOfMM.DB

5.) 在 sqlite-prompt 上,执行以下命令:

SELECT sql FROM sqlite_master WHERE type='table' AND name='Songs';

6.) 将完整的 CREATE TABLE 输出文本复制到 Notepad++ 等编辑器中

7.) 将所有出现的COLLATE IUNICODE文本替换为空(删除它们)

8.) 退出 sqlite-prompt.quit

9.) 在 CMD 窗口中以单行方式执行以下命令(将CREATE TABLE Songs部分完全替换为您在步骤 #7 中修改的文本。此文本在 MediaMonkey-Versions 之间有所不同!添加后缀' WHERE type='table' AND name='Songs';"

sqlite3.exe CopyOfMM.DB "PRAGMA writable_schema=1; UPDATE sqlite_master SET sql='CREATE TABLE Songs (......)' WHERE type='table' AND name='Songs';"

这只需一秒钟。

9a) 如果您想确定此命令是否更改了表定义,请重复步骤 #4 和 #5 并仔细检查是否不再存在 IUNICODE COLLATION。退出 sqlite3.exe 提示。

10.) 使用以下命令重新索引表 Songs:

sqlite3.exe CopyOfMM.DB "REINDEX Songs;"

这需要一分钟左右,具体取决于此表中的条目数量。

现在你终于可以为你的 Songs 表执行任何 sqlite 命令,而不会出现“错误:没有这样的排序序列:IUNICODE”</p>

重复一遍:不要对您的原始 MediaMonkey 数据库执行此操作!

于 2020-10-06T13:16:01.113 回答
0

答案是这里发布的一个脚本,它将数据库中包含的所有表提取到单个 CSV 文件中,并且可以在 bash 中运行。在这种情况下,需要的输出是一张表,并被命名为songs.csv。

然后,您可以创建一个 SQL 文件:import.sql,您必须对其进行定制以包含提取的表中显示的所有列(此示例显示四列):

CREATE TABLE Songs (ID varchar(255) not null, Artist varchar(255) not null, IDAlbum varchar(255) not null, Album varchar(255) not null);
.separator ,
.import songs.csv Songs

现在您可以在 bash 中运行以下命令:

sqlite3 currdb.sqlite < import.sql

...创建一个包含您导入的表的可访问数据库。

于 2017-11-08T13:56:00.760 回答