Comment On SQL Sentences

At David’s company, management wasn’t a big fan of the whole check-in/re-compile/re-deploy process. They felt that it had too many steps and took far too long to complete. Their organization needed to adapt to software changes - especially bug fixes - much faster. So, to address this problem, they thoroughly analyzed the development process and carefully tweaked it for efficiency. I’m just kidding. Actually, their solution was to pioneer a new methodology called “SQL Sentences”. [expand full text]
« PrevPage 1 | Page 2Next »

Re: SQL Sentences

2008-02-20 08:08 • by snoofle
Soooo, hard coded magic numbers, double the amout of code, an indirect requiring multiple DB reads just to figure out what to do, and presuming arguments needed to be passed to the query's where-clause, the whole thing was hard-wired anyway.

Nice!

Re: SQL Sentences

2008-02-20 08:10 • by JonC (unregistered)
I hope they included a SQL sentence history table as well for version control!

Re: SQL Sentences

2008-02-20 08:19 • by akatherder
Can you patent ideas? I would like to patent this concept. Then I will never let anyone use it ever again.

Re: SQL Sentences

2008-02-20 08:24 • by Drum D.
How can one become "lead" developer by relying on hearsay? Probably because the superiors "heard" this person "is fit for the job". UnbeWTFinglievable!

Re: SQL Sentences

2008-02-20 08:31 • by TGV
177964 in reply to 177961
JonC:
I hope they included a SQL sentence history table as well for version control!

Why stop there? I would suggest adding all code to an SQL library, with an identifier column, a language column and then a column with the code itself. Heck, you might even add a comment column.

Then, instead of calling a hard-wired procedure, you retrieve the correct id/language from the library, and eval() it. Much more flexible!

Re: SQL Sentences

2008-02-20 08:31 • by ObiWayneKenobi
177965 in reply to 177963
Drum D.:
How can one become "lead" developer by relying on hearsay? Probably because the superiors "heard" this person "is fit for the job". UnbeWTFinglievable!


Where have you been? These days, "lead developer" doesn't mean you have experience, it means that you were the second programmer the company ever hired (the first would be Director/VP of IT). You won't believe how many so-called "leads" I've met who were terrible, terrible coders, yet were Leads based only on seniority, not talent. God forbid companies actually promote people based on WHAT THEY CAN DO, and not HOW LONG THEY'VE BEEN THERE.

Addendum (2008-02-20 08:41):
Same thing with the majority of IT managers I've met - most of them had no real skill, but got their position through being with the company for 10 years.

I love places that proudly claim "We promote Leads from within", yet the guy who is the current lead has been there for 7 years, and was the second developer they hired.

BTW the real WTF is this "You can only edit the post for x amount of time before it forces you to append" nonsense.

Re: SQL Sentences

2008-02-20 08:44 • by taylonr
177968 in reply to 177958
of course, the where clauses were also in the SQLSentences

Re: SQL Sentences

2008-02-20 08:47 • by pillus (unregistered)
Though David wasn't around when these changes were implemented, when he came onboard and heard the story he asked the Lead Developer if he'd ever heard of a Stored Procedure before.

Misread that last part as Stoned Procedure. That could have been, too.

Re: SQL Sentences

2008-02-20 08:48 • by A Nonny Mouse
you had me at "So, to address this problem, they thoroughly analyzed the development process and carefully tweaked it for efficiency. I’m just kidding." :)

Re: SQL Sentences

2008-02-20 08:53 • by Cosmin Marginean (unregistered)
- Did you hear about spoons?
- Yes, but I also heard that they are a pain in the ass for some reason (I don't know why), so I'm gonna keep eating my soup with the fork.

Re: SQL Sentences

2008-02-20 08:55 • by Dave (unregistered)
177974 in reply to 177958
snoofle:
Soooo, hard coded magic numbers, double the amout of code, an indirect requiring multiple DB reads just to figure out what to do, and presuming arguments needed to be passed to the query's where-clause, the whole thing was hard-wired anyway.

Nice!


Wow, you noticed that too?

Re: SQL Sentences

2008-02-20 08:57 • by rbowes
Heh, that reminds me of a not-really-WTFey project I once did for a university.

Basically, they had a legacy system with fixed-width text fields. They wanted to convert the whole thing to a different type of legacy system, that was comma-delimited. The problem was, the formats weren't directly translatable, some tables had to be combined and others torn apart.

Additionally, we were doing this work for VB developers who at least had a handle on SQL.

So what did we do?

We wrote a ~100-line program that would read "tbl_queries", which held an entry for each column in the new format. When the program ran, it would import the old format to MySQL, run the query for each output column, and output all the old data to the new format.

It ran beautifully!

Re: SQL Sentences

2008-02-20 09:04 • by Jon B (unregistered)
Some developers may want to use constants. Others might want functions to write the SQL:

string sql;
// @SQLSentence=0x02f0
if ((bool)(Configuration.GetValue("UseHardcodedSQL")))
{
sql = "SELECT cust_name, cust_phone, cust_addr " +
" FROM customers WHERE cust_type='Active'";
}
else if ((bool)(Configuration.GetValue("UseSQLConstants")))
{
sql = GET_CUSTOMERS;
}
else if ((bool)(Configuration.GetValue("UseSQLFunctions")))
{
sql = GetCustomerSql();
}
else
{
sql = DataConnector.GetSQLSentence(0x02f0);
}

Re: SQL Sentences

2008-02-20 09:05 • by J. Irvine (unregistered)
I wish I could say this was new to me, but we use a similar system here. We store statements such as "SELECT * FROM Table WHERE ?1?" in a table, then our homegrown data access object takes a numeric ID and a parameter list, replaces the wild cards, and executes the statement.

The reason for doing this, of course, is to "prevent SQL injection attacks". Never mind that the developers can simply fill in the wild cards with whatever they want, including user input: since it's in the database already, there's no way for an injection attack to succeed.

Fortunately, the management does listen to reason occasionally and we're now free to use stored procs and actual injection prevention for new code. The old stuff doesn't show any sign of going away, though.

Re: SQL Sentences

2008-02-20 09:05 • by Marc B (unregistered)
But where do they store the SQL code that queries the sql_sentences table?

Re: SQL Sentences

2008-02-20 09:06 • by Coincoin
I wonder if the queries inside DataConnector.GetSQLSentence(0x02f0); are also in the database... if so, is the query to retrieve that query also in the database.

We should rate programmers on how many layers of useless indirection they write before they realize their idea is stupid. +10 bonus for using integers as identifier per layer. We could call that the Enterprisey Programmer Scale.

Re: SQL Sentences

2008-02-20 09:16 • by Anonymous (unregistered)
I've got a much better solution for them:
- Program a Turing machine interpreter in SQL (its possible! i've done this)
- Program your business logic as a Turing machine and store it in the DB

This has major advantages:
- Barely anything needs to be done in the hardcoded program, making maintenance easy
- If SQL ever changes (or if you switch to a different DBMS) you only need to change the Turing machine interpreter - perfect portability

Re: SQL Sentences

2008-02-20 09:24 • by John (unregistered)
177984 in reply to 177962
akatherder, that's actually a very good idea. You are a genius. If we can get enough donations, then we could patent all the really bad ideas, and then if people use them, we can charge them a fortune for it (as a kind of fine for being so stupid).

The only problem with this idea is that because some idiot thought of it first, then you can't really patent it as he/she would own the patent.

To work around this problem, we all need to put our collective heads together and come up with the most f*&#ed up and deranged ideas we can think of, and then get enough money together to patent them all. We'll get our money back in the end, from all the patent infringement fees.

WE'LL ALL BE RICH! RICH I SAY! DID YOU HEAR ME? RICH!

Re: SQL Sentences

2008-02-20 09:25 • by NO no NO! (unregistered)
Why!? Why were these stores SQL Sentences stored as XML strings? That would add a lot more enterprisey and usability/maintanability!!! Why?!

Re: SQL Sentences

2008-02-20 09:32 • by T604 (unregistered)
177990 in reply to 177986
NO no NO!:
Why!? Why were these stores SQL Sentences stored as XML strings? That would add a lot more enterprisey and usability/maintanability!!! Why?!


That sounds like ibatis.

Re: SQL Sentences

2008-02-20 09:42 • by vereor (unregistered)
Saving in the data base is a bad idea, but referencing something by a HEX number is a good one...

They could have just #define GET_ALL_CUSTOMERS 0x00F9 in their header file... I don't see the problem with that.

But reading SQL via SQL doesn't seem like a good idea, if they got injection attacked they whole program could be took over.

All you credit cards and bank info are belong us.

Re: SQL Sentences

2008-02-20 09:43 • by Chris G (unregistered)
One of my previous workplaces the entire database was just three columns: TABLE_NAME, COLUMN_NAME, DATA_TYPE. I suspect you'll get the idea....

You might call it'a self-aware database...??

Re: SQL Sentences

2008-02-20 09:50 • by death
OUCH! Views and stored procedures... who needs them, right:P

Re: SQL Sentences

2008-02-20 09:52 • by GalacticCowboy
178002 in reply to 177996
Chris G:
One of my previous workplaces the entire database was just three columns: TABLE_NAME, COLUMN_NAME, DATA_TYPE. I suspect you'll get the idea....

You might call it'a self-aware database...??


What about the actual value? I recommend a separate (nullable) column for each data type. So, INTEGER_VALUE, DATETIME_VALUE, NVARCHAR_50_VALUE, etc. If you want to abstract this, everything can be stored as a VARCHAR(50) anyway...

Re: SQL Sentences

2008-02-20 09:58 • by Outlaw Programmer
178004 in reply to 177995
vereor:
Saving in the data base is a bad idea, but referencing something by a HEX number is a good one...

They could have just #define GET_ALL_CUSTOMERS 0x00F9 in their header file... I don't see the problem with that...


Uhhh what? If they are given some arbitrary identifier, then how are you supposed to look these things up to see if a query you want already exists? This looks like C# also so no #define statements either.

That said, what these guys are trying to do isn't the craziest idea that I've ever heard of, but it may be the craziest implementation. At my company we do maintain a mapping of key -> statement, but we keep it in a simple properties file and not the database itself. The vast majority of these statements are calls to stored procedures, though.

You have to remember that the whole purpose of this was to facilitate bug fixes. These guys recognized that lots of changes needed to be made to their SQL statements so they needed a way to change these easily without recompiling the code. Except for the fact that they are hardcoding these things anyway in that stupid switch statement, separating your code from your SQL stuff isn't such a bad idea.

Re: SQL Sentences

2008-02-20 09:59 • by snoofle
178005 in reply to 177974
Dave:
snoofle:
Soooo, hard coded magic numbers, double the amout of code, an indirect requiring multiple DB reads just to figure out what to do, and presuming arguments needed to be passed to the query's where-clause, the whole thing was hard-wired anyway.

Nice!


Wow, you noticed that too?

Actually, I noticed it first, but yes, I am Master of the Obvious!

Re: SQL Sentences

2008-02-20 10:11 • by FredSaw
178014 in reply to 177995
vereor:
All you credit cards and bank info are belong us.
Wow! Multiple layers of Engrish!

Re: SQL Sentences

2008-02-20 10:13 • by FredSaw
178015 in reply to 177973
Cosmin Marginean:
- Did you hear about spoons?
- Yes, but I also heard that they are a pain in the ass for some reason (I don't know why), so I'm gonna keep eating my soup with the fork.
Reminds me of that poem:

I eat my peas with honey;
I've done it all my life.
It makes the peas taste funny,
But it keeps them on my knife.

Re: SQL Sentences

2008-02-20 10:22 • by dpm
178021 in reply to 177963
Drum D.:
How can one become "lead" developer by relying on hearsay? Probably because the superiors "heard" this person "is fit for the job". UnbeWTFinglievable!


Obviously, the superiors heard about him from the secretary, just like any other normal software company.

Re: SQL Sentences

2008-02-20 10:22 • by Zonkers
Though David wasn't around when these changes were implemented, when he came onboard and heard the story he asked the Lead Developer if he'd ever heard of a Stored Procedure before.

“Yeah,” he replied, “but I’ve heard they’re a big pain to maintain.”

Classic. I laughed so hard when I read this.

Re: SQL Sentences

2008-02-20 10:22 • by Barf 4 Eva (unregistered)
"Though David wasn't around when these changes were implemented, when he came onboard and heard the story he asked the Lead Developer if he'd ever heard of a Stored Procedure before.

“Yeah,” he replied, “but I’ve heard they’re a big pain to maintain.” "


BWAHAHAHAHAHAHAHA! where's the 2 drum hits and a cymbal?
That sounded just like a punchline to a joke, WHERE punchline = 'sprocs a pain to maintain' and joke = 'sql sentences stored in a database' Although not a very funny one if you were hearing it in person, I'd imagine...

Also kinda funny, that to use the SQL, they jump up network traffic to GET the SQL to go BACK to the database WITH the SQL.. I don't even want to think about concurrency issues..

Re: SQL Sentences

2008-02-20 10:23 • by savar
178025 in reply to 177958
snoofle:
Soooo, hard coded magic numbers, double the amout of code, an indirect requiring multiple DB reads just to figure out what to do, and presuming arguments needed to be passed to the query's where-clause, the whole thing was hard-wired anyway.

Nice!


...and how does this fix their deployment problem?? <confused>

Re: SQL Sentences

2008-02-20 10:30 • by J (unregistered)
178032 in reply to 178014
I've encountered Stored Procedure Fear many times and I don't get it. A quick Google search turns up a few sites explaining why they are evil and unnecessary - the authors of these sites typically claim that they are "old school" and experience has taught them that dynamic SQL is better.

Who do you think commits more "custom solution" WTFs? Young programmers who haven't yet learned that there's a better way to do something or old programmers who insist that their personally developed code is superior to common practice?

Re: SQL Sentences

2008-02-20 10:48 • by Licky Lindsay
178052 in reply to 178032
The kicker here is the hexadecimal identifiers for each sentence. I've seen half-ass homemade stored procedures like this several times in real applications, so it would be only a mild WTF for me. But I don't think I've ever seen them named with this amount of opacity before. Wow.

Re: SQL Sentences

2008-02-20 10:49 • by snoofle
178053 in reply to 178025
savar:
snoofle:
Soooo, hard coded magic numbers, double the amout of code, an indirect requiring multiple DB reads just to figure out what to do, and presuming arguments needed to be passed to the query's where-clause, the whole thing was hard-wired anyway.

Nice!


...and how does this fix their deployment problem?? <confused>

It doesn't; a big part of the wtf!

Re: SQL Sentences

2008-02-20 10:49 • by Droll Troll on a roll (unregistered)
Another case of someone trying to reinvent an existing technology because they think they can make it better just like HyperParser.

I learned long ago that in corporate IT everything has already been done by smart people. I just have to find the solution, license and implement it. It is a great job. No stress and great hours for decent pay. However, I do have to look elsewhere for any kind of mental challenge, but I don't consider that a drawback because I don't live to work.

Re: SQL Sentences

2008-02-20 10:52 • by Staszek (unregistered)
DRWTF is buried at the begining of second paragraph:

"Management figured that, (...)"

Everything else is just a downstream effect of business team developing a technical solution. Major no-no.

Re: SQL Sentences

2008-02-20 10:57 • by bungeman (unregistered)
178058 in reply to 178002
I wish you were joking, that I didn't understand what you were talking about, and that I wasn't working with people (lead architects) who think this is a good idea.

Re: SQL Sentences

2008-02-20 11:05 • by Barf 4 Eva (unregistered)
178061 in reply to 178032
J:
I've encountered Stored Procedure Fear many times and I don't get it. A quick Google search turns up a few sites explaining why they are evil and unnecessary - the authors of these sites typically claim that they are "old school" and experience has taught them that dynamic SQL is better.

Who do you think commits more "custom solution" WTFs? Young programmers who haven't yet learned that there's a better way to do something or old programmers who insist that their personally developed code is superior to common practice?


sprocs have been around for a while, so I'd say it's not a matter of old vs new. However, what really gets me about the purely dynamic crowd and the purely stored procedure crowd is that neither of them seem to realize how properly managing dynamic sql IN a stored procedure can yield EXTREMELY great results. As long as you understand how sql text is parsed by the engine in determining when a new execution plan is generated, utilizing both (sproc with dynamic sql) in the appropriate amounts will yield excellent results and better maintainability. There are many people who swear by this, and make an excellent case for such use. Check out Erland Sommarskog for example, this guy knows his shit!!!

Re: SQL Sentences

2008-02-20 11:07 • by Barf 4 Eva (unregistered)
178064 in reply to 178061
Barf 4 Eva:
J:

There are many people who swear by this, and make an excellent case for such use. Check out Erland Sommarskog for example, this guy knows his shit!!!


doh... And so that I don't mis-state his position, on his site he gives many different examples of properly maintaining dynamic sql... Obviously via a sproc is just one way.

Re: SQL Sentences

2008-02-20 11:20 • by Licky Lindsay
Re: the "useHardCodedSQL" config setting, yes I've seen that in real life too.

An app started out with hard-coded queries:


<cfquery name="get_products" ds="#datasource#>
select * from products where customer_id=#customer_id#
</cfquery>


Then someone had the idea that stored procs were the way to go. They used a perl or sed script or something to run through all the code and find all the queries and make them all be like this:


<cfif storedProcs>
<cfquery name="get_products" ds="#datasource#>
select * from products where customer_id=#customer_id#
</cfquery>
<cfelse>
<cfquery name="get_products" ds="#datasource#>
select * from products where customer_id=#customer_id#
</cfquery>
</cfif>


Yes, its the same on both branches. Someone then had to manually go through and change it:


<cfif storedProcs>
{call sp_get_products(#customer_id#)}
<cfelse>
<cfquery name="get_products" ds="#datasource#>
select * from products where customer_id=#customer_id#
</cfquery>
</cfif>


Well, they never made it through the whole app. Lots and lots of queries remained with the same SQL code repeated twice. Most of them, in fact. Then they abandoned the whole idea of converting everything to stored procs, but left all this code in.

Because the "storedProcs" config setting had already been set to true and left that way permanently, people eventually started only bothering to maintain the SQL on the true side. So for instance say they added a new column "status" and some more logic:


<cfif storedProcs>
<cfquery name="get_products" ds="#datasource#>
select * from products where
customer_id=#customer_id#
and status = 1
</cfquery>
<cfelse>
<cfquery name="get_products" ds="#datasource#>
select * from products where customer_id=#customer_id#
</cfquery>
</cfif>


So if you ever turned "storedProcs" off, the app would run the wrong SQL, even through stored procedures weren't being used at all.

Re: SQL Sentences

2008-02-20 11:36 • by Stupidumb
Quis query ipsos queries?

Re: SQL Sentences

2008-02-20 11:52 • by brazzy
178086 in reply to 178055
Droll Troll on a roll:
Another case of someone trying to reinvent an existing technology because they think they can make it better just like HyperParser.

It's really more another case of someone creating a horrible, unusable, unmaintainable mess in the name of "not hardcoding stuff". They're probably proud because it's so much more flexible and maintainable.

This kind of thing is frighteningly common amongst architects and framework programmers who come up with APIs that they don't have to use themselves.

Re: SQL Sentences

2008-02-20 11:53 • by Ubersoldat (unregistered)
“but I’ve heard they’re a big pain to maintain.”

What? I'm no DBA but what? Maybe I missed something when I studied SP's but "a big pain" is not the idea I had. Maybe some experienced DBA can explain us in which way SP are a pain to maintain, must be so complex that my IQ doesn't reach there.

Anyway, what a stupid solution for such a simple matter. Thank god they weren't using C/C++ and filled it with DEFINE's.

Re: SQL Sentences

2008-02-20 11:53 • by Andrew (unregistered)
178088 in reply to 177984
John:
akatherder, that's actually a very good idea. You are a genius. If we can get enough donations, then we could patent all the really bad ideas, and then if people use them, we can charge them a fortune for it (as a kind of fine for being so stupid).

The only problem with this idea is that because some idiot thought of it first, then you can't really patent it as he/she would own the patent.

To work around this problem, we all need to put our collective heads together and come up with the most f*&#ed up and deranged ideas we can think of, and then get enough money together to patent them all. We'll get our money back in the end, from all the patent infringement fees.

WE'LL ALL BE RICH! RICH I SAY! DID YOU HEAR ME? RICH!


This site alone lists too much prior art! How many patents could we get past review?

Re: SQL Sentences

2008-02-20 12:11 • by Anonymous (unregistered)
178095 in reply to 178014
FredSaw:
vereor:
All you credit cards and bank info are belong us.
Wow! Multiple layers of Engrish!

Welcome to the Internet. Yes, we know that these owls and cats look funny, we noticed that too.

Re: SQL Sentences

2008-02-20 12:19 • by OMGWTFBBQ (unregistered)
178097 in reply to 177984
John:
akatherder, that's actually a very good idea. You are a genius. If we can get enough donations, then we could patent all the really bad ideas, and then if people use them, we can charge them a fortune for it (as a kind of fine for being so stupid).

The only problem with this idea is that because some idiot thought of it first, then you can't really patent it as he/she would own the patent.

To work around this problem, we all need to put our collective heads together and come up with the most f*&#ed up and deranged ideas we can think of, and then get enough money together to patent them all. We'll get our money back in the end, from all the patent infringement fees.

WE'LL ALL BE RICH! RICH I SAY! DID YOU HEAR ME? RICH!


Alex is way ahead of you.

Re: SQL Sentences

2008-02-20 12:42 • by Zonkers
178104 in reply to 178055
I learned long ago that in corporate IT everything has already been done by smart people. I just have to find the solution, license and implement it.


This is so true in CS in general. I do game development and I'm constantly amazed by the gall that game programmers have when they think they write a better mousetrap.

We (as an industry) still think that it's a good idea to always write a custom memory handling code for every project rather than having the OS handle it like a normal application. This may make sense on PS3 or something (not even sure about this) but on Windows? Mac? or Linux??? Are you crazy?!! Game programmers always like to say games are different than normal apps when it comes to memory management and OS's just can't handle it well. Riiiiight.

Usually it makes sense to tweak things here and there like allocate a huge block of memory when you know you are going to fill it all up right away then throw it all away. But to write a full memory allocation routine for everything in the heap is just madness in my opinion and usually is a cause of painful hard to debug errors when things like "page" handling breaks. Or more commonly, huge unneeded memory usage when your heap becomes all fragmented to hell and it becomes nontrivial to reclaim "freed" memory in an efficient manner. Just leave that to the OS developers! They've worked on that problem for a long time and know their domain way better than we do.

Re: SQL Sentences

2008-02-20 12:50 • by GalacticCowboy
178107 in reply to 178104
Zonkers:
We (as an industry) still think that it's a good idea to always write a custom memory handling code for every project rather than having the OS handle it like a normal application. This may make sense on PS3 or something (not even sure about this) but on Windows? Mac? or Linux??? Are you crazy?!! Game programmers always like to say games are different than normal apps when it comes to memory management and OS's just can't handle it well. Riiiiight.


Even if what "they" say is true, it still doesn't make sense to solve the problem again and again. Either build a library of code that you can reuse or - even better - find someone else who has already solved the problem better than you ever could, and reuse their code. As you say, these are the types of problems that have already been solved by people much smarter than you and I.

Re: SQL Sentences

2008-02-20 13:34 • by Peter X (unregistered)
My company did this. Seriously.

Major european contractor of municipial software. The bonus part is guess where parameters to a query is handled? client or server?

You guessed right. Major fucking secority hole. Luckely it is not a public system.
« PrevPage 1 | Page 2Next »

Add Comment