You are here

function devel_store_queries in Devel 5

Same name and namespace in other branches
  1. 6 devel.module \devel_store_queries()
1 call to devel_store_queries()
devel_shutdown in ./devel.module
See devel_init() which registers this function as a shutdown function. Displays developer information in the footer.
1 string reference to 'devel_store_queries'
devel_admin_settings in ./devel.module

File

./devel.module, line 599

Code

function devel_store_queries() {
  if (variable_get('devel_store_queries', 0) && rand(1, variable_get('devel_store_random', 1)) == 1) {
    global $active_db, $queries;
    $qids = array();
    $values = array();
    $fields = array();

    // We need this for the devel_queries insert below.
    setlocale(LC_NUMERIC, 'C');
    foreach ($queries as $value) {
      list($function, $query) = explode("\n", $value[0]);
      $query = preg_replace(array(
        "/'.*'/s",
        "/\\d.*\\.\\d.*/",
        "/\\d.*/",
      ), array(
        "S",
        "F",
        "D",
      ), $query);
      $hash = md5($function . $query);
      if (!isset($qids[$hash])) {
        $qids[$hash] = db_result(devel_db_query("SELECT qid FROM {devel_queries} WHERE hash = '%s'", $hash));
        if (!$qids[$hash]) {
          devel_db_query("INSERT INTO {devel_queries} (query, function, hash) VALUES ('%s', '%s', '%s')", $query, $function, $hash);
          $qids[$hash] = mysql_insert_id();
        }
      }
      $fields[] = "(%d, '%f')";
      $values[] = $qids[$hash];
      $values[] = $value[1];
    }
    if (count($fields)) {
      devel_db_query('INSERT INTO {devel_times} (qid, time) VALUES ' . implode(',', $fields), $values);
    }
  }
}