### Eclipse Workspace Patch 1.0
#P drupal
Index: modules/imagecache/imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/sandbox/quicksketch/imagecache/imagecache.module,v
retrieving revision 1.2
diff -u -r1.2 imagecache.module
--- modules/imagecache/imagecache.module	16 Oct 2006 22:34:21 -0000	1.2
+++ modules/imagecache/imagecache.module	16 Oct 2006 23:15:07 -0000
@@ -314,7 +314,8 @@
  *    name of the ruleset to be created.
  */
 function _imagecache_ruleset_create($name) {
-  db_query('INSERT INTO {imagecache_rulesets} (rulesetname) VALUES (\'%s\')', $name);
+  $next_id = db_next_id('{imagecache_rulesets}_rulesetid');
+  db_query('INSERT INTO {imagecache_rulesets} (rulesetid,rulesetname) VALUES (%d,\'%s\')', $next_id, $name);
   $path = file_directory_path(). '/imagecache/'.$name;
   //debug_msg($path);
   $_REQUEST['destination'] = 'admin/imagecache/preset/' . $next_id;
@@ -380,7 +381,8 @@
 
 function _imagecache_action_create($action) {
   //debug_msg($action, 'action@create: ');
-  db_query('INSERT INTO {imagecache_actions} (rulesetid, weight, data) VALUES (%d, %d, "%s")', $action['rulesetid'], $action['weight'], serialize($action['data']));
+  $next_id = db_next_id('{imagecache_actions}_actionid');
+  db_query('INSERT INTO {imagecache_actions} (actionid, rulesetid, weight, data) VALUES (%d, %d, %d, "%s")', $next_id, $action['rulesetid'], $action['weight'], serialize($action['data']));
   $_REQUEST['destination'] = 'admin/imagecache/preset/' . $next_id;
 }
 
Index: modules/imagecache/imagecache.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/sandbox/quicksketch/imagecache/imagecache.install,v
retrieving revision 1.1
diff -u -r1.1 imagecache.install
--- modules/imagecache/imagecache.install	16 Oct 2006 22:29:59 -0000	1.1
+++ modules/imagecache/imagecache.install	16 Oct 2006 23:15:06 -0000
@@ -1,34 +1,34 @@
 <?php
-// $Id: imagecache.install,v 1.1 2006/10/16 22:29:59 quicksketch Exp $
+// $Id: imagecache.install,v 1.2 2006/10/16 22:43:44 quicksketch Exp $
 
 function imagecache_install() {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
       $ret1 = db_query('CREATE TABLE {imagecache_rulesets} (
-            rulesetid INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
+            rulesetid INT UNSIGNED NOT NULL PRIMARY KEY,
             rulesetname VARCHAR(255) NOT NULL DEFAULT \'\' )'
       );
 
       $ret2 = db_query('CREATE TABLE {imagecache_actions} (
-            actionid INT UNSIGNED NOT NULL PRIMARY KEY auto_increment,
+            actionid INT UNSIGNED NOT NULL PRIMARY KEY,
             rulesetid INT UNSIGNED NOT NULL DEFAULT 0,
             weight INT NOT NULL DEFAULT 0,
-            data VARCHAR(255) NOT NULL DEFAULT \'\');'
+            data TEXT NOT NULL DEFAULT \'\');'
       );
       break;
 
     case 'pgsql':
       $ret1 = db_query('CREATE TABLE {imagecache_rulesets} (
-            rulesetid SERIAL NOT NULL,
+            rulesetid INTEGER NOT NULL CHECK (rulesetid > 0),
             rulesetname VARCHAR(255) NOT NULL DEFAULT \'\',
             PRIMARY KEY (rulesetid));'
       );
       $ret2 = db_query('CREATE TABLE {imagecache_actions} (
-            actionid SERIAL NOT NULL,
+            actionid INTEGER NOT NULL CHECK (rulesetid > 0),
             rulesetid INTEGER NOT NULL DEFAULT 0,
             weight INTEGER NOT NULL DEFAULT 0,
-            data VARCHAR(255) NOT NULL DEFAULT \'\',
+            data TEXT NOT NULL DEFAULT \'\',
             PRIMARY KEY (actionid));'
       );
       break;
@@ -37,10 +37,37 @@
   if ($ret1 && $ret2) {
     drupal_set_message(t('Imagecache module installed succesfully.'));
   } else {
-    drupal_set_message(t('Imagecache module installation was unsuccesfull. Necessary database tables should be created by hand.', 'error'));
+    drupal_set_message(t('Imagecache module installation was unsuccessful. Necessary database tables should be created by hand.', 'error'));
   }
 }
 
 function imagecache_update_1() {
-  update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL  primary key auto_increment');
+  $ret = array();
+  $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL primary key auto_increment');
+  return $ret;
+}
+
+/**
+ * Remove auto-increment from tables, instead depending on the sequences table and db_next_id()
+ */
+function imagecache_update_2() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql('ALTER TABLE {imagecache_actions} CHANGE actionid actionid INT UNSIGNED NOT NULL');
+      $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} CHANGE rulesetid rulesetid INT UNSIGNED NOT NULL');
+    case 'pgsql':
+      db_change_column($ret, 'imagecache_actions', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
+      db_change_column($ret, 'imagecache_rulesets', 'rulesetid', 'rulesetid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
+      // Re-add our indexes
+      $ret[] = update_sql("ALTER TABLE {imagecache_actions} ADD PRIMARY KEY (actionid)");
+      $ret[] = update_sql("ALTER TABLE {imagecache_rulesets} ADD PRIMARY KEY (rulesetid)");
+  }
+  // Create the columns in the sequences table
+  $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_actions}'));
+  $count_ruleset = db_result(db_query('SELECT max(rulesetid) FROM {imagecache_rulesets}'));
+  $ret[] = update_sql('INSERT INTO {sequences} (name, id) VALUES (\'{imagecache_actions}_actionid\',' . $count_action . ')');
+  $ret[] = update_sql('INSERT INTO {sequences} (name, id) VALUES (\'{imagecache_rulesets}_rulesetid\',' . $count_ruleset . ')');
+  return $ret;
 }
