问题
I'm trying to do a clean export-import of a malformed sqlite file.
Using info from techblog.dorogin.com/sqliteexception-datab..., this is what I did sqlite3 oldfile
:
.mode insert
.output tempfile
.dump
Then I created a new sqlite3 newfile
:
.read tempfile
Error:
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)
In the output file, my maximum line is 35737 chars.
How can I fix this error?
What are some solutions to do a clean export-import of a malformed sqlite file?
回答1:
This is due to a change in version 3.18.0's 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.
If there are too many newline characters in a single string value, the resulting SQL expression becomes too complex.
This was fixed in version 3.19.0. If you are still using 3.18.0, you can work around this by converting the file to use raw newlines instead:
sed -e "s/'||char(10)||'/\\n/g" < tempfile > tempfile_with_newlines
来源:https://stackoverflow.com/questions/43145117/sqlite-error-expression-tree-is-too-large-maximum-depth-1000