Comment On Simple SQL

John Dorn's colleague's approach to problem solving is best described as follows. The solution to any given problem is to introduce two additional problems. While this approach generated quite a many interesting implementations, it rarely produced the needed results: simple, custom software for their clients. Ultimately, this approach led towards his de-hiring, which meant that John would have to maintain his old systems. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Simple SQL

2009-06-15 09:04 • by Yohan J (unregistered)
Sometimes killing is the only solution to a programmer. This one is on the firing list.

Re: Simple SQL

2009-06-15 09:05 • by DOA
Cause you never know when basic SQL syntax will change...

Re: Simple SQL

2009-06-15 09:06 • by graybreard (unregistered)
I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.

Re: Simple SQL

2009-06-15 09:12 • by Sean (unregistered)
Teacher said not to use constants in your code, use objects instead. And if you absolutely have to have constants somewhere, well at least bury them where no one will ever see.

Re: Simple SQL

2009-06-15 09:14 • by snoofle
Criteria $comment = new Criteria();
$comment->add("What");
$comment->space();
$comment->add("the");
$comment->space();
$comment->add("fuck?");
print $comment->toString();

Re: Simple SQL

2009-06-15 09:14 • by dpm
269196 in reply to 269192
DOA:
Cause you never know when basic SQL syntax will change...
or the value of " ".

Re: Simple SQL

2009-06-15 09:15 • by Ethan Qix (unregistered)
The funny fact is that the original programmer must have had a harder time using his Criteria wrapper class than just mere SQL. But at least this code will be easy to adapt when the SQL "(" becomes "¤" ...

Re: Simple SQL

2009-06-15 09:16 • by Joe (unregistered)
I suppose I'm ruining the fun by pointing out that the supplied code doesn't generate the example SQL string...

Re: Simple SQL

2009-06-15 09:18 • by Sean (unregistered)
269199 in reply to 269197
Ethan Qix:
The funny fact is that the original programmer must have had a harder time using his Criteria wrapper class than just mere SQL. But at least this code will be easy to adapt when the SQL "(" becomes "¤" ...

Not really, because then you'd have to do a global search and replace changing "leftParenthesis" to "funnyThing".

Re: Simple SQL

2009-06-15 09:20 • by Mithious
There are some good reasons to use an abstraction to SQL. A direct copy of the manual process isn't one of them.

I have written an object oriented sql abstraction and I find it a joy to use, especially when writing queries with a shed load of joins and functions in them.

Re: Simple SQL

2009-06-15 09:21 • by Ben Jammin (unregistered)
I'm not a php programmer, but wouldn't that return something along the lines of

SELECT * FROM bean_overtime_availability
WHERE (`startDateTime` >= "06/15/2009") AND `available` = "1" order by startDateTime;

assuming getToday() returned a string representation of today.

Re: Simple SQL

2009-06-15 09:22 • by Ben Jammin (unregistered)
I ask because I need to make sure I'm using that class right

Re: Simple SQL

2009-06-15 09:25 • by Mark (unregistered)
269206 in reply to 269199
Sean:
Ethan Qix:
The funny fact is that the original programmer must have had a harder time using his Criteria wrapper class than just mere SQL. But at least this code will be easy to adapt when the SQL "(" becomes "¤" ...

Not really, because then you'd have to do a global search and replace changing "leftParenthesis" to "funnyThing".

That's why a function name should say what the function does, not how it accomplishes it. Implementation may change, API must remain the same. So the function should have been named "beginNestedExpressionWithEvaluationPrecedence".

Re: Simple SQL

2009-06-15 09:30 • by Anonymous (unregistered)
He didn't even pick an appropriate name for his "Criteria" class. Rubbish.

Re: Simple SQL

