You are here

function imagecache_update_3 in ImageCache 5.2

Same name and namespace in other branches
  1. 5 imagecache.install \imagecache_update_3()
  2. 6.2 imagecache.install \imagecache_update_3()

Remove auto-increment from tables, instead depending on the sequences table and db_next_id()

File

./imagecache.install, line 161

Code

function imagecache_update_3() {
  $ret = array();
  $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1;
  $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1;
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL");
      $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL");

      // Add the sequences
      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', {$count_action})");
      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', {$count_preset})");
      break;
    case 'pgsql':
      db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array(
        'not null' => TRUE,
        'default' => '0',
      ));

      // Re-add our indexes
      $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)");
      $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)");

      // Add the sequences
      $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START {$count_action};");
      $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START {$count_preset};");
  }
  return $ret;
}