开发者

Strange issue in SQL Management Studio IDE with CR instead of 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:

Strange issue in SQL Management Studio IDE with CR instead of CRLF

Now I know how to modify the build scri开发者_StackOverflow社区pts 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