2009-06-15 09:32 • by Little Bobby Tables (unregistered)
With so many levels of unnecessary modularization (given that there's no "
class EscapeMySuperiorCriteria extends Criteria { ... }
" etc.) the SQL injection possiblity still exists. How PHPish, oh forgot, OOP is so b0rken in PHP so it's not probably even possible with his "return my instance" approach.

Re: Simple SQL

2009-06-15 09:35 • by Inhibeo (unregistered)
269210 in reply to 269206
[quote user="Mark"]
Not really, because then you'd have to do a global search and replace changing "leftParenthesis" to "funnyThing".[/quote]
That's why a function name should say what the function does, not how it accomplishes it. Implementation may change, API must remain the same. So the function should have been named "beginNestedExpressionWithEvaluationPrecedence".[/quote]

That's way too ambiguous and inflexible. What if mathematical order of operation conventions change?

Re: Simple SQL

2009-06-15 09:40 • by powerlord
ArrayList? In PHP? Are people really that desperate to use OO?

Ararys with numeric indexes in PHP already act like Java's lists, and array_slice can be used to remove arbitrary elements by not specifying a replacement.

Is there also a PHP HashMap to do the same operations, but on arrays with named keys?

Re: Simple SQL

2009-06-15 09:42 • by Phlip
To be fair, the function's called "quote", not "quoteAndEscape"... if it escaped the string then that'd totally be a WTF since it's not only doing the thing that can be completely described by the one-word function name, right?

Re: Simple SQL

2009-06-15 09:44 • by snoofle
269213 in reply to 269210
Inhibeo:
What if mathematical order of operation conventions change?

I agree! In case we ever get a postfix sql engine...

select * from someTable
where field1 6 = field2 3 * 12 = and

Re: Simple SQL

2009-06-15 09:45 • by Phlip
269214 in reply to 269198
Joe:
I suppose I'm ruining the fun by pointing out that the supplied code doesn't generate the example SQL string...
The relevant clause is "similar to"...

If you wanted to comment on typos in the article, I'd suggest starting with the inconsistent "equal()"/"equals()", and work up from there.

Re: Simple SQL

2009-06-15 09:45 • by mr_man (unregistered)
Genius! I have the perfect project for this utility class. Thank you for the code sample!

Re: Simple SQL

2009-06-15 09:47 • by Andrey Lebedev (unregistered)
Looks like cargo cult.

Re: Simple SQL

2009-06-15 09:48 • by xtremezone
Alex Papadimoulis or submitter:
public function lassThanOrEqualTo() {

$this->lessThan();
$this->equals();
return $this;
}
:P

Re: Simple SQL

2009-06-15 09:50 • by COB (unregistered)
He was ahead of his time, it's an early version of LINQ. Intellisense and everything! Genius!

IT'S PROPEL!

2009-06-15 09:51 • by Jason (unregistered)
propel.phpdb.org

What a waste of an article. I would never expect in a thousand years to see Propel in a WTF, thanks to an uneducated developer - here we have one.

Jesus christ.

Sure for one simple query, write a SQL and be done with it.. but showing the Propel criteria object as part of the WTF is just ridiculous.

Propel is designed to be used for application development, certainly not for Select * from sometable where date >= now.

Your WTF would be much better read if you pointed out that the developer had went through the trouble of using a powerful database abstraction and ORM layer to execute a very simple query, but somehow I believe there's more to the story than just that simple query otherwise why would they have spent the time to fucking deploy it in the first place?

Horrible WTF.

Alex - WTF?!

Re: Simple SQL

2009-06-15 09:52 • by Jason (unregistered)
AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

Good god.

Re: Simple SQL

2009-06-15 09:52 • by Crafty_Shadow (unregistered)
When I read $c = new Criteria(); I thought to myself WTF, Propel? (no pun intended), but as I actually went about reading the article I found myself uttering What In The Name Of All That Is Holly...

It seems like the developer came across the Propel implementation of Criteria at some point, and left with those vague impressions set off to build it's own... and failed miserably.

Re: Simple SQL

2009-06-15 09:53 • by Anonymous Coward (unregistered)
269222 in reply to 269213
snoofle:
Inhibeo:
What if mathematical order of operation conventions change?

I agree! In case we ever get a postfix sql engine...

select * from someTable
where field1 6 = field2 3 * 12 = and


where field1 6 = field2 3 12 * = and ?

Re: Simple SQL

2009-06-15 09:55 • by Jason (unregistered)
AND TO FURTHER RANT - The goddamn submitter should have KNOWN because every fucking file is prefixed with a gigantic disclaimer, license, and url to propel.phpdb.org AND a plain as day explanation of what it does. WITH FULL PHPDOC COMMENTS.

If all of that were, for some VERY strange reason, stripped from the files, THEN, perhaps MAYBE that is "TRWTF" ™

Re: Simple SQL

2009-06-15 09:56 • by snoofle
269224 in reply to 269217
xtremezone:
Alex Papadimoulis or submitter:
public function lassThanOrEqualTo() {

...
}

Perhaps he had Irish-Girl on his mind...

Re: Simple SQL

2009-06-15 09:59 • by ath (unregistered)
269226 in reply to 269195
snoofle:
Criteria $comment = new Criteria();
$comment->add("What");
$comment->space();
$comment->add("the");
$comment->space();
$comment->add("fuck?");
print $comment->toString();


Criteria $comment = new Criteria();
$comment->n()->o()->t()->space();
$comment->g()->e()->n()->e()->r()->a()->l()->space();
$comment->e()->n()->o()->u()->g()->h()->space();
$comment->tostring()

Re: IT'S PROPEL!

2009-06-15 10:00 • by Crafty_Shadow (unregistered)
269227 in reply to 269219
Jason:

Your WTF would be much better read if you pointed out that the developer had went through the trouble of using a powerful database abstraction and ORM layer to execute a very simple query, but somehow I believe there's more to the story than just that simple query otherwise why would they have spent the time to fucking deploy it in the first place?


Did you read the article at all?
This IS NOT the Propel Criteria object even though it's trying to look like it. Read.

Re: Simple SQL

2009-06-15 10:00 • by snoofle
269228 in reply to 269222
Anonymous Coward:
snoofle:
Inhibeo:
What if mathematical order of operation conventions change?

I agree! In case we ever get a postfix sql engine...

select * from someTable
where field1 6 = field2 3 * 12 = and


where field1 6 = field2 3 12 * = and ?


Trnslating my postfix into infix for you...

where (field1 = 6) and (field2 * 3 = 12)

Re: Simple SQL

2009-06-15 10:02 • by snoofle
269230 in reply to 269226
ath:
snoofle:
Criteria $comment = new Criteria();
$comment->add("What");
$comment->space();
$comment->add("the");
$comment->space();
$comment->add("fuck?");
print $comment->toString();


Criteria $comment = new Criteria();
$comment->n()->o()->t()->space();
$comment->g()->e()->n()->e()->r()->a()->l()->space();
$comment->e()->n()->o()->u()->g()->h()->space();
$comment->tostring()

True, we must support our mid and far eastern friends with full unicode support as well!

Re: Simple SQL

2009-06-15 10:05 • by Jason (unregistered)
269231 in reply to 269221
Crafty_Shadow:
When I read $c = new Criteria(); I thought to myself WTF, Propel? (no pun intended), but as I actually went about reading the article I found myself uttering What In The Name Of All That Is Holly...

It seems like the developer came across the Propel implementation of Criteria at some point, and left with those vague impressions set off to build it's own... and failed miserably.


There you go, good point. I honestly didnt bother to read that much because I couldn't believe in the first place that someone would submit Propel as a WTF. But it's there for a reason. Holy shit.

Why in god's name would anyone attempt to replace the Criteria object, why?! in his case he SHOULD have simply done

$SQL = "Select * from blah where date >= 'some-date' and wtf='no'"; $con = propel::getconnection('dbname') $stmt = $con->prepare($sql); $stmt->execute(); - that simply uses the PDO routines.

What a fucknut. God damn it. *facepalm*

Re: Simple SQL

2009-06-15 10:06 • by brazzy
269232 in reply to 269221
Jason:

Sure for one simple query, write a SQL and be done with it.. but showing the Propel criteria object as part of the WTF is just ridiculous.


RTFWTF. A hint: the dev is NOT using Propel...

Crafty_Shadow:
It seems like the developer came across the Propel implementation of Criteria at some point, and left with those vague impressions set off to build it's own... and failed miserably.


With a 99% certainty, that's exactly what happened.

Re: Simple SQL

2009-06-15 10:12 • by configurator (unregistered)
269233 in reply to 269228
snoofle:

Trnslating my postfix into infix for you...

where (field1 = 6) and (field2 * 3 = 12)


prefix is much better!

where and = field1 6 = * field2 3 12

Re: Simple SQL

2009-06-15 10:13 • by Whoevar (unregistered)
269234 in reply to 269201
Mithious:
I have written an object oriented sql abstraction and I find it a joy to use, especially when writing queries with a shed load of joins and functions in them.


I have seen one of those self-knitted "OR mappers" and had to work with it. It generated SQL in an absolutely confusing way. A funny moment was when the SQL query size limit (2^15 chars) was exceeded in one query for only one customer (an importan one, obviously...). It had been assembled like this:

SELECT * FROM customer WHERE
customerid = [uuid-string] OR
customerid = [uuid-string] OR
customerid = [uuid-string] OR
...

Rewrote the query generator to use the IN-clause as a quick fix and then got rid of the "OR mapper".

I don't want to imply that yours is as crappy as the one I found but good OR mappers exist already.

Re: Simple SQL

2009-06-15 10:14 • by John (unregistered)
Gloves!

Re: Simple SQL

2009-06-15 10:22 • by Smyle (unregistered)
269237 in reply to 269221
Crafty_Shadow:
What In The Name Of All That Is Holly...

Are you referring to Buddy or Ms. Hunter?

Re: Simple SQL

2009-06-15 10:39 • by Zagyg
269238 in reply to 269237
Smyle:
Crafty_Shadow:
What In The Name Of All That Is Holly...

Are you referring to Buddy or Ms. Hunter?

Ilex opaca or Ilex aquifolium?

Re: Simple SQL

2009-06-15 10:55 • by drachenstern
269241 in reply to 269204
Ben Jammin:
I ask because I need to make sure I'm using that class right
Wow, that's so full of WIN I couldn't keep reading without commenting.

And if it's not full of WIN, then the sarcasm at least makes it full of LULZ. kthxbye

Re: Simple SQL

2009-06-15 10:57 • by Anonymous (unregistered)
269242 in reply to 269223
Jason:
AND TO FURTHER RANT - The goddamn submitter should have KNOWN because every fucking file is prefixed with a gigantic disclaimer, license, and url to propel.phpdb.org AND a plain as day explanation of what it does. WITH FULL PHPDOC COMMENTS.

If all of that were, for some VERY strange reason, stripped from the files, THEN, perhaps MAYBE that is "TRWTF" ™
Would you just shut up already? This ISN'T Propel, end of story. No prizes for guessing where the coder's "inspiration" came from but it doesn't change the fact that this is not Propel so you're just talking rubbish. Instead of ranting about the very first line, why not go back to the article and read the rest of it?

Re: Simple SQL

2009-06-15 11:07 • by Mr. A. T. Roll (unregistered)
269244 in reply to 269242
Anonymous:
Jason:
AND TO FURTHER RANT - The goddamn submitter should have KNOWN because every fucking file is prefixed with a gigantic disclaimer, license, and url to propel.phpdb.org AND a plain as day explanation of what it does. WITH FULL PHPDOC COMMENTS.

If all of that were, for some VERY strange reason, stripped from the files, THEN, perhaps MAYBE that is "TRWTF" ™
Would you just shut up already? This ISN'T Propel, end of story. No prizes for guessing where the coder's "inspiration" came from but it doesn't change the fact that this is not Propel so you're just talking rubbish. Instead of ranting about the very first line, why not go back to the article and read the rest of it?


Thank God I read Daily WTF. I had heard about Propel, and thought about using it today. Now I will be sure to steer absolutely clear of that piece of garbage! TYVM Daily WTF!

Re: IT'S PROPEL!

2009-06-15 11:08 • by scuzzman
269245 in reply to 269219
We don't use Propel. This class was custom-built.

Re: Simple SQL

2009-06-15 11:25 • by Hogan
He was lazy to add new functions for ordering definition...

Re: Simple SQL

2009-06-15 11:30 • by Quirk (unregistered)
269252 in reply to 269250
Hogan:
He was lazy to add new functions for ordering definition...


If only you knew.

Re: Simple SQL

2009-06-15 11:33 • by WhatTheFrank (unregistered)
269253 in reply to 269193
graybreard:
I have a friend.. who's a brilliant programmer. The only problem is, he's good at solving extremely complicated issues. But not easy ones. So he turns easy ones into complicated before solving them.


Based on your description, your friend is not a brilliant programmer. It takes a pretty shoddy programmer to be unable to solve easy problems without turning them into complicated ones. The brilliant programmers are the ones who can take extremely complicated problems and break them down into easy ones, then solve those.

Re: IT'S PROPEL!

2009-06-15 11:49 • by Stephen Melrose (unregistered)
269255 in reply to 269219
I thought the exact same thing when I read this article!

However, that is not the Propel Criteria class. I honestly believe the developer has written their own, which is a WTF in itself.

But I due agree, this developer has added complication and abstraction when it is truely not needed, and further more they have written their own based on an ORM which is far better?!

Re: Simple SQL

2009-06-15 11:50 • by Stephen Melrose (unregistered)
269256 in reply to 269244
Mr. A. T. Roll:
Thank God I read Daily WTF. I had heard about Propel, and thought about using it today. Now I will be sure to steer absolutely clear of that piece of garbage! TYVM Daily WTF!

Propel is a lot better than what this guy has demonstrated. Give it a go before you knock it. Makes development a hell of a lot easier.

Also Doctrine is another very good PHP ORM.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment