Sqlite Error: Expression tree is too large (maximum depth 1000)

Sqlite Error: Expression tree is too large (maximum depth 1000)

我正在尝试对格式错误的 sqlite 文件进行干净的导出-导入。

使用来自 techblog.dorogin.com/sqliteexception-datab... 的信息,这就是我所做的 sqlite3 oldfile:

  1. .mode insert
  2. .output tempfile
  3. .dump

然后我创建了一个新的sqlite3 newfile:

错误:

sqlite> .read tempfile
Error: near line 52330: Expression tree is too large (maximum depth 1000)
Error: near line 53097: Expression tree is too large (maximum depth 1000)
Error: near line 53427: Expression tree is too large (maximum depth 1000)
Error: near line 54013: Expression tree is too large (maximum depth 1000)
Error: near line 54014: Expression tree is too large (maximum depth 1000)
Error: near line 54047: Expression tree is too large (maximum depth 1000)
Error: near line 54048: Expression tree is too large (maximum depth 1000)
Error: near line 54227: Expression tree is too large (maximum depth 1000)
Error: near line 54294: Expression tree is too large (maximum depth 1000)
Error: near line 54373: Expression tree is too large (maximum depth 1000)
Error: near line 54374: Expression tree is too large (maximum depth 1000)
Error: near line 56688: Expression tree is too large (maximum depth 1000)
Error: near line 57950: Expression tree is too large (maximum depth 1000)
Error: near line 58015: Expression tree is too large (maximum depth 1000)
Error: near line 58077: Expression tree is too large (maximum depth 1000)
Error: near line 58246: Expression tree is too large (maximum depth 1000)
Error: near line 59795: Expression tree is too large (maximum depth 1000)
Error: near line 60439: Expression tree is too large (maximum depth 1000)
Error: near line 61501: Expression tree is too large (maximum depth 1000)
Error: near line 61523: Expression tree is too large (maximum depth 1000)
Error: near line 61811: Expression tree is too large (maximum depth 1000)
Error: near line 61824: Expression tree is too large (maximum depth 1000)

在输出文件中,我的最大行数是 35737 个字符。

我该如何解决这个错误?

对格式错误的 sqlite 文件进行干净的导出-导入有哪些解决方案?

这是由于版本 3.18.0 中的 change sqlite3:

In the output of the ".dump" command in the CLI, quote newline and carriage-return characters using the char() function, so that they do not get eaten by end-of-line processing logic in the OS or in other command-line utilities and/or libraries.

如果单个字符串值中的换行符过多,生成的 SQL 表达式将变得过于复杂。

这是 fixed in version 3.19.0。 如果您仍在使用 3.18.0,则可以通过将文件转换为使用原始换行符来解决此问题:

sed -e "s/'||char(10)||'/\n/g" < tempfile > tempfile_with_newlines