<?php
// $Id: devel.install,v 1.4.2.7 2006/11/23 03:31:19 weitzman Exp $
/**
 * Implementation of hook_install()
 */
function devel_install() {
  // New module weights in core: put devel as the very last in the chain.
  db_query("UPDATE {system} SET weight = 88 WHERE name = 'devel'");

  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $sql = "CREATE TABLE {devel_queries} (
        qid int(10) NOT NULL auto_increment,
        function varchar(255) NOT NULL default '',
        query text NOT NULL,
        hash varchar(255) NOT NULL default '',
        PRIMARY KEY (`hash`),
        KEY qid (qid)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */;";
      db_query($sql);

      $sql = "CREATE TABLE {devel_times} (
        tid int(10) NOT NULL auto_increment,
        qid int(10) NOT NULL default 0,
        time float default NULL,
        PRIMARY KEY (tid),
        KEY qid (qid)
      ) /*!40100 DEFAULT CHARACTER SET utf8 */;";
      db_query($sql);
      break;
  }

  // Enable the blocks automatically at install.
  _block_rehash();
}

/**
 * Do update 1 again as the hook_install() was missing and new
 * installations are not having the weight set.
 */
function devel_update_2() {
  // New module weights in core: put devel as the very last in the chain.
  $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'devel'");
  return $ret;
}

function devel_update_3() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $sql = "CREATE TABLE {devel_queries} (
        qid int(10) NOT NULL auto_increment,
        query varchar(255) NOT NULL default '',
        hash varchar(255) NOT NULL default '',
        PRIMARY KEY (`hash`),
        KEY qid (qid)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */;";
      $ret[] = update_sql($sql);

      $sql = "CREATE TABLE {devel_times} (
        tid int(10) NOT NULL auto_increment,
        qid int(10) NOT NULL default 0,
        time float default NULL,
        PRIMARY KEY (tid),
        KEY qid (qid)
      ) /*!40100 DEFAULT CHARACTER SET utf8 */;";
      $ret[] = update_sql($sql);
      return $ret;
  }
}

function devel_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {devel_queries} ADD `function` varchar(255) NOT NULL default ''");
  }
  return $ret;
}

function devel_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {devel_queries} CHANGE query query text NOT NULL");
  }
  return $ret;
}
