tblIsThere

« Return to Article
  • daef 2012-06-04 10:24
    kinda reminds me of oracle's "DUAL"... it IS there ;-)
  • Jo 2012-06-04 10:29
    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 2012-06-04 10:34
    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 2012-06-04 10:37
    I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
  • sagaciter 2012-06-04 10:46
    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.
  • Loren Pechtel 2012-06-04 10:46
    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.
  • emurphy 2012-06-04 10:48
    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 2012-06-04 10:48
    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 2012-06-04 10:50
    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.
  • emurphy 2012-06-04 10:53
    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 2012-06-04 10:55
    It makes my eyes bleed.
  • iToad 2012-06-04 11:17
    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 2012-06-04 11:17
    tblIsThere? That depends on what the definition of the word "Is" is.
  • SilentRunner 2012-06-04 11:17
    It's amazing what words some people will come up with when trying to communicate with educated people.
  • Tasty 2012-06-04 11:18
    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 2012-06-04 11:18
    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 2012-06-04 11:19
    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.
  • KattMan 2012-06-04 11:42
    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 2012-06-04 12:24
    SELECT * FROM commentIsThere
    If Count = 0 Then
    INSERT INTO commentIsThere (isthere) VALUES ('BRILLANT')
    Else
    UPDATE commentIsThere SET isthere = 'FILE_NOT_FOUND'
    End If
  • null 2012-06-04 12:30
    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 2012-06-04 12:33
    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 2012-06-04 13:04
    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 2012-06-04 13:07
    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.
  • KattMan 2012-06-04 13:11
    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!
  • ObiWayneKenobi 2012-06-04 13:23
    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 2012-06-04 13:23
    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 2012-06-04 13:25
    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 2012-06-04 14:03
    ¯\(°_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 2012-06-04 14:12
    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 2012-06-04 14:39
    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 2012-06-04 14:48
    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.
  • PedanticCurmudgeon 2012-06-04 14:56
    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 2012-06-04 14:59
    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 2012-06-04 15:38
    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 2012-06-04 16:27
    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 2012-06-04 16:38
    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 2012-06-04 17:04
    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 2012-06-04 17:18
    Bill Clinton:
    tblIsThere? That depends on what the definition of the word "Is" is.


    The definition of "Is" is is is is is is.
  • Ruakh 2012-06-04 17:30
    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 2012-06-04 17:43
    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?
  • Silverhill 2012-06-04 18:05
    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 2012-06-04 18:07
    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 2012-06-04 18:21
    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.
  • Coyne 2012-06-04 20:24
    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 2012-06-05 03:21
    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?
  • toshir0 2012-06-05 03:34
    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 2012-06-05 05:41
    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 2012-06-05 07:05
    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!
  • ObiWayneKenobi 2012-06-05 09:07
    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 2012-06-05 09:31
    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.
  • toth 2012-06-05 09:33
    So basically, he uses a single-column table as (totally unnecessary) scratch space for this existence check, when he could have just as easily has run SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '?' [table_name]. Assuming he really needed to check if the table existed in the first place.

    He'd better have a really good justification for this...
  • TheSHEEEP 2012-06-05 09:44
    toth:
    So basically, he uses a single-column table as (totally unnecessary) scratch space for this existence check, when he could have just as easily has run SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '?' [table_name]. Assuming he really needed to check if the table existed in the first place.

    He'd better have a really good justification for this...


    Madness?
  • Nagesh 2012-06-05 10:09
    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*.


    Scarecrow? Ain't this new word? I am massaging my hands to gether to find what it menes.
  • Rootbeer 2012-06-05 10:11
    Jack:
    Metadata should be stored in XML in case the database is down.


    What if the disk where the XML file is stored is offline also.

    All access to metadata shall be done through a MetadataManager class (subclassed from a DataManager and, ultimately, an AbstractManager class) which maintains a list of MetdataManagerDriver objects that represent different ways in which the metadata can be stored: MetadataManagerXMLDriver, MetadataManagerDBDriver, MetadataManagerCSVDriver, MetadataManagerExcelCompatibleCSVDriver, etc...

    To prevent overloading any one storage medium, a different MetadataManagerDriver will be used for each method call to the MetadataManager. The algorithm for choosing which MetadataManagerDriverSelector to use per call (MetadataManagerDriverRandomSelector, MetadataManagerDriverRoundRobinSelector, etc.) shall be implemented in the MetadataManagerDriverSelectorMediator.

    Just hardcode all the config values for the MetadataManager right in the constructor for now.
  • Nagesh 2012-06-05 10:41
    Nagesh:
    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*.


    Scarecrow? Ain't this new word? I am massaging my hands to gether to find what it menes.


    dictionary.com:
    scarecrow
    [skair-kroh]   Origin
    scare·crow
       [skair-kroh] Show IPA
    noun
    1.
    an object, usually a figure of a person in old clothes, set up to frighten crows or other birds away from crops.
    2.
    anything frightening but not really dangerous.
    3.
    a person in ragged clothes.
    4.
    an extremely thin person.


    I ain't understanding this.
  • PedanticCurmudgeon 2012-06-05 11:08
    Nagesh:
    toshir0:
    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*.


    Scarecrow? Ain't this new word? I am massaging my hands to gether to find what it menes.
    Well, toshir0, I hope you're happy. Now he's "learned" a third word.
  • Nagesh 2012-06-05 11:45
    PedanticCurmudgeon:
    Nagesh (fake):
    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.


    This madarchod is bad version of imitating me. Atleast I have spell-checking feature in my browser all enabled now.
  • Nagesh 2012-06-05 11:50
    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...


    I have seen code like this in real live production system. It is only for some special group of users, but each user having individual table that define rights and privileges.

    We found out after some user changes his single-sign-on identity name. Then lose all rights. This table never maintained, except by severe sql scripts kept in a Unix folder with label of IMP-DO-NOT-MESS-WITH-THIS.

    Then we discover reason for lost rights for that user. This is still the way the system is running. This is system in place for client in Canada. Not develop by Indian programmers, but now being maintain by us only

    I could never make this story anonymous, so I not submit it to WTF
  • Nagesh 2012-06-05 12:37
    Gyxi:
    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?
    enum UniverseIsThere (is, ain't, FileNotFound);

    Kant compile. Must the ' marke be require for spell ain't?

    Pls send me the corect codez.

    Pls do not ignore becuse I know you are think "bad Nagesh I punnish him by ignore" but even so you are think about Nagesh so I win.
  • Meep 2012-06-05 13:11
    Tasty:
    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.


    You do realize that a DBMS will routinely create temporary tables to execute large SELECT queries, right? There is absolutely nothing wrong with generating temp tables to handle your work, especially if they're only visible to your transaction.

    For handling really large modifications to a table, often the best way to do it is through a CREATE ... AS SELECT because the DBMS doesn't have to do any locking: no one else can possibly access that table because it hasn't been created yet.

    Certain systems absolutely do, for legal reasons such as provenance and auditing, require a fixed schema.

    Many don't. The only good reason not to do DDL in a system that doesn't have a legal restriction on the schema is your concurrency model.

    Oracle, for instance, isolates DDL from transactions. That is, (BEGIN DML DDL DML COMMIT) is quietly changed to (BEGIN DML COMMIT) DDL (BEGIN DML COMMIT), since, being Oracle, it happens in the most unexpected way possible.

    Others, like PostgreSQL, handle DDL within a transaction just fine.

    As to whether you have a genuinely good reason that your fields aren't fixed, and whether these tables you're constructing have any actual meaning in the real world, that's a whole other debate...
  • Diego 2012-06-05 14:14
    Jim:
    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.
    You laugh, but this really happened at my workplace recently.
    [...]
    I guess this is the expected level of brainpower for a former Director of Big Things (recently demoted).


    Well, the person who gave me the example teaches in a US College, he's a Professor. Perhaps he was thinking in an abstract way, but the information is way too often absorbed as "dogmatic way of doing things". No wonder, then, that some graduates come out with some abominations.
  • M 2012-06-05 14:36
    Diego:
    Jim:
    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.
    You laugh, but this really happened at my workplace recently.
    [...]
    I guess this is the expected level of brainpower for a former Director of Big Things (recently demoted).


    Well, the person who gave me the example teaches in a US College, he's a Professor. Perhaps he was thinking in an abstract way, but the information is way too often absorbed as "dogmatic way of doing things". No wonder, then, that some graduates come out with some abominations.


    I'm not really a DB person as I find them incredibly boring, but wouldn't the obvious way to look at it be similar to a OO approach in programming? Tables take on the role of classes, and each row would be an instance of that class. If you think of it this way, then creating a table for each user would be analogous to creating a separate class for each user...i.e. batshit insane.
  • Jeff 2012-06-05 14:52
    M:
    creating a table for each user would be analogous to creating a separate class for each user...i.e. batshit insane.
    I am intrigued by your ideas. Hmmm... an opportunity to implement a UserClassFactory Class!

    No, you're right. Not enterprisey. Need more layers of factories.
  • emurphy 2012-06-05 15:21
    Tasty:
    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.


    Most, yes. Another exception would be an installer that creates a database and initializes its tables and such.

    Nagesh:
    This madarchod is bad version of imitating me.


    You wash your hands out with soap, young man!
  • Dave 2012-06-05 18:16
    Ruakh:

    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.

    So Oracle databases have a table called DUAL which has only ONE thing in it. But you can fix this by making a DUAL with 2 things in it. But that breaks normal code.

    Yet DUAL isn't a reserved word, or otherwise restricted to its valid if ill-named purpose.

    Conclusion: Oracle is the Real WTF.
    AMIRITE?
  • ur 2012-06-06 05:58
    ¯\(°_o)/¯ I DUNNO LOL:
    So TRWTF is that this function doesn't return FILE_NOT_FOUND?

    Close - we have here a pentabool, able to return TRUE, FALSE, NULL, RECORD_NOT_FOUND and TABLE_NOT FOUND.
  • ur 2012-06-06 05:59
    ur:
    ¯\(°_o)/¯ I DUNNO LOL:
    So TRWTF is that this function doesn't return FILE_NOT_FOUND?

    Close - we have here a pentabool, able to return TRUE, FALSE, NULL, RECORD_NOT_FOUND and TABLE_NOT FOUND.

    D'oh - I misread the table definition, the field isn't nullable, so this is just a boring old quadbool.
  • Mr Clever Ideas 2012-06-06 07:01
    Jeff:
    M:
    creating a table for each user would be analogous to creating a separate class for each user...i.e. batshit insane.
    I am intrigued by your ideas. Hmmm... an opportunity to implement a UserClassFactory Class!

    No, you're right. Not enterprisey. Need more layers of factories.

    DDL should also include syntax for anonymous inner tables.
  • M 2012-06-06 10:14
    Mr Clever Ideas:
    Jeff:
    M:
    creating a table for each user would be analogous to creating a separate class for each user...i.e. batshit insane.
    I am intrigued by your ideas. Hmmm... an opportunity to implement a UserClassFactory Class!

    No, you're right. Not enterprisey. Need more layers of factories.

    DDL should also include syntax for anonymous inner tables.


    Fine, fine, but I think multiple inheritance of tables should be avoided. Instead we should have abstract and interface tables with no actual columns, just ideas.

    captcha: letatio = lettuce head
  • Melvis 2012-06-06 12:03
    You guys are all crazy. He's obviously using this code to see if the DATABASE is there. Jeez...
  • C 2012-06-10 08:33
    Agention:
    Bill Clinton:
    tblIsThere? That depends on what the definition of the word "Is" is.


    The definition of "Is" is is is is is is.
    Umm, could you please properly paranthesize that? My brain's Language Interpretation Module just overflowed on me... :">
  • nmn 2012-06-12 10:41
    Metadata should be stored in XML in case the database is down...

    And if the database is down? Is the metadata useful in any way? I doubt.