* * * * *

                     WTF? And I do mean, seriously, WTF?

I've been looking into The Error From Hell [1], and seeing how I'm given the
exact line number where the error occurs, I thought I'd start there.

So, line 136 from include/database/pgsqlManager.php:

> $result = pg_query($sql);
>

Nice.

So, to see the full query that's failing, I decide to print out the query
just before it's made. And that's when I realize that the function this line
appears in is called several times throughout the program (not all SQL
(Structured Query Language) calls are funneled through this function, just
enough to make it painful).

Nice.

Okay, approach the problem from a different angle. What's the function that
this piece of code is in? Oh, that's easy—query().

Okay, try a different approach.

The error complains about a syntax error near contact_name_owner, so let's
try looking for that. Thirty-one loations where it's used, but none of them
appear to construct a 3,544 character long SQL statement, and the one place
where such a statement might be constructed, isn't called.

Head?

Meet Mr. Desk.

Mr. Desk? Meet my head.

Ouch.

I think I see the problem:

> … ' ' AS contact_name , ' ' AS contact_id , ' ' contact_name_owner …
>

It seems as if there's a few missing ASes in the SQL Statement From Hell, but
not knowing where it's constructed (or even how), it's not that easy to fix.

Or rather … there is a way …

Just before I call pg_query(), scan the string, looking for missing ASes and
add them as required, maybe using some form of regular expression search and
replace funct—[at this point, Sean's head exploded from even entertaining
such a notion and was pronounced “mostly dead” at the scene. Further updates
as they arrive. —Editor]

[1] gopher://gopher.conman.org/0Phlog:2007/12/17.1

Email author at [email protected]