- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
protected static final String FRIST = "FRIST";
Admin
I can understand the desire to move SQL literals to constants (benefits: interning/autocompletion/cleaner looking code), but what strikes me is that they didn't use these constants after defining them.
Admin
I am not sure its exactly a WTF to make some SQL reserved words constants. BRACE_BEGIN though is going a bit far. Especially when its actually a open parenthesis. One would normally expect it to be a brace '{'. That might be just an example of these constants acting as exactly the abstraction layer they were put in to provide. The really amazing part though is some of the SQL strings have spaces before, after, or before and after the token while others don't. So I guess you have to scroll up and read though the constants to know if you need to append additional spaces or not when using them or have a really good memory.
Admin
Hey, I think I could use this idea: they are the first coding shop to be ready for SQL implementations in any language; they just need to update the constants and VOILA: Globalized SQL. The string definitions should be moved to a resource file though.
Admin
They did use some, but still they just turned the whole thing to an unreadable mess. A better approach: jOOQ (have not tried yet, but looks promising for projects where JPA is not an option nor needed)
Admin
How does one use BETWEEN ?
Why are ISNULL and ISNOTNULL the only ones not using _ naming ?
Why is MIN's value lowercase ?
What is the purpose of ONE_DAY_MINUS_ONE_MILLISEC ? Er, let me rephrase that : Is there a legitimate reason to have such value ?
Admin
This will only solve syntax changes, not semantic changes. Obviously, there is a need to code a more elaborate framework that will handle that case also.
Admin
This is not so much an abstraction layer as a horrible calling on the dark ones.
How is this in any way easier than just telling whomever is supposed to be using this how to write proper SQL? Or just have them use certain key words like INSERT, DELETE, UPDATE etc. and then create the correct syntax depending on what they're trying to do, if the users are that stupid?
Admin
It's essentially http://thedailywtf.com/Articles/InsertSql().aspx all over again.
Admin
There can be a legitimate reason: a "datcolumn between '2013-05-22' and '2013-05-23'" will select all dates from midnight 2013-05-22 up to and including midnight 05-23. So if you don't want to include that second midnight and still want to use "between", you could use "a millisecond less than that" (if database precision doesn't round it up to midnight...)
Admin
Bonus points for the inconsistent use of spaces in the literals. Some have a space before and after the word, some only before, some none at all...
Admin
for (i = 1; i <= ONE_DAY_IN_MILLISECONDS; i++) { // sleep, yawn, eat, watch telly, party or go surfing if (i == ONE_DAY_MINUS_ONE_MILLISEC) { // burst into frantic activity to meet some // study-related deadline } }
Admin
That's very bad practice, having string literals like " " all over the place ;-)
Admin
Admin
Looks like the spaces are set up so you don't have to include any padding spaces in the strings you're concatenating these constants with. still fugly but at leaset some thought went into that (just not quite enough).
Admin
Let's hope they never want to call one of those pesky stored procedures. Code is always so much better when it contains raw SQL.
Admin
While I don't know jOOQ (I haven't written any Java in quite some time), it looks similar to sqlalchemy's SQL expression layer. I find that approach an enormeous improvement over literal SQL, and clearly the way to go when building SQL query strings.
DISCLAIMER: I don't do SQL on my day job, only for hobby projects; so I don't really know how that kind of stuff scales.
Admin
It should have read in this from a file, this way they didn't even have to recompile the application for it to work when we someday change comma to something else.
Admin
Admin
Admin
The real data access object ("MyDAO") would then get an instance of the right "DAO...Base" for the job from a "DAOPersistencyAccessFactory" which in turn chooses the right "DAO...Base" implementation using a "DAOBaseSelectorStrategy" object.
To be more enterprisey, somewhere in all this XML should play a role, but for the sake of illustration it is not necessary.
Admin
It is reasonable (aside perhaps from SQL not supporting it) to expect a constant with this name to be 86399999000 (microseconds) or 86399.999 (seconds) or even 863999990000 (hectananoseconds, the increment of time in NTFS timestamps) or 0,999999988425926 (days, approximately).
And it's a bad name for another reason - it doesn't explain what it is for. As written, the name describes (aside from the lack of units) what it represents at the most literal level, but why would I need such a thing? As it is, it is just as bad as our old friends:
Admin
I once made something alarmingly similar to this. I re-visited it recently and wondered wtf I was thinking. It didn't go quite as far as this though. No constants for brackets though I did do one for "=".
It seemed like a good idea at the time, my only justification is that it was a situation where we couldn't use sprocs.
Admin
This one isn't so bad you just need to write a little helper app that translates your raw SQL command into a giant string concatenation. Another function to reverse the translation and you can make it a plugin for your SQL execution tool of choice. At first glance this might seem like a lot of extra work, but when you dabble in storing SQL inside of your application you have already opened the pandora's box of WTF.
nobis - you have nobis writing SQL with constants.
Admin
More bonus points for simply append()ing column names into selects and inserts. Cue mandatory Bobby Tables reference in 3... 2... 1...
Admin
There are two more interesting things about the code nobody seems to have mentioned so far:
First, where does "useLiteralCustomerId" come from? It's not a parameter of the methods in which it is used, it's not a member variable... does Java allow global variables?
Second: CustIdUtil.getCustIdAsString(). This looks like a call to a static method to me, which begs the question: do all customers have the same id?
Admin
StringBuilder sql = new StringBuilder(1024); <---- sql.append(UPDATE).append(viewname).append(SET).append(columsForUpdate); if (additionalColumns != null && additionalColumns.length() != 0) { sql.append(additionalColumns); }
Just wondering how the 1024 will hold the whole string, if there are a lot of additional Columns???
Admin
Admin
I would like to update the following additional columns, please:
Admin
Not necessarily. It depends on the RDBMS, data type and precision. For example in Oracle the DATE data type has a precision of seconds so you'd never have a record that's half a second between 23:59:59 on one day and 00:00:00 on the next.
Admin
TRWTF is another article about constant abuse.
Admin
Such dumbassery is rather common, unfortunately.
It provides no real cross-syntax benefit (even in such cases it makes more sense to run the full statement through a translator, to provide a bit of flexibility), but it's slower for developers to write, slower for the compiler (how many string concatenations does it take to change a light bulb?), and adds more chance of error (spacing).
Every time someone tries to make their SQL "easier" with constants, a good programmer dies.
Admin
Real bonus points for putting this information in a database instead of code. Then you can change databases without rebuilding! OF course, then you'd have to abstract the database to abstract the database. Hey, THAT could be in another database, too!
http://knowyourmeme.com/memes/xzibit-yo-dawg
captcha: genitus; Whoever does this should be kicked in the face. Or something.
Admin
TRWTF is assuming that all of your readers are sexually attracted to females and are at all interested in marriage, assuming the option is even available to them. "We change our clothes, jobs and sometimes even wives." Way to annoy at least 2 large groups of people there.
Admin
What a stupid comment.
Sometimes, we change our jobs - BUT WHAT ABOUT UNEMPLOYED PEOPLE, OR COLLEGE KIDS WHO'VE NEVER HAD JOBS? Someone think of the kids!
Admin
TRWTF : StringBuffer
Admin
Henny Youngman must drive you crazy, then.
Admin
thats not a brace '(', this is a brace '{'
just imagine Crocodile Dundee reading that
Admin
These people never learn. They probably use more memory by calling these daft functions all the time than they ever did by using literals. Which the compiler is going to rationalise away in any case.
Admin
Admin
Admin
question: how many hours has one day?
once you found the right answer you see the real WTF in that: ONE_DAY_MINUS_ONE_MILLISEC
Admin
Admin
They expected the vocabulary of the query language to change and planned for it appropriately. What happens if the grammar also changes?
Admin
Why? WHy?? WHY???
Admin
Admin
Oh, we can put them in an XML file, so we can easily change that.
Then the code that parses the XML file can load up another CSV file that tells how to parse XML, in case that changes.
Finally we need a manifest that contains the current character that represents ',' in case the deliminator in our CSV ever changes.
Admin
do you know that :
even though you know people will laugh at you?
Admin
It's the reader's job to insert replacers for content that doesn't directly apply to them.
I've lost all patience for the easily offended. So much so that I have a one gesture for them, and it only needs one finger.
Otherwise, he really should have wrote this: "We change our [Whatever applies], [Another whatever applies], and sometimes even [more shocking that could apply]."
And, if it takes offending two large groups (which you won't, because most women I know aren't offended by terms like waiter and tailor, only the wastrels that don't have anything better to do since we stop making soap operas 20 years ago), so I don't have to read a damn MadLibs game, then so be it.
It's not the writer's responsibility to make sure every statement applies to every reader.
Admin
[Deprecated()]