• Yohan J (unregistered)

    Sometimes killing is the only solution to a programmer. This one is on the firing list.

  • (cs)

    Cause you never know when basic SQL syntax will change...

  • 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.

  • 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.

  • (cs)

    Criteria $comment = new Criteria(); $comment->add("What"); $comment->space(); $comment->add("the"); $comment->space(); $comment->add("fuck?"); print $comment->toString();

  • (cs) in reply to DOA
    DOA:
    Cause you never know when basic SQL syntax will change...
    or the value of " ".
  • 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 "¤" ...

  • Joe (unregistered)

    I suppose I'm ruining the fun by pointing out that the supplied code doesn't generate the example SQL string...

  • Sean (unregistered) in reply to Ethan Qix
    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".
  • (cs)

    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.

  • 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.

  • Ben Jammin (unregistered)

    I ask because I need to make sure I'm using that class right

  • Mark (unregistered) in reply to Sean
    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".
  • Anonymous (unregistered)

    He didn't even pick an appropriate name for his "Criteria" class. Rubbish.

  • 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.

  • Inhibeo (unregistered) in reply to Mark

    [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?

  • (cs)

    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?

  • (cs)

    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?

  • (cs) in reply to Inhibeo
    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

  • (cs) in reply to Joe
    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.

  • mr_man (unregistered)

    Genius! I have the perfect project for this utility class. Thank you for the code sample!

  • Andrey Lebedev (unregistered)

    Looks like cargo cult.

  • (cs)
    Alex Papadimoulis or submitter:
    public function lassThanOrEqualTo() {
        $this->lessThan();
        $this->equals();
        return $this;
    }
    :P
  • COB (unregistered)

    He was ahead of his time, it's an early version of LINQ. Intellisense and everything! Genius!

  • 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?!

  • Jason (unregistered)

    AND TO ADD To my extreme disbelief, apparently the rest of you knuckleheads don't know it's Propel either.

    Good god.

  • 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.

  • Anonymous Coward (unregistered) in reply to snoofle
    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 ?

  • 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" ™

  • (cs) in reply to xtremezone
    xtremezone:
    Alex Papadimoulis or submitter:
    public function lassThanOrEqualTo() {
        ...
    }
    Perhaps he had Irish-Girl on his mind...
  • ath (unregistered) in reply to snoofle
    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()

  • Crafty_Shadow (unregistered) in reply to Jason
    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.

  • (cs) in reply to Anonymous Coward
    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)

  • (cs) in reply to ath
    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!

  • Jason (unregistered) in reply to Crafty_Shadow
    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

  • (cs) in reply to Crafty_Shadow
    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.

  • configurator (unregistered) in reply to snoofle
    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

  • Whoevar (unregistered) in reply to Mithious
    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.

  • John (unregistered)

    Gloves!

  • Smyle (unregistered) in reply to Crafty_Shadow
    Crafty_Shadow:
    What In The Name Of All That Is Holly...
    Are you referring to Buddy or Ms. Hunter?
  • (cs) in reply to Smyle
    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?
  • (cs) in reply to Ben Jammin
    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

  • Anonymous (unregistered) in reply to Jason
    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?
  • Mr. A. T. Roll (unregistered) in reply to Anonymous
    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!

  • (cs) in reply to Jason

    We don't use Propel. This class was custom-built.

  • (cs)

    He was lazy to add new functions for ordering definition...

  • Quirk (unregistered) in reply to Hogan
    Hogan:
    He was lazy to add new functions for ordering definition...

    If only you knew.

  • WhatTheFrank (unregistered) in reply to graybreard
    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.

  • Stephen Melrose (unregistered) in reply to Jason

    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?!

  • Stephen Melrose (unregistered) in reply to Mr. A. T. Roll
    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.

Leave a comment on “Simple SQL”

Log In or post as a guest

Replying to comment #:

« Return to Article