Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Subtle Line Feed / Carriage Return issue


Subtle Line Feed / Carriage Return issue

Author
Message
seebert42
seebert42
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 34
Bug must be fixed in 2008:
What you see...
-----------------------
print 1
-- Comment one
print 2
-- Comment two
print 3
-- Comment three
print 4
is not what you get!
-----------------------
1
2
3
4
seebert42
seebert42
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 34
Only if you've failed in the server patch department- this was fixed SQL Server 2005 SP1
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21137 Visits: 18259
Thanks for the question. It would have been nice to have something a little more current.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

jts2013
jts2013
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1176 Visits: 5009
I also got 1,2,3,4 so not sure what the question was trying to show - no bug here!
danschl
danschl
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1388 Visits: 644
the question would have been alright in 2005 when that was an issue

so the only people to get the question right were people have fully patched sql 2005



seebert42
seebert42
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 34
Just the opposite- If you FAILED to patch your server, you got this quesiton right- and failed to patch it EVER since this was fixed in SP1.

Still, interesting behavior for the compiler when dealing with line comments. And I'm willing to bet there are MANY other compilers out there, for a variety of languages, that don't recognize CR/LF, CR, AND LF (sorry, I'm old enough to remember Epson printer coding in the late 1970s- I will NEVER see char(10) as NL instead of LF, even though they have the same meaning- new line or line feed) as end of line. And for those who are actually coding compilers, it's a darn good lesson to remember to test for all three as end of line.
Dena Edwards-446268
Dena Edwards-446268
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 12
What I got out of this question is that it shows there once was a bug in SQL2K, which was corrected with SP updates years ago. I usually walk away with learning something from the questions, but this one feels like a waste of time.

I have access to a SQL2K, SP4 server with Query Analyzer as well as SQL2K5 9.0.3054 with Management Studio 2005. In both instances I get the following:


What you see...
-----------------------
print 1
-- Comment one
print 2
-- Comment two
print 3
-- Comment three
print 4

is not what you get!
-----------------------
1
2
3
4

arthur.teter
arthur.teter
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1193 Visits: 122
Not sure what system the author ran the script on, but I ran it in Management Studio 2005 version 9.00.1399.00 and got 1,2,3,4. Also ran it in Management Studio 2008 and got 1,2,3,4.
Rune Bivrin
Rune Bivrin
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3730 Visits: 1466
While I find the question slightly pointless, I have to say I'm more than a little surprised that so many got it wrong. The question made it perfectly clear that 1,2,3,4 wouldn't be correct.

As an old hand (and C programmer to boot) I remember quite well that line feed is the most "functional" line separator. That made it resonable to guess the '2' would fall prey to the one line comment.


Just because you're right doesn't mean everybody else is wrong.
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10769 Visits: 12019
stewartc-708166 (12/23/2010)
Tom.Thomson (12/23/2010)
stewartc-708166 (12/23/2010)
Having investigated this further, I have found that the "correct" answer occurs on SQL2000 and SQL2005 RTM.
this was registered as a bug and repaired with CU2 of SQL2005 (also included in service pack 1).


So MS had it right (CR does not terminate a -- comment) and some nitwit reported this as a bug and MS was sufficiently stupid to "fix" it? Oh mo chreach!

par for the course....
CR was a placemarker character, left over from the old typeset days, which told the typesetter to go to the begining of a line (or the first available space thereafter). It was thus used in conjunction with the NL character which, without it, would cause the cursor to go to the next line, but continue from the same position.

Not quite, because NL and LF are not the same character and ASCII has no NL character (the reference to the old typeset days is incorrect too - there was no CR in manual typesetting, although there was in typing).

Back in the bad old days (early 60s, before there were reasonable coding standards) encoding standards were going in two directions: IBM was devising 8-bit EBCDIC (based on IBM's 6-bit BCD) while ECMA and ASA were devising 7-bit ECMA-6 and 7-bit ASCII (with only very minor differences) mainly based on ECMA-1 (another 6 bit code) with noticeable influence from the CCITT coding standard for control characters. The ASCII and ECMA 7 bit codes were convenient for transmission using 7 bits (either with a parity bit added to improve error detection or without to get a 12.5% required bandwidth reduction) , while IBM's 8-bit code wasn't but could represent more characters. But the part of this divergence that affects the discussion here was that the two groups (IBM and followers with EBCDIC, the rest with ASCII/ECMA) had different views of line feed, carriage return, and newline: ASCII had only the first two characters (CR and LF) while EBCDIC had all three. This gave EBCDIC barrel printers (using NL) a tiny advantage over ASCII barrel printers (using CR-LF) which caused some people to start treating ASCII LF as if it were NL, to recover this tiny edge, but in fact that gave EBCDIC printers a different advantage of ASCII barrel printers which did this (because they now had to received LF plus a wodge of spaces where the EBCDIC printers just needed LF).

It is incorrect for a parser to treat CR as End of Line in either ASCII or EBCDIC, because it provides for overprinting on the same line; in some languages this is irrelevant, because EoL never has any syntactic significance beyond being white space, so no EoL detection is needed anyway and the parser doesn't detect EoL; in the case of SQL, CR provides for overprinting in a comment introduced by --, and in the context of a comment introduced by -- EoL has syntactic significance beyond being white space so the parser has to detect it. MS treating CR as EoL in this context is a bug; it is not and never was a bug fix, it was a foolishly introduced bug which spoiled previously correct code.

Tom

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search