• Alargule (unregistered)

    Wow...1600 words a minute!

  • Mr. TA (unregistered)

    That's huge.

  • Rob (unregistered)

    My eyes are bleeding.

    CAPTCHA: conventio (which is what this line of code defies)

  • John (unregistered)

    Added for "clarity" you say? There is no clarity for something like that.

  • Usher (unregistered)

    I noticed that 'RECIEVE' is spelled wrong...I wonder if it even worked.

  • HonoredMule (unregistered)

    This is actually quite efficient. It describes the system in only 1,240 words. But I think I can clean it up a bit more, condensing it to one word:

    Augh!

  • Jorma Rebane (unregistered)

    Now that's TRWTF.

    How are systems like that able to work at all? Looks very enterprisey though...

  • (cs)

    And yet, there are "senior developers" out there who swear by doing things like this, or by setting the CommandText property of a SqlCommand, and wonder what's all the hullabaloo about these fancy "ORM" things, and why did Microsoft bother to add in Linq to SQL or Entity Framework at all.

  • Robyrt (unregistered)

    But imagine how easy this is to deploy! Just update one line in a config file and you're good to go!

  • Richard (unregistered)

    If you can pull everything you need in a single, guaranteed-consistent FETCH from the database, especially if its done a whole lot, that's not necessarily a WTF.

    Sure, there's a lot of legacy-isms in there, but you might be looking at something that cut a two minute process with a ton of stupid SQL calls into a sub-second 250 line one.

    Although the homegrown reverse polish in the resulting column names is unfortunate - and the massive REPLACE nest is probably optimizable at least.

  • (cs)

    If you had something that ugly in your codebase, wouldn't you hide it in a config file too?

  • Jason Y (unregistered)

    I think it's better to go ahead and refactor as you go, making the code self-documenting, than to try documenting nasty code. You shouldn't use it prior to refactoring because programming against a well-documented mess is less productive than refactoring the mess to something clean and then programming against it. Simple, clean interfaces / contracts are more important than documentation, imo.

  • Richard (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    And yet, there are "senior developers" out there who swear by doing things like this, or by setting the CommandText property of a SqlCommand, and wonder what's all the hullabaloo about these fancy "ORM" things, and why did Microsoft bother to add in Linq to SQL or Entity Framework at all.
    If its SOP for the whole system? Yeah, that's bollocks. But pulling a query like this through an ORM system would probably take minutes.

    Disclaimer: we use ORM all over the place where it doesn't matter (GUIs, etc). We also generate massively-joined reporting queries and have a few hand-written 80LOC queries where it does (although nothing quite on this scale).

  • commoveo (unregistered)

    Shirley this is not possible. You can't put CDATA in an XML attribute, can you?

    However, seeing as this is a .config file, one would reckon that this was an auto-generated file in a proprietary format that places the value of the DB query in an ultimately-generated XML file. Now let's conjecture that regular expressions are not supported... . . . Not a wtf?

  • Mordred (unregistered)

    It's called job security Doggs. Actually i dont think it was written by a person. It looks like it is some of that automated code that gets written like in Macromedia.

  • Two (unregistered)

    Ze goggles! They do nothing!

  • jrh (unregistered) in reply to Richard
    Richard:
    If you can pull everything you need in a single, guaranteed-consistent FETCH from the database, especially if its done a whole lot, that's not necessarily a WTF.

    You've heard of stored procedures right? Well that is where any chunk of SQL code this long belongs. And while you're in there, you might be able to break it down into a few more logical steps, maybe use a temp table or a union.

    This code has no place in a config file.

  • (cs)

    My favorite part:

    CASE substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( Documents.Destination,' ',''),')',''),'(',''), '-',''),'/',''),'.',''),'*',''),',',''),';',''), '\',''),'-',''),1,1) WHEN '1' THEN substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*',''), ',',''),';',''),'\',''),'-',''), 2, len( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*','') ,',',''),';',''),'\',''),'-','')) ) ELSE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE(Documents.Destination,' ',''),'-',''),')', ''),'(',''),'/',''),'.',''),'*',''),',',''),';',''),'\',''),'-','')

    I 'd like to think that this replaces all smilies into frowns into tears.

  • (cs) in reply to jrh
    jrh:
    You've heard of stored procedures right? Well that is where any chunk of SQL code this long belongs. And while you're in there, you might be able to break it down into a few more logical steps, maybe use a temp table or a union.

    This code has no place in a config file.

    Ah, but having that SQL in a Sproc prevents the end user from changing a field, and the CEO must be able to customize the queries if he sees fit, at any time.

  • (cs)

    In a config file?! Good grief. This is what the Windows Registry is there for people!

  • WC (unregistered) in reply to commoveo
    commoveo:
    Shirley this is not possible. You can't put CDATA in an XML attribute, can you?

    However, seeing as this is a .config file, one would reckon that this was an auto-generated file in a proprietary format that places the value of the DB query in an ultimately-generated XML file. Now let's conjecture that regular expressions are not supported... . . . Not a wtf?

    And don't call me Surely.

  • (cs)

    Besides the replace madness, what's the problem?

    Placing an SQL query in a config file? Maybe not the 'INDUSTRY STANDARD' (ohh beware the industry standard!), but not a wtf.

    The length of the query? Has nobody else had to write a complex query that included multiple tables?

    Maybe I'm not looking closely enough at the code.

  • (cs) in reply to amischiefr

    Correct me if I'm wrong but wouldn't the proper way of writing "a complex query that included multiple tables" be to abstract things out into Views or Functions? The method shown is little more than spaghetti code.

  • (cs)

    Does this even work? It appears to be an SQL query but it has C-style comments inside it!

  • (cs) in reply to mott555
    mott555:
    Does this even work? It appears to be an SQL query but it has C-style comments inside it!

    As we say in MMOs: "wat"

    C-style comments work perfectly fine within SQL. I really hope this comment was a joke.

  • Vinny (unregistered) in reply to Jason Y

    No. The best way to deal with this is to go work somewhere else.

  • KaiseanGames (unregistered)

    If this was all in one line, it sure is some nice example of the code obfuscation. :D

  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    mott555:
    Does this even work? It appears to be an SQL query but it has C-style comments inside it!

    As we say in MMOs: "wat"

    C-style comments work perfectly fine within SQL. I really hope this comment was a joke.

    I honestly didn't know C-style comments worked in SQL. Learned something new today.

  • (cs)

    I can understand the need for a single huge complex multi-table query - legacy crap is a fact of life. As others have pointed out, it might even be more efficient that multiple simple queries (databases are pretty good at optimizing so-so queries; even complex ones). I can even see the need for the nested replaces under certain circumstances (though probably a little hard to justify).

    But all that on one long line?

  • (cs) in reply to mott555
    mott555:
    I honestly didn't know C-style comments worked in SQL. Learned something new today.

    You're forgiven :)

  • by (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    Correct me if I'm wrong but wouldn't the proper way of writing "a complex query that included multiple tables" be to abstract things out into Views or Functions? The method shown is little more than spaghetti code.

    Views and functions can't be indexed (at least not views that come from more than one table, which defeats the purpose of views IMO)... At least if it's a join, the query optimizer may be able to make the query a little more effecient than it is written.

    The REPLACE functions are WTF, but lets not forget the SQL injection possibility here (check the last WHERE clause).

    I've seen stuff like this before, and it's terribly ineffecient. It looks like they're trying to generate massively complex reports (which obviously isn't a bad thing) from an RDB, likely a live application DB. This screams for OLAP or data warehousing... It's funny because this is the result of "business" wanting "up-to-the-second, real-time" reporting (which is never used). Then they cringe when someone generates a report that takes 8 minutes to create, which kills performance across the rest of the application.

  • TheAngryBeast (unregistered)

    Ouch. That, my friends is A config!

    the actual program is probably actually like this:

    void Main() { string sql = Application.Config.Get(sqlSource);
    Console.WriteLine("Results: {0]", db.Execute(sql));
    

    }

    Excuse my syntax errors, I haven't done .NET in a while

    captcha: ideo

  • Harvey (unregistered)

    I don't think this guy ever heard of stored procedures or functions in SQL.

  • (cs)

    On the plus side, they aren't finishing the whole thing off with a GROUP BY. I've had to work with queries that have a hundred elaborate SELECT columns with most of them reappearing in their entirety in the GROUP BY clause.

    I would say that Aaron should be thankful, but something tells me such a query probably lurks elsewhere in his codebase or config files.

  • (cs) in reply to renewest
    renewest:
    My favorite part:
    CASE substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( Documents.Destination,' ',''),')',''),'(',''), '-',''),'/',''),'.',''),'*',''),',',''),';',''), '\',''),'-',''),1,1) WHEN '1' THEN substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*',''), ',',''),';',''),'\',''),'-',''), 2, len( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*','') ,',',''),';',''),'\',''),'-','')) ) ELSE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE(Documents.Destination,' ',''),'-',''),')', ''),'(',''),'/',''),'.',''),'*',''),',',''),';',''),'\',''),'-','')

    I 'd like to think that this replaces all smilies into frowns into tears.

    That would explain why, after seeing this code, my facial expression changed from frowning to crying.

  • (cs) in reply to WC
    WC:
    And don't call me Surely.

    Don't be so surly.

  • frits (unregistered)

    Who hasn't done something like this?

  • (cs) in reply to Harvey
    Harvey:
    I don't think this guy ever heard of stored procedures or functions in SQL.

    Or maybe he had heard of stored procedures, but he just didn't know where they get stored and so opted for a config file.

  • by (unregistered) in reply to Severity One
    Severity One:
    renewest:
    My favorite part:
    CASE substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( Documents.Destination,' ',''),')',''),'(',''), '-',''),'/',''),'.',''),'*',''),',',''),';',''), '\',''),'-',''),1,1) WHEN '1' THEN substring(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*',''), ',',''),';',''),'\',''),'-',''), 2, len( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE( REPLACE(REPLACE( REPLACE(Documents.Destination,' ',''),')', ''),'(',''),'-',''),'/',''),'.',''),'*','') ,',',''),';',''),'\',''),'-','')) ) ELSE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE(Documents.Destination,' ',''),'-',''),')', ''),'(',''),'/',''),'.',''),'*',''),',',''),';',''),'\',''),'-','')

    I 'd like to think that this replaces all smilies into frowns into tears.

    That would explain why, after seeing this code, my facial expression changed from frowning to crying.

    :`-(

  • Tim Rowe (unregistered)

    It would be easy to prevent code like that. Pay programmers by the line.

    Of course, that has other problems.

  • (cs)

    Well, I guess that's one way to store a procedure...

  • (cs) in reply to by
    by:
    Views and functions can't be indexed...
    Not so. Several databases do support indexing functions/expressions, and some even support indexes on views.
    by:
    ...(at least not views that come from more than one table, which defeats the purpose of views IMO)... At least if it's a join, the query optimizer may be able to make the query a little more effecient than it is written.
    I believe that in most cases (if not all), the view becomes part of the query, so it's fair game for the optimizer as well. Views don't typically store data, just the SQL that identifies them, so the optimizer must parse the view as well as the rest of the query.

    Of course this means that views generally don't need indexes, because the underlying (multiple) tables' indexes are at the optimizer's disposal.

  • pjt33 (unregistered) in reply to amischiefr
    amischiefr:
    Besides the replace madness, what's the problem?
    There are at least three replace madnesses.
    1. The processing of Documents.Destination
    2. The injection-vulnerable use case which must surely lie behind REPLACE_NUMBER_OF_ROWS_TO_RETRIEVE and REPLACE_WHERE_CLAUSE_CRITERIA.
    3. The hard-coded values in e.g. REPLACE(DTConfigurations.ImageDir, 'D:\Data', '\'+ServerName)
  • (cs)

    Omg omg omg omg! It hurts so bad. Make the bad man stop!!!!!

  • Michal Kočárek (unregistered)

    This is crazy... They are BREAKING UP the string as part of a JOIN... Why bothering having more columns, when we can have all the data in one

    LEFT OUTER JOIN Globalization HistoryGeneric_Detail ON HistoryGeneric_Detail.Namespace = 'RightFax.SQL.HistoryGeneric' AND SUBSTRING(HistoryGeneric_Detail.LocKey,5,20) = 'DetailMsg' AND SUBSTRING(HistoryGeneric_Detail.LocKey,1,3) = CAST(HistoryGeneric.GenType AS varchar) AND HistoryGeneric_Detail.IsoLanguageName = 'en-us'
  • (cs) in reply to amischiefr
    amischiefr:
    Besides the replace madness, what's the problem?

    Placing an SQL query in a config file? Maybe not the 'INDUSTRY STANDARD' (ohh beware the industry standard!), but not a wtf.

    The length of the query? Has nobody else had to write a complex query that included multiple tables?

    The problem is that putting a large, complex SQL query on a single line in a config file is basically a giant "fuck you" to the developers who inherit it later.

  • (cs) in reply to Lockwood
    Lockwood:
    Omg omg omg omg! It hurts so bad. Make the bad man stop!!!!!

    Okay, Lockwood, show us on the doll where the bad SQL touched you.

  • Jamie (unregistered) in reply to Mr. TA

    That's what she.. wait, I mean, I've seen worse in a shop near and dear to my heart.

  • Childish (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    mott555:
    Does this even work? It appears to be an SQL query but it has C-style comments inside it!

    As we say in MMOs: "wat"

    C-style comments work perfectly fine within SQL. I really hope this comment was a joke.

    Actually, SQL doesn't have C-style comments. SQL allows nested multi-line comments. The following would break an ANSI-C compiler, but not SQL:

    /* Comment 1: /* comment 2: this is nested. */ This is my main comment. */

  • electric boogaloo (unregistered)

    I'm pretty sure if I worked with the author of this monstrocity, I would have shocked him repeatedy with a cattle prod.

Leave a comment on “All In The Config”

Log In or post as a guest

Replying to comment #:

« Return to Article