Article 6E17A CodeSOD: More and More Replacements

CodeSOD: More and More Replacements

by
Remy Porter
from The Daily WTF on (#6E17A)

You can do a lot in an SQL query. But sometimes, you should probably do less, like this ad-hoc ORDER BY clause from KT.

sql = sql + "Order By Section, " +"replace(replace(replace(replace(" + "replace(replace(replace(replace(replace(replace(replace(replace" +"(replace('.' +Num + '.','.2.','.02.'),'.1.','.01.'),'.3.','.03.')" + ",'.4.','.04.'),'.6.','.06.'),'.5.','.05.'),'.7.','.07.')" + ",'.8.','.08.'),'.9.','.09.'),'.5.','.05.'),'.1.','.01.')" + ",'.2','.02'),'.3','.03')";

The line-breaks were not in the original, but I wanted this to be vaguely readable.

On one hand, this is possibly the symptom of a really bad data model, where Num fields encode some meaningful identifier one way, but other applications need it represented another way. But then I notice that some of the replacements get repeated (.5. and .1.), and some are just similar (.2. vs. .2), and then I suspect someone just had no clue what was happening here.

buildmaster-icon.png [Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments