Monday, December 17, 2007

It's not the bloddy PHP programmers, I think.

Looking at a SQL error can be daunting, particularly with no formatting. I always find it easier to format the statement for readability. It should be written that way, but it may be formatted in the code, but not when submitted, or the error message may have stripped line feeds.

I don't know PostgreSQL, but in general, SQL is the same, in broad strokes across implementations.

The error message:
Query failed:  ERROR: syntax error at or near "contact_name_owner"
The beginning of the statement:
(SELECT
meetings.id ,
meetings.name,
meetings.status,
' ' AS contact_name ,
' ' AS contact_id ,
' ' contact_name_owner ,
' ' contact_name_mod ,
meetings.date_modified ,
jt1.user_name AS assigned_user_name ,
jt1.created_by AS assigned_user_name_owner ,
'Users' AS assigned_user_name_mod,
' ' filename ,
meetings.assigned_user_id ,
'meetings' AS panel_name
FROM meetings LEFT JOIN users AS jt1 ON jt1.id= meetings.assigned_user_id
AND jt1.deleted=0
AND jt1.deleted=0
where
(
meetings.parent_id= 'd3e15dc6-9525-d1b8-63fb-474f614635fa' AND
meetings.parent_type='Leads' AND
meetings.deleted=0 AND
(
meetings.status='Held' OR meetings.status='Not Held'
)
)
AND meetings.deleted=0
) UNION ALL
...
I think the problem is a missing AS in the column alias.
  ' ' contact_name_owner
It should be
  ' ' AS contact_name_owner
It appears to be missing it in a few places.

Hey, at least you got an error. Sometimes you don't even get an error, it just doesn't work.

3 comments:

Chrisranjana.com software said...

Also it pays not to show elaborate SQL errors to the average web user in view of the security risks associated. Instead SQL errors can be written to a log file which can be securely accessed only by the admin

Chrisranjana.com
Php Programmers

Unknown said...

1. I didn't write the mess.

2. I didn't port the mess (from MySQL to PostgreSQL)

3. I have to deal with the mess.

Jeff said...

Most projects I work on tend to follow your three step approach.

Post a Comment