I need some guru help -- if there's an easier way please tell me. I
have a MySQL ambiguity bug in a query -- I thought I had nailed all
these issues but I saw one in my error log and need to pinpoint the
query that is actually causing it. It has to do with something in some
convoluted pagination stuff I'm doing and I just can't see the error
nor reproduce it.

So what I want to do is make cake write the whole query to the error
log when it happens -- not to the screen as we are running DBEUG=1 at
the moment and this occured on a production site (can't goto debug=2
becuase all the extraneous output users will see).

So I see in dbosource.php where in the execute function it calls
logQuery on error to pitch the query to the screen, and calls
showQuery which ends up (DEBUG=1) sending the SQL error msg to my
error.log.

I seriously doubt I can use $this->log in this context to pitch the
entire sql query into the error log -- what is the easiest way to make
this happen? trigger_error is sending my output to the error log --
where is this setup and why does this output end up in my error.log
file instead of onscreen?

This is driving me insane. I fully specify model.field in all my
queries, I know exactly which query is generating the problem, just
not in what context or circumstances and I have been unable to
reproduce it. Logging the errors as well as some of the parms around
the call I'm hoping it happens again and I have enough evidence to
track the real problem down.


/**
 * Log given SQL query.
 *
 * @param string $sql SQL statement
 * @todo: Add hook to log errors instead of returning false
 */
        function logQuery($sql) {
                $this->_queriesCnt++;
                $this->_queriesTime += $this->took;
                $this->_queriesLog[] = array('query' => $sql,
                                        'error'         => $this->error,
                                        'affected'      => $this->affected,
                                        'numRows'       => $this->numRows,
                                        'took'          => $this->took
                );
                if (count($this->_queriesLog) > $this->_queriesLogMax) {
                        array_pop($this->_queriesLog);
                }
                if ($this->error) {
                        return false;
                }
        }
/**
 * Output information about an SQL query. The SQL statement, number of
rows in resultset,
 * and execution time in microseconds. If the query fails, an error is
output instead.
 *
 * @param string $sql Query to show information on.
 */
        function showQuery($sql) {
                $error = $this->error;
                if (strlen($sql) > 200 && !$this->fullDebug && 
Configure::read() >
1) {
                        $sql = substr($sql, 0, 200) . '[...]';
                }

                if (($this->debug || $error) && Configure::read() > 0) {
                        e("<p style = \"text-align:left\"><b>Query:</b> {$sql} 
");
                        if ($error) {
                                trigger_error("<span style = 
\"color:Red;text-align:left\"><b>SQL
Error:</b> {$this->error}</span>", E_USER_WARNING);
                        } else {
                                e("<small>[Aff:{$this->affected} 
Num:{$this->numRows} Took:{$this-
>took}ms]</small>");
                        }
                        print ('</p>');
                }
        }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to