• (cs)

    ... does that code turn into an ASCII art magic-eye picture if you use a monospaced font?

    there has to be some sort of a redeeming quality to it :(

  • Dr. Evil (unregistered) in reply to AshG
    AshG:
    Dr. Evil:
    When I read this first thing this morning, I let out an audible long and drawn out UUUUUUUUUUUUUUUUUUGH... Everybody was looking at me so I had to act like I messed something up.
    The real WTF is working at a place where EVERYBODY will look at you. What do they practice there, a zealous agile/extreme methodology up to placing everyone in a room facing each other? Are farts allowed?

    I am just VERY handsome.

  • RefactoringThisCode (unregistered)

    Yes this code is real.

    Props to the guy who recognized this is a table from Solomon. Or rather Microsoft Dynamics SL now. More importantly, this code was expensive!! And still sold as way to easily and safely interface with MS Dynamics SL.

  • code_guy (unregistered)

    This is funny! Solomon code. Recognized it right away.

  • Daniel Stewart (unregistered)

    That is a perfect example of how code should be written... i write code like that all the time

  • mara (unregistered)

    I think it's a generated code.

  • (cs)

    Microsoft SQL Server has a callable routine that will double the quotes and stuff. I'm sure the other dialects of SQL have the same thing.

  • (cs) in reply to SenTree
    SenTree:
    wtf!:
    "There are almost an infinite number of ways to perform any task; yet, there is only one best way. That is, our chances of guessing the correct way is basically zero. Nature has endowed us with “intuition” which quickly gives us a workable solution – one which is usually better than most solutions. However, among all possible solutions, there is only one best method. Since the intuitive solutions are generally arrived at quickly with insufficient information, they are seldom optimum. Therefore, your chances of hitting the optimum method using intuition are very low." Chang, Fundamentals of Piano Practice
    However, a rapidly-conceived intuitive solution which allows the monkey to escape the lion is far more useful than an elegant optimum solution resulting in a well-fed lion.
    <snipped multiple comments>
    Well, that was a lot of wilful misinterpretation of both the OP and my throwaway comment. Are all you unregistered cowards feeling better now ?
  • Unix Dev Head (unregistered)

    He would be fired!

  • JayC (unregistered) in reply to bjolling
    bjolling:
    asdf:
    static public string SqlList(params object[] values) {
    	StringBuilder sb = new StringBuilder;
    	bool first = true;
    	for (object value in values) {
    		if (!first) sb.Write(", ");
    		first = false;
    		if (value is string) sb.Write("'"+((string)value).Trim().Replace("'","''")+"'");
    		else if (value is decimal || value is int || value is float || value is double) sb.Write(value.ToString());
    		else throw new NotSupportedException("Unexpected value type: " + typeof(value));
    	}
    	return sb.ToString();
    }
    Nooooo! You're doing it wrong.
    if (!first) sb.Write(", ");
    Don't waste time checking this inside the loop. Just ALWAYS add a comma at the END of the string and once you leave the loop, just strip the last one off again.

    You do realize with the very act of stripping the last ", " from an immutable string, you now have created TWO gigantic strings, instead of one. The only way I can see that NOT happening would be if there's some way to "strip" or "shorten" the stringbuilder before you call sb.ToString() or during some call that converts to a string without the last two or so characters, in which case I'd agree with you. Otherwise there's nothing wrong with the above code.

  • (cs)

    TRWTF is the incorrect line wrapping and the redundant parentheses.

    return str + "'" + this.Acct.Replace("'", "''") + "', " + "" + this.AcctDist.ToString().Trim() + ", " + "'" + this.BatNbr.Replace("'", "''") + "', " + ...

    Doing it this way makes it clear that the text types have an extra single quote at the front and the back, and internal single quotes doubled up; numeric types are ToString()'d.

    OK, maybe .ToString().Trim() is a WTF. Why would you need to Trim()? Even if ToString() somehow added spaces to the number, the SQL would ignore them.

    Adding the blank strings is also a little strange.

    But if you're going to add line breaks, do it right.

  • (cs) in reply to JayC
    JayC:
    bjolling:
    asdf:
    static public string SqlList(params object[] values) {
    	StringBuilder sb = new StringBuilder;
    	bool first = true;
    	for (object value in values) {
    		if (!first) sb.Write(", ");
    		first = false;
    		if (value is string) sb.Write("'"+((string)value).Trim().Replace("'","''")+"'");
    		else if (value is decimal || value is int || value is float || value is double) sb.Write(value.ToString());
    		else throw new NotSupportedException("Unexpected value type: " + typeof(value));
    	}
    	return sb.ToString();
    }
    Nooooo! You're doing it wrong.
    if (!first) sb.Write(", ");
    Don't waste time checking this inside the loop. Just ALWAYS add a comma at the END of the string and once you leave the loop, just strip the last one off again.

    You do realize with the very act of stripping the last ", " from an immutable string, you now have created TWO gigantic strings, instead of one. The only way I can see that NOT happening would be if there's some way to "strip" or "shorten" the stringbuilder before you call sb.ToString() or during some call that converts to a string without the last two or so characters, in which case I'd agree with you. Otherwise there's nothing wrong with the above code.

    Perl FTW: return join(",", map { ... } @values);

  • (cs)

    was that ASCII art?

  • (cs) in reply to kastein
    kastein:
    ... does that code turn into an ASCII art magic-eye picture if you use a monospaced font?

    there has to be some sort of a redeeming quality to it :(

    beat me to it :-)

  • (cs) in reply to Code Dependent

    Dude, that's THREE words! ;)

  • Awkward Silence (unregistered) in reply to Anonymous Coward

    Actually, it is in alphabetical order because the data comes from Solomon Accounting, which puts all its fields in alphabetical order.

  • hans (unregistered)

    "Our Senior Architect..."

    How does someone with so little skill end up senior? There has to be more to the story.

  • Snaphoo (unregistered) in reply to charlieo

    I think you're right.

  • (cs) in reply to Ken

    Death by parenthesis! Join me, fellow abused enclosing-thingies and have our rightous revenge now! ATTACK! Die, you ingorant fool, for you have misused us for the last time! Die twice already, come on! (Heard at The Battle Of The Parenthesis. The one who wrote this code lost the battle. And thus, the war.) (In this case. :)

  • Marcipicus (unregistered)

    Good thing they added the line breaks. I wouldn't have a clue what this did otherwise.

  • (cs)

    I can see why some people get suicidal tendencies...

Leave a comment on “The SQL String”

Log In or post as a guest

Replying to comment #:

« Return to Article