如何在SQLite中插入新行("\ n")字符?

编程入门 行业动态 更新时间:2024-10-10 05:20:34
本文介绍了如何在SQLite中插入新行("\ n")字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在尝试插入类似内容时:

While trying to insert something like:

"Hello\nWorld"

SQLite会引发类似以下的错误:

SQLite throws error something like:

消息:无法识别的令牌:'Hello";"(还有其他一些错误)

Message: unrecognized token: "'Hello";" (also few other errors)

即使我将上面的字符串转换为"Hello''\nWorld"或"Hello\"\n\"World",这些转义字符序列在这种情况下也不起作用.

Even though I convert above string to "Hello''\nWorld" or "Hello\"\n\"World", these escape characters sequences don't work in this case.

当前使用C ++语言,我将像插入其他任何简单字符串列一样插入此列.我尝试了以上转义序列(即使我在Internet上阅读过,但它们不适用于\n).

Currently using C++ language, I am inserting this column like any other simple string columns. I tried above escape sequence (even though I read in internet that, they don't work with \n).

如何在SQLite DB中插入换行符和其他此类特殊字符?

How to insert new line and other such special characters in SQLite DB?

推荐答案

在SQL中,没有逃脱换行符的机制.您必须按原样插入它们:

In SQL, there is no mechanism to escape newline characters; you have to insert them literally:

INSERT INTO MyTable VALUES('Hello world');

或者,动态构造字符串:

Alternatively, construct the string dynamically:

INSERT INTO MyTable VALUES('Hello' || char(10) || 'world');

(换行符的类型(13或10或13 + 10)取决于操作系统.

(The type of newline (13 or 10 or 13+10) is OS dependent.)

将SQL语句嵌入C ++字符串时,在第一种情况下必须转义换行符:

When you embed the SQL statements in C++ strings, you have to escape the newline in the first case:

q1 = "INSERT INTO MyTable VALUES('Hello\nworld');"; q2 = "INSERT INTO MyTable VALUES('Hello' || char(10) || 'world');";

更多推荐

如何在SQLite中插入新行("\ n")字符?

本文发布于:2023-10-26 18:07:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   如何在   SQLite   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!