• daef (unregistered)

    kinda reminds me of oracle's "DUAL"... it IS there ;-)

  • Jo (unregistered)

    Well... I can see that most of that code does indeed make some warped sense. At least if you assume that the system should create tables as needed, maybe as some kind of upgrade script. I've seen worse things, along with their marginal justifications.

    But catching exceptions, showing an error box, and THEN CARRYING ON AS IF EVERYTHING HAD WORKED? That's not even marginally justifiable.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    So TRWTF is that this function doesn't return FILE_NOT_FOUND?

    Seriously, it is really amazing what kind of brillant crap people can come up with when they have no idea what they fuck they are doing.

  • Captcha:dignissim (unregistered)

    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?

  • sagaciter (unregistered) in reply to Captcha:dignissim

    The function looks if a table with the given name exists in the database. The result is first written into and the read from a helper table, which is created on demand. Obviously the developer did not know an easier way to get back the result of an "exists" test.

  • (cs)

    I don't mind the on-the-fly table creation. In that case you're basically faced with create the table or fail the whole task. If the table is not there what else could you do? There's also a certain amount of benefit to putting the table creation code with the code that accesses it--gather like stuff together.

    If creating the table isn't the right answer it almost certainly means the database needs to be restored from a backup and at that point it doesn't really matter what you do.

    The error handling, though, is utterly unjustifiable.

  • (cs) in reply to Captcha:dignissim
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    1. If the table doesn't already exist, create it
    2. If it's empty, then insert a row with 0, otherwise update all rows to contain 0
    3. If it exists, update all rows to contain 1
    4. Return the number in the first row
    5. If anything fails, then display a prompt but keep going
  • Anonymous Coward (unregistered) in reply to Captcha:dignissim
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    Sure thing. It's a function that [appears] to return a boolean indicating whether a table exists in the database.

    To do this:

    1. It checks to see if a table called "tblIsThere" exists. I'm saddened he didn't try to do this using recursion. If the table doesn't exist, he's making a sql string to create the table, with a single field, a BIT, named "isthere".

    2. He executes the Sql inside a try/catch. If it fails, he alerts that it failed .. and then continues like nothing happened.

    3. Then he updates the table, setting the value of isthere to 0. Again, inside a try/catch. Again, alerts if an exception is thrown and then continues like nothing is wrong.

    4. He then checks to see if the table exists, and if it does he's updating tblIsThere so that the isthere BIT is switched to 1. Again, same try/catch "trick".

    5. He then reads back the value of tblIsThere and returns the value of isthere, implicitly casting it as a booean

  • anony-mouse (unregistered) in reply to Captcha:dignissim
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?

    First it runs a query to see if the table tblIsThere exists; if it doesn't, it creates it.

    Then it sets the value of the first record of tblIsThere to 0.

    Then, it chekcs to see if the TableName string passed to the function exists as a table; if it does, it sets the first record's value of tblIsThere to 1.

    The function returns true/false depending on if TableName exists in the database.

  • (cs)

    Part of the implied WTF (which some have missed, or perhaps pretended to miss for the lulz) is that this is the only function that does anything with this table. There are some things that it could make sense for a program to test (whether it can reach the database server at all, whether it can create/insert/update tables) but this function and table would still be a WTF regardless.

  • LieutenantFrost (unregistered) in reply to Captcha:dignissim

    It makes my eyes bleed.

  • iToad (unregistered) in reply to emurphy
    emurphy:
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    1. If the table doesn't already exist, create it
    2. If it's empty, then insert a row with 0, otherwise update all rows to contain 0
    3. If it exists, update all rows to contain 1
    4. Return the number in the first row
    5. If anything fails, then display a prompt but keep going

    Too bad that this summary only appears here, instead of appearing as a comment at the beginning of the function.

  • Bill Clinton (unregistered)

    tblIsThere? That depends on what the definition of the word "Is" is.

  • SilentRunner (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL

    It's amazing what words some people will come up with when trying to communicate with educated people.

  • Tasty (unregistered) in reply to emurphy
    emurphy:
    Part of the implied WTF (which some have missed, or perhaps pretended to miss for the lulz) is that this is the only function that does anything with this table. There are some things that it could make sense for a program to test (whether it can reach the database server at all, whether it can create/insert/update tables) but this function and table would still be a WTF regardless.

    No, it never makes sense. Production code shouldn't execute DDL statements, with the rare exception of CREATE TEMP TABLE.

    One can test a program's database access and DML statement permissions by following them with a terminal SELECT. I don't think most live applications should have DDL permissions.

  • Anonymous (unregistered) in reply to daef
    daef:
    kinda reminds me of oracle's "DUAL"... it IS there ;-)

    Reminds me of that old trick to fool fellow developers:

    CREATE TABLE DUAL (id INT); INSERT INTO DUAL VALUES (1); INSERT INTO DUAL VALUES (2);

    Worked at least in Oracle 8 (might have gotten the CREATE TABLE wrong, but you get the point). Since then I always use "FROM SYS.DUAL" to be sure.

  • Stan (unregistered) in reply to Captcha:dignissim
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    It forces the next dev to use their source control system to find out who did this. The culprit is then visited with unspeakable horrors.
  • (cs) in reply to Stan
    Stan:
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    It forces the next dev to use their source control system to find out who did this. The culprit is then visited with unspeakable horrors.

    Of the lovecraftian kind of course, nothing like having fishy tentacled old ones to visit ones co-workers at night.

  • abigo (unregistered)

    SELECT * FROM commentIsThere If Count = 0 Then INSERT INTO commentIsThere (isthere) VALUES ('BRILLANT') Else UPDATE commentIsThere SET isthere = 'FILE_NOT_FOUND' End If

  • null (unregistered)

    This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)

  • Albert (unregistered) in reply to null
    null:
    This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.
  • Anonymous (unregistered) in reply to Albert
    Albert:
    null:
    This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.

    Nobody said that a boolean would be returned for UniverseIsThere. Clearly, it would have to be a string: "Maybe"

  • Silent D (unregistered) in reply to Albert
    Albert:
    null:
    This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.

    Obviously, UniverseIsThere must be able to hold the values 0, 1, or FILE_NOT_FOUND.

  • (cs) in reply to Silent D
    Silent D:
    Albert:
    null:
    This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.

    Obviously, UniverseIsThere must be able to hold the values 0, 1, or FILE_NOT_FOUND.

    Yes Impolemting the Trillian data type. We have booleans and we have enums, and I have choosen Trillian for the name of this type as a side reference to HHGTTG. Long live Douglas Adams!

  • (cs)

    The "developer" who wrote this code sure as hell isn't the type of developer to make use of unit testing (or, judging from the cls prefix, know anything about writing code from the last 10 years or so).

    The saddest part and for me TRWTF is that developers like this "developer" seem to be much more common than developers who do know what they are doing.

  • Nagesh (unregistered) in reply to SilentRunner
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
  • big picture thinker (unregistered) in reply to emurphy
    emurphy:
    Part of the implied WTF (which some have missed, or perhaps pretended to miss for the lulz) is that this is the only function that does anything with this table. There are some things that it could make sense for a program to test (whether it can reach the database server at all, whether it can create/insert/update tables) but this function and table would still be a WTF regardless.
    It could be just a script some dev wrote to test something and s/he never got rid of it. This is further indicated by the message boxes that are displayed showing direct SQL errors without any dumbed-down interpretation for end users. Not really a WTF to me.

    The only WTF in my mind is the isTableThere field. I hate it when people use tables to store info about tables. What's that called? Meta database? Database within a database? Something like that.

    CAPTCHA: ullamcorper

  • radarbob (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    So TRWTF is that this function doesn't return FILE_NOT_FOUND?

    Seriously, it is really amazing what kind of brillant crap people can come up with when they have no idea what they fuck they are doing.

    Mega-Dittos!

  • Jack (unregistered) in reply to big picture thinker
    big picture thinker:
    I hate it when people use tables to store info about tables. What's that called? Meta database? Database within a database? Something like that.
    Metadata should be stored in XML in case the database is down. Also this is a legitimate reason for production code to create tables. If you need to do a few queries you can cut the relevant portion out of the XML, load it into the database (there are libraries to make all this easy) do your business and then clean up those new tables and go on.
  • Meep (unregistered) in reply to Captcha:dignissim
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?

    The first half is typical VB drudgery to create objects and stuff to declare what you're obviously doing.

    Then they create the table if it doesn't exist, make sure that there really is a row in this table. And do some other stuff, and set the row to 0.

    Then they check whether some table exists, update isThere to 1 if it does, and request the value of the table.

    I guess it never occurred to the author to simply:

    SELECT COUNT(*) FROM INFORMATION_SCHEMA.blahblah WHERE table_name = ?

    Because the I_S views are magical or something, so you can't just query them?

  • Nagesh (unregistered) in reply to Meep
    Meep:
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?

    The first half is typical VB drudgery to create objects and stuff to declare what you're obviously doing.

    Then they create the table if it doesn't exist, make sure that there really is a row in this table. And do some other stuff, and set the row to 0.

    Then they check whether some table exists, update isThere to 1 if it does, and request the value of the table.

    I guess it never occurred to the author to simply:

    SELECT COUNT(*) FROM INFORMATION_SCHEMA.blahblah WHERE table_name = ?

    Because the I_S views are magical or something, so you can't just query them?

    Everyone ain't profesional DBA knowing how to masage querys.

  • (cs) in reply to Nagesh
    Nagesh:
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
    At that rate you should have a decent vocabulary in about 50 years.
  • Nagesh (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Nagesh:
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
    At that rate you should have a decent vocabulary in about 50 years.

    Indian ain't have shortened life span providing he stay away from massage in diarrhea food poisioning.

  • Diego (unregistered) in reply to Tasty

    Production code shouldn't execute DDL statements

    I couldn't agree more. Yet, I know of a certain individual who, when asked what would be the best way to implement a relationship such as "user->list of friends" (typical of a social network), recommended creating a separate table for each user. That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...

  • Jim (unregistered) in reply to Diego
    Diego:
    Production code shouldn't execute DDL statements

    I couldn't agree more. Yet, I know of a certain individual who, when asked what would be the best way to implement a relationship such as "user->list of friends" (typical of a social network), recommended creating a separate table for each user. That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...

    You laugh, but this really happened at my workplace recently. We were designing an inventory app where one object may have several associated people. (Car analogy: one car may have many drivers.) Mr. Genius proposed that a table for each person would be created when you log in to the app by selecting your records from the primary table.

    I asked what should happen when the user updates info on an item. Should the update go back into his own table or back to the master table? Yeah, he admitted, that could get complicated.

    So... ?

    Nothing.

    He could see a problem with his design, but could not back away from it or come up with any other solution. So he just stood there, silent, stuck at a mental dead end, without even the common sense to throw it in reverse.

    I guess this is the expected level of brainpower for a former Director of Big Things (recently demoted).

  • Scrummy (unregistered)

    One great thing (of many) about Agile is that it ushered in the code-first ORM era of development. That would surely have avoided such a ridiculous DB table.

  • Kasper (unregistered) in reply to Anonymous
    Anonymous:
    Reminds me of that old trick to fool fellow developers
    You won't fool me with that. I know for a fact that I have no clue what your code did.
  • Agention (unregistered) in reply to Bill Clinton
    Bill Clinton:
    tblIsThere? That depends on what the definition of the word "Is" is.

    The definition of "Is" is is is is is is.

  • (cs) in reply to Kasper
    Kasper:
    Anonymous:
    Reminds me of that old trick to fool fellow developers
    You won't fool me with that. I know for a fact that I have no clue what your code did.

    Oracle has a built-in system table named "dual" with exactly one row. (Unlike some DBMSes, Oracle emits a syntax error on any query or subquery that doesn't have a FROM clause, so a single-row table is useful for things like "SELECT current_date FROM dual" and "SELECT 1 FROM dual WHERE EXISTS (...)" and so on.) Anonymous' code would hide that table by creating a non-system table with that name . . . and it would put two records in that user table, thereby causing lots of queries to return the wrong number of rows.

  • YF (unregistered) in reply to Stan
    Stan:
    Captcha:dignissim:
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
    It forces the next dev to use their source control system to find out who did this. The culprit is then visited with unspeakable horrors.
    I use source control to find culprits... and I imagine the horrors they should suffer for every great display of stupidity... should I see a doctor, or a shrinker?
  • (cs) in reply to Silent D
    Silent D:
    Albert:
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.
    Obviously, UniverseIsThere must be able to hold the values 0, 1, or FILE_NOT_FOUND.
    ...or 42, don't forget!

    (Or perhaps the xkcd number; see http://xkcd.com/207/ )

  • Darth Paul (unregistered) in reply to Diego
    Diego:
    Production code shouldn't execute DDL statements

    I couldn't agree more. Yet, I know of a certain individual who, when asked what would be the best way to implement a relationship such as "user->list of friends" (typical of a social network), recommended creating a separate table for each user. That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...

    Given how badly the web interface is designed, I would not be surprised.

  • Rodd (unregistered) in reply to Diego
    Diego:
    Production code shouldn't execute DDL statements

    I couldn't agree more. Yet, I know of a certain individual who, when asked what would be the best way to implement a relationship such as "user->list of friends" (typical of a social network), recommended creating a separate table for each user. That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...

    If you think about what a table is in an abstract sense, this actually makes a lot of sense. You are storing a list of objects related to a main object, which might have extra properties (date when they became friends, type of relationship...). The problem is that the implementation is not designed for that.

  • (cs)

    It looks a bit like a broken semaphore: I.e., update to 1 to indicate that a process is running that can't be interrupted. Of course, nothing else checks the semaphore, including this routine, so all it really is, is one majorly incredible WTF.

  • Gyxi (unregistered) in reply to Albert
    If you've been paying attention to quantum theory you'd know that UniverseIsThere cannot be represented in a simple boolean.

    How about a nullable boolean then?

  • (cs) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Nagesh:
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
    At that rate you should have a decent vocabulary in about 50 years.
    Please... you're no new guy here, Pedobearmudgeon. That scarecrow is *not* worth a talk. He's not even a joke getting old, he deserves only one thing : to be shot with *the Ignore gun*.
  • Doctor_of_Ineptitude (unregistered) in reply to toshir0
    toshir0:
    PedanticCurmudgeon:
    Nagesh:
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
    At that rate you should have a decent vocabulary in about 50 years.
    Please... you're no new guy here, Pedobearmudgeon. That scarecrow is *not* worth a talk. He's not even a joke getting old, he deserves only one thing : to be shot with *the Ignore gun*.

    I was of the opinion that this particular scarecrow should be secured, delineated and segmented.

  • OptimalExpert (unregistered) in reply to Diego
    Diego:
    ... That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...

    Such is the professional practice of 'sharding' a database. It is best to put every user in her own virtual machine, so resource sharing is fair and can be managed by a hypervisor. I think friendship connections between users are represented by TCP sockets, so that messages can be exchanged easily. You see, this requires no traditional database at all!

  • (cs) in reply to Scrummy
    Scrummy:
    One great thing (of many) about Agile is that it ushered in the code-first ORM era of development. That would surely have avoided such a ridiculous DB table.

    Except shops such as the one that allows such a ridiculous DB table won't embrace Agile since ORMs mean you can't put everything in a stored procedure (and it means you gasp! have to recompile when the database changes!), and doing TDD means less time to sling code, and pair programming means you have half as many things going at the same time (because each task requires 2 programmers instead of one), and you can't bother the business users for requirements because they have "real" work to do...

  • Mongo (unregistered) in reply to toshir0
    toshir0:
    PedanticCurmudgeon:
    Nagesh:
    SilentRunner:
    It's amazing what words some people will come up with when trying to communicate with educated people.
    I am lern two in past weeks: "ain't" and "massage."
    At that rate you should have a decent vocabulary in about 50 years.
    Please... you're no new guy here, Pedobearmudgeon. That scarecrow is *not* worth a talk. He's not even a joke getting old, he deserves only one thing : to be shot with *the Ignore gun*.
    Agree, fake Nagesh is so lame, he doesn't deserve any attention.

    HEAR ME EVERYONE. I AM IGNORING FAKE NAGESH, I REPEAT, I AM IGNORING FAKE NAGESH. PAY NO ATTENTION TO HIM, JUST LIKE I AM DOING NOW.

Leave a comment on “tblIsThere”

Log In or post as a guest

Replying to comment #382569:

« Return to Article