在新换行/换行符之前的MS SQL反斜杠可删除换行符 [英] MS SQL Backslash preceding new line/line feed removes line break
问题描述
我正在使用经典ASP,并且试图将一些用户输入简单地插入到我的MS SQL 2008数据库中.这基本上是我每天都会做的事情,但是我认为我以前从未遇到过该错误.
I'm working in classical ASP and am trying to simply insert some user input into my MS SQL 2008 database. This is something I do basically every day, but I don't think I've ever experienced this bug before.
我得到的错误是,如果用户在反斜杠处结束一行文本,然后在下面开始新行,则将数据存储在数据库中后,反斜杠和换行符都会丢失.
The bug I am getting is that, if a user ends a line of text in backslash, and starts a new line below, both the backslash and line break are lost after the data is stored in the DB.
如果我尝试从ASP文件进行硬编码的以下语句:
If i try the following statement, hardcoded from an ASP file:
UPDATE TBLarticle_text SET Introduction = 'Text on first line \" & vbCrLf & " text on second line' WHERE ArticleGuid = 28
结果数据没有反斜杠或换行符.如果将字符串存储在变量中并打印在页面上,则该字符串是正确的.
The resulting data is without the backslash or the line break. The string is correct if stored in a variable and printed on the page.
这是示例用户输入(通常从表单输入,但实际上并不相关).输入:
Here is the example user input (normally from a form, but it's not really relevant). The input:
Text on first line \
text on second line
...存储为:
Text on first line text on second line
如果反斜杠后面跟有换行符,那么我看不到任何问题.
I don't see any issues if the backslash is followed by anything other than a line break.
推荐答案
我知道这很旧,但是我刚看到一篇MS KB文章对此进行了讨论:
I know this is old, but I just came across a MS KB article that discusses this: http://support.microsoft.com/kb/164291/en-us. The long and short of it is that the three characters \<CR><LF>
together is some weird escape sequence, and you need to replace all occurrences of \<CR><LF>
with \\<CR><LF><CR><LF>
when inserting or updating because the first backslash in \\<CR><LF><CR><LF>
escapes the weird escape sequence, i.e. the next three characters \<CR><LF>
, and then the additional <CR><LF>
puts the carriage return back in place. Annoying, yes.
这篇关于在新换行/换行符之前的MS SQL反斜杠可删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!