SQL Management Studio IDE 中使用 CR 而不是 CRLF 的奇怪问题
我遇到了一个关于在 SQL 语句末尾放置返回字符的奇怪功能(可能与 SQL Management Studio 有关)。虽然查询在 ID 内运行得很好,但相关功能破坏了我们的部署脚本。
本质上,由于某种原因,某些行被看起来像回车符 (CR) 而不是 CRLF 的内容终止,如下面两个文件之间的差异所示:
现在我知道如何修改构建脚本来捕获此问题,但我很好奇这是如何引起的。究竟如何使用 CR 字符来代替 CRLF 字符?
有人想吗?
I've encountered a strange feature (that may be related to SQL Management Studio) with regard to the placement of return characters at the end of SQL Statements. Whilst the query runs just fine within the ID, the feature in question was breaking our deployment scripts.
Essentially, for some reason, certain lines were being terminated by what looked like a Carriage Return (CR) instead of a CRLF, as can be seen in the diff between two files below:
Now I know how to modify the build scripts to catch this, but I was curious as to how this was being caused. How on earth would a CR character be used in place of a CRLF character?
Thoughts anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ANSI->统一码转换? UNIX-> Windows 转换?例如,您可能在另一个编辑器中对其进行了编辑并保存,并以 UNIX 格式保存。
ANSI -> Unicode conversion? UNIX -> Windows conversion? Chances are, you edited it in another editor and saved it and it saved in a UNIX format, for example.
这正是今天发生在我身上的事情,经过一番调查后,我发现了一些细节:
我在同事的机器上使用了与常用编辑器不同的编辑器。我习惯了 EditPlus,这是 Notepad++(我认为)。经过一些编辑后,我将一些代码复制到 MSSMS 中,然后进行更多编辑,然后保存为 .sql 文件。然后稍后,当打开文件时,我收到有关 cr/lf 问题的警告。使空白字符可见后,我注意到大多数行都是 cr/lf,但只有少数行是 lf。
事实证明,当我在 Notepad++ 中时,我进行了搜索并替换了“><”与“>\n<” (将 html 标签分隔成新行),在 Notepad++ 中“\n”表示“lf”,而在 editplus 中“\n”表示“换行”(无论您的文件当前使用什么,通常是“crlf”)。
有趣的是,MSSMS 允许我毫无怨言地保存这个混合文件。
因此,教训是,当使用类似正则表达式的表达式进行搜索和替换时,像 \n 这样的常见内容可能在不同的编辑器中以不同的方式实现
This is exactly what happened to me today and after a little investigating I found a few details:
I was using a different editor to my usual one on colleague's machine. I'm used to EditPlus and this was Notepad++ (i think). After a little editing I copied some code into MSSMS, then a bit more editing, then saved as .sql file. Then sometime later when opening the file I got the warning about cr/lf issue. After making the whitespace chars visible I noticed that most lines were cr/lf but just a few were lf only.
Turns out that while I was in Notepad++ I did a search and replace on "><" with ">\n<" (separate html tags into new lines) and in Notepad++ "\n" means "lf" whereas in editplus "\n" means "newline" (whatever your file is currently using, so normally "crlf").
Interestingly MSSMS allowed me to save this hybrid file without any complaints.
So, the lesson is when doing search and replace using regex-like expressions, common things like \n may be implemented differently in different editors