mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-75614-debugsqltrace' of https://github.com/brendanheywood/moodle
This commit is contained in:
commit
9911faf8be
@ -897,9 +897,6 @@ abstract class moodle_database {
|
||||
// convert table names
|
||||
$sql = $this->fix_table_names($sql);
|
||||
|
||||
// Optionally add debug trace to sql as a comment.
|
||||
$sql = $this->add_sql_debugging($sql);
|
||||
|
||||
// cast booleans to 1/0 int and detect forbidden objects
|
||||
foreach ($params as $key => $value) {
|
||||
$this->detect_objects($value);
|
||||
@ -911,6 +908,9 @@ abstract class moodle_database {
|
||||
$dollar_count = preg_match_all('/\$[1-9][0-9]*/', $sql, $dollar_matches);
|
||||
$q_count = substr_count($sql, '?');
|
||||
|
||||
// Optionally add debug trace to sql as a comment.
|
||||
$sql = $this->add_sql_debugging($sql);
|
||||
|
||||
$count = 0;
|
||||
|
||||
if ($named_count) {
|
||||
|
@ -519,6 +519,30 @@ EOD;
|
||||
$CFG->debugsqltrace = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the database debugging as SQL comment in anon class
|
||||
*
|
||||
* @covers ::add_sql_debugging
|
||||
*/
|
||||
public function test_sql_debugging_anon_class() {
|
||||
global $CFG;
|
||||
$CFG->debugsqltrace = 100;
|
||||
|
||||
// A anon class.
|
||||
$another = new class {
|
||||
/**
|
||||
* Just a test log function
|
||||
*/
|
||||
public function log() {
|
||||
global $DB;
|
||||
$DB->get_records_sql('SELECT firstname FROM {user} WHERE firstname = :firstname', ['firstname' => 'JohnDoe']);
|
||||
}
|
||||
};
|
||||
$another->log();
|
||||
$CFG->debugsqltrace = 0;
|
||||
// No assertions just it should not error.
|
||||
}
|
||||
|
||||
public function test_strtok() {
|
||||
// Strtok was previously used by bound emulation, make sure it is not used any more.
|
||||
$DB = $this->tdb;
|
||||
|
@ -697,18 +697,23 @@ function format_backtrace($callers, $plaintext = false) {
|
||||
if (!isset($caller['file'])) {
|
||||
$caller['file'] = 'unknownfile'; // probably call_user_func()
|
||||
}
|
||||
$from .= $plaintext ? '* ' : '<li>';
|
||||
$from .= 'line ' . $caller['line'] . ' of ' . str_replace($dirroot, '', $caller['file']);
|
||||
$line = $plaintext ? '* ' : '<li>';
|
||||
$line .= 'line ' . $caller['line'] . ' of ' . str_replace($dirroot, '', $caller['file']);
|
||||
if (isset($caller['function'])) {
|
||||
$from .= ': call to ';
|
||||
$line .= ': call to ';
|
||||
if (isset($caller['class'])) {
|
||||
$from .= $caller['class'] . $caller['type'];
|
||||
$line .= $caller['class'] . $caller['type'];
|
||||
}
|
||||
$from .= $caller['function'] . '()';
|
||||
$line .= $caller['function'] . '()';
|
||||
} else if (isset($caller['exception'])) {
|
||||
$from .= ': '.$caller['exception'].' thrown';
|
||||
$line .= ': '.$caller['exception'].' thrown';
|
||||
}
|
||||
$from .= $plaintext ? "\n" : '</li>';
|
||||
|
||||
// Remove any non printable chars.
|
||||
$line = preg_replace('/[[:^print:]]/', '', $line);
|
||||
|
||||
$line .= $plaintext ? "\n" : '</li>';
|
||||
$from .= $line;
|
||||
}
|
||||
$from .= $plaintext ? '' : '</ul>';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user