sqlite未转义"字符 - 如何逃避双引号?

liv*_*ove 6 sqlite

我无法导入到sql lite中.我正在将表从Sql Server导出到以UTF-8编码的平面文件中.然后尝试将平面文件导入sqlite db.DB是UTF-8编码的.

这些行很麻烦(制表符分隔,行以CRLF结尾):

ID  w   posid   def
1234    bracket 40  "(" and ")" spec...

1234    bracket 40  Any of the characters "(", ")", "[", "]", "{", "}", and, in the area of computer languages, "<" and ">".
Run Code Online (Sandbox Code Playgroud)

错误:

未转义的"性格

我试过用"双引号"替换引号,"仍然不起作用.

导入设置:选项卡分隔符

.分隔器 " "

.import data.txt字样

sqlite表架构:

CREATE TABLE words (ID integer NOT NULL, w TEXT  NOT NULL, posid integer NOT NULL, def TEXT NOT NULL);
Run Code Online (Sandbox Code Playgroud)

更新:不知何故,在Sql Server的def字段开头添加一个哈希工作:

更新单词设置def ='#'+ def

不知道为什么会这样.这有效,但它在该领域增加了一个不需要的角色.

liv*_*ove 3

事实证明,当存在换行符、引号或逗号时,导入可能会混乱。

一种解决方案是将这些字符替换为其他一些字符序列或字符代码(例如 char(1)、char(2)...),并在运行之前确保字段不包含这些序列或代码进口。例如,将引号替换为 - -,然后导入,然后再次将 - - 替换为引号。我有另一个表,其中一些文本字段具有换行符,并且此解决方案似乎有效。

before import:

update [table] set comment = REPLACE(comment, CHAR(13), '-*-')
update [table] set comment = REPLACE(comment, CHAR(10), '%-$-%')
update [table] set comment = REPLACE(comment, '"', '%-&-%')

after import:

update [table] set comment = REPLACE(comment, '-*-', CHAR(13))
update [table] set comment = REPLACE(comment, '%-$-%', CHAR(10))
update [table] set comment = REPLACE(comment, '%-&-%', '"')
Run Code Online (Sandbox Code Playgroud)