Comment On tblIsThere

"I've been maintaining a 'certain' application for several months now," Trent writes, "it exists in a wonderful state of being partially properly written code, but mostly legacy garbage. I've done my best to avoid anything in the database realm, but a change request forced me to journey down that dark path." [expand full text]
« PrevPage 1 | Page 2Next »

Re: tblIsThere

2012-06-04 10:24 • by daef (unregistered)
kinda reminds me of oracle's "DUAL"... it IS there ;-)

Re: tblIsThere

2012-06-04 10:29 • by 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.

Re: tblIsThere

2012-06-04 10:34 • by ¯\(°_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.

Re: tblIsThere

2012-06-04 10:37 • by Captcha:dignissim (unregistered)
I don't suppose anyone could summarize here what this chunk of VB+SQL code does?

Re: tblIsThere

2012-06-04 10:46 • by sagaciter (unregistered)
382523 in reply to 382522
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.

Re: tblIsThere

2012-06-04 10:46 • by Loren Pechtel
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.

Re: tblIsThere

2012-06-04 10:48 • by emurphy
382525 in reply to 382522
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

Re: tblIsThere

2012-06-04 10:48 • by Anonymous Coward (unregistered)
382526 in reply to 382522
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

Re: tblIsThere

2012-06-04 10:50 • by anony-mouse (unregistered)
382527 in reply to 382522
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.

Re: tblIsThere

2012-06-04 10:53 • by 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.

Re: tblIsThere

2012-06-04 10:55 • by LieutenantFrost (unregistered)
382529 in reply to 382522
It makes my eyes bleed.

Re: tblIsThere

2012-06-04 11:17 • by iToad (unregistered)
382530 in reply to 382525
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.

Re: tblIsThere

2012-06-04 11:17 • by Bill Clinton (unregistered)
tblIsThere? That depends on what the definition of the word "Is" is.

Re: tblIsThere

2012-06-04 11:17 • by SilentRunner (unregistered)
382532 in reply to 382521
It's amazing what words some people will come up with when trying to communicate with educated people.

Re: tblIsThere

2012-06-04 11:18 • by Tasty (unregistered)
382533 in reply to 382528
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.

Re: tblIsThere

2012-06-04 11:18 • by Anonymous (unregistered)
382534 in reply to 382516
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.

Re: tblIsThere

2012-06-04 11:19 • by Stan (unregistered)
382535 in reply to 382522
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.

Re: tblIsThere

2012-06-04 11:42 • by KattMan
382537 in reply to 382535
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.

Re: tblIsThere

2012-06-04 12:24 • by 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

Re: tblIsThere

2012-06-04 12:30 • by 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. ;-)

Re: tblIsThere

2012-06-04 12:33 • by Albert (unregistered)
382541 in reply to 382539
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.

Re: tblIsThere

2012-06-04 13:04 • by Anonymous (unregistered)
382543 in reply to 382541
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"

Re: tblIsThere

2012-06-04 13:07 • by Silent D (unregistered)
382544 in reply to 382541
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.

Re: tblIsThere

2012-06-04 13:11 • by KattMan
382545 in reply to 382544
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!

Re: tblIsThere

2012-06-04 13:23 • by ObiWayneKenobi
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.

Re: tblIsThere

2012-06-04 13:23 • by Nagesh (unregistered)
382547 in reply to 382532
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."

Re: tblIsThere

2012-06-04 13:25 • by big picture thinker (unregistered)
382548 in reply to 382528
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

Re: tblIsThere

2012-06-04 14:03 • by radarbob (unregistered)
382550 in reply to 382521
¯\(°_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!

Re: tblIsThere

2012-06-04 14:12 • by Jack (unregistered)
382551 in reply to 382548
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.

Re: tblIsThere

2012-06-04 14:39 • by Meep (unregistered)
382553 in reply to 382522
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?

Re: tblIsThere

2012-06-04 14:48 • by Nagesh (unregistered)
382554 in reply to 382553
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.

Re: tblIsThere

2012-06-04 14:56 • by PedanticCurmudgeon
382555 in reply to 382547
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.

Re: tblIsThere

2012-06-04 14:59 • by Nagesh (unregistered)
382556 in reply to 382555
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.

Re: tblIsThere

2012-06-04 15:38 • by Diego (unregistered)
382557 in reply to 382533
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...

Re: tblIsThere

2012-06-04 16:27 • by Jim (unregistered)
382558 in reply to 382557
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).

Re: tblIsThere

2012-06-04 16:38 • by 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.

Re: tblIsThere

2012-06-04 17:04 • by Kasper (unregistered)
382560 in reply to 382534
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.

Re: tblIsThere

2012-06-04 17:18 • by Agention (unregistered)
382562 in reply to 382531
Bill Clinton:
tblIsThere? That depends on what the definition of the word "Is" is.


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

Re: tblIsThere

2012-06-04 17:30 • by Ruakh
382563 in reply to 382560
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.

Re: tblIsThere

2012-06-04 17:43 • by YF (unregistered)
382566 in reply to 382535
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?

Re: tblIsThere

2012-06-04 18:05 • by Silverhill
382567 in reply to 382544
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/ )

Re: tblIsThere

2012-06-04 18:07 • by Darth Paul (unregistered)
382568 in reply to 382557
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.

Re: tblIsThere

2012-06-04 18:21 • by Rodd (unregistered)
382569 in reply to 382557
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.

Re: tblIsThere

2012-06-04 20:24 • by Coyne
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.

Re: tblIsThere

2012-06-05 03:21 • by Gyxi (unregistered)
382571 in reply to 382541
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?

Re: tblIsThere

2012-06-05 03:34 • by toshir0
382572 in reply to 382555
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*.

Re: tblIsThere

2012-06-05 05:41 • by Doctor_of_Ineptitude (unregistered)
382574 in reply to 382572
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.

Re: tblIsThere

2012-06-05 07:05 • by OptimalExpert (unregistered)
382575 in reply to 382557
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!

Re: tblIsThere

2012-06-05 09:07 • by ObiWayneKenobi
382576 in reply to 382559
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...

Re: tblIsThere

2012-06-05 09:31 • by Mongo (unregistered)
382577 in reply to 382572
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.
« PrevPage 1 | Page 2Next »

Add Comment