Backtracing an SQL error shown in drupal set message with no specifying information
turn on error reporting for php. turn on mysql query log and inspect new queries -- add a simple parameter you can lookup like SELECT ..., 'IS-THIS-BROKEN-1' as debug_key to easily find your quer(ies) in the mysql log file. ... Views offer such a debug parameter for views sql queries too ... my point is there are better ways to tackle this that strictly form your PHP code and drupal_set_message.