Chris McGrath’s Blog

Just another Developer’s Blog

SQL Generators

leave a comment »

SQL Generators are known for how many brackets they love to put in. So many in fact it made a simple query hard to understand.

Like most professional developers I don’t spend too much time using generators, I much prefer to write the query myself. And I generally stay away from DataSets completely. But today I had to paste my SQL into a query in a DataSet, and I noticed how Microsoft had tried to optimise the Builder so when it reformatted my SQL it didn’t have so many brackets.

The problem was it removed the useful brackets and added useless ones.

Here’s what I entered…

(x1 = x2 AND y1 = y2) OR (n1 = n2 AND m1 = m2)

And here’s what it optimised it to…

(x1 = x2) AND (y1 = y2) OR (n1 = n2) AND (m1 = m2)

How completely stupid! The main reason anyone adds brackets in SQL is to make the order of operations absolutely clear. Yet it removes those ones and adds sets around single statements.

The query might be correct but a human has trouble – not everyone knows the order of operations with booleans.

Advertisements

Written by Chris McGrath

August 31, 2009 at 4:16 pm

Posted in Blog

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: