Quick background:
We have this program, that handles database connections and returns the data for us. We're using it to query multiple databases at once. (No, I don't know why we can't do that ourselves.)
It doesn't support dates. If you try and pull a date value out of a database, it will return with an "undefined" value. But we need dates.
So I come up with a plan. I can write a JDBC wrapper that wraps around the actual JDBC drivers and "mask" the existance of dates in the results. That way the data can be in a format that actually works.
Except that it turns out this program is smarter than I thought it was and actually had the database do queries for it instead of just pulling in the data and manipulating it itself. (Although now I'm left wondering why it's so slow to do so.)
Well, long story short, it turns out that 123456789 isn't a valid SQL date. So when it tries to do:
SELECT date FROM table WHERE date <= 1000000000 AND date >= 1100000000
It doesn't work, causing an error. (Except in MySQL, where it merrily runs the query because MySQL sucks. I have no idea what it thinks that query is, though.)
Except I'm lieing. The above ISN'T what it actually tries. No, instead it tries to run:
SELECT MYALIAStable.date FROM table MYALIAStable WHERE (MYALIAStable.date <= 1.0E9 AND MYALIAStable.date >= 1.1E9) AND ( 1 = 1 )
I'm assuming the ( 1 = 1 ) is there because they always add a WHERE clause and this allows them to just dump clauses into it without thinking. (As opposed to saying "if this is the first clause, add WHERE, if it's not, add AND" which works out the same without 1=1.)
Well, we want another feature that it doesn't provide: substring matching. So instead of:
SELECT string FROM table WHERE string = 'a string'
We want:
SELECT string FROM table WHERE string LIKE '%a string%'
So how does this program handle string matching?
SELECT MYALIAStable.string FROM table MYALIAStable WHERE (MYALIAStable.string <= 'a string' AND MYALIAStable.string >= 'a string') AND ( 1 = 1 )
Of course.
Sigh.
I think I'm going to go insane.