问题
Currently I am facing the issue that newlines from a MySQL dump will be ignored when I put the data in a SQLite database. The "\r\n", which MySQL dumps, interprets SQLite as a string, so I have sentences like "nomnomnom\r\n nomnomnom" in the application instead of "nomnomnom
nomnomnom".
So my question is what have I to do that SQLite reads the linebreaks correctly? I have already googled a lot to find out what kind of newline syntax SQLite needs but to my surprise I haven't found any clear answer.
回答1:
SQL has no backslash escapes (this is a MySQL quirk).
To convert the MySQL dump into real SQL, use an editor or some script to convert these escape sequences:
\n -> new line
\r -> carriage return
\" -> "
\' -> '' (inside strings)
(In SQL strings, every character except '
is interpreted literally.)
For example, this command:
INSERT INTO MyTable VALUES('nomnomnom\r\n nomnomnom');
would be converted into this:
INSERT INTO MyTable VALUES('nomnomnom
nomnomnom');
Alternatively, you could insert control characters using SQL functions:
INSERT INTO MyTable VALUES('nomnomnom' || char(13) || char(10) || ' nomnomnom');
来源:https://stackoverflow.com/questions/24626296/newlines-migration-from-mysql-to-sqlite