Sqlite - 如何转义双引号?

标签 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 ">".

错误:

未转义的 "字符

我试过用双引号替换引号“”,还是不行。

导入设置:制表符分隔符

.分隔符“”

.import data.txt 单词

sqlite 表模式:

CREATE TABLE words (ID integer NOT NULL, w TEXT  NOT NULL, posid integer NOT NULL, def TEXT NOT NULL);

更新: 不知何故,在 Sql Server 中的 def 字段的开头添加一个散列有效:

更新单词集 def = '#' + def

不知道为什么会这样。这行得通,但在该字段中添加了不需要的字符。

最佳答案

事实证明,当有换行符、引号或逗号时,导入可能会出错。

一种解决方案是将这些字符替换为其他一些字符序列或字符代码(例如 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, '%-&-%', '"')

关于Sqlite - 如何转义双引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27951146/

相关文章:

java - Android:SQL - 代码行为不同

python - 将 .db 文件读入 Python

android - Nexus 9 SQLite 文件在外部目录上写入操作的解决方法?

sqlite - 来自日期和时间与温度的sqlite数据库的数据的gnuplot?

arrays - React-native Sqlite,强制 ListView 用新数据更新

sqlite - SQLite3 中 TIMESTAMP 类型的 EXTRACT

ios - 如何在 Swift 3 上修复 'No such module SQLite'

c# - 使用 navicat 打开与 SQLite 安全数据库的连接

Android 将现有数据库导入项目时出错

android - 删除所有查询或删除查询