Newlines: Migration from MySQL to SQLite

折月煮酒 提交于 2020-01-17 02:17:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!