? fix_prefixing.patch
? fix_prefixing_2.patch
? fix_prefixing_3.patch
Index: object_driver.install
===================================================================
RCS file: object_driver.install
diff -N object_driver.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ object_driver.install	14 Jul 2007 15:36:10 -0000
@@ -0,0 +1,31 @@
+<?php
+// $Id$
+
+function object_driver_install() {
+  return;
+}
+
+/**
+* Fix mis-named rows in {sequences}.
+ */
+
+function object_driver_update_5000() {
+  $ret = array();
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+    $class_list = object_driver_class_list();
+    foreach ($class_list as $class) {
+      $id_name = $class .'_id';
+      $obj_def = call_user_func($class .'_class_define');
+      $table = isset($obj_def['table']) ? $obj_def['table'] : $class;
+
+      $max = db_result(db_query("SELECT MAX(". $id_name .") FROM {". $table ."}"));
+      $name = db_prefix_tables("{". $table ."}_id");
+      $ret[] = update_sql("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $max);
+    }
+  }
+  
+  return $ret;
+}
Index: object_driver.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/object_driver/object_driver.module,v
retrieving revision 1.9
diff -u -p -r1.9 object_driver.module
--- object_driver.module	8 Apr 2007 16:45:03 -0000	1.9
+++ object_driver.module	14 Jul 2007 15:36:11 -0000
@@ -459,7 +459,7 @@ function object_driver_load($class, $id,
     $obj_def = call_user_func($class .'_class_define');
     $table = isset($obj_def['table']) ? $obj_def['table'] : $class;
     
-    $obj = db_fetch_object(db_query("SELECT * FROM {%s} WHERE %s = %d", $table, $id_name, $id));
+    $obj = db_fetch_object(db_query("SELECT * FROM {". $table ."} WHERE %s = %d", $id_name, $id));
 
   }
   if (isset($obj->$id_name)) {
@@ -479,21 +479,22 @@ function object_driver_load($class, $id,
 function object_driver_save(&$obj) {
   $class = $obj->class;
 
-  $id_name = $class .'_id';
-  $obj->is_new = FALSE;
+  // Is this a new object?
+  $obj->is_new = empty($obj->$id_name);
 
-  if (empty($obj->$id_name)) {
-    // Insert a new object
-    $obj->is_new = TRUE;
-    $obj->$id_name = db_next_id("{$table}_id");
-  }
-  
   if (function_exists($class .'_save')) {
     call_user_func($class .'_save', $obj);
   }
   else { // Default functionality
+    $id_name = $class .'_id';
     $obj_def = call_user_func($class .'_class_define');
     $table = isset($obj_def['table']) ? $obj_def['table'] : $class;
+
+    if ($obj->is_new) {
+      // Insert a new object
+      $obj->$id_name = db_next_id("{". $table ."}_id");
+    }
+    
     $column_names = array();
     $column_placeholders = array();
     $column_assignments = array();
@@ -513,10 +514,10 @@ function object_driver_save(&$obj) {
     }
     $data[] = $obj->$id_name;
     if ($obj->is_new) {
-      db_query("INSERT INTO {$table} (". implode(', ', $column_names) .", $id_name) VALUES (". implode(', ', $column_placeholders) .', %d)', $data);
+      db_query("INSERT INTO {". $table ."} (". implode(', ', $column_names) .", $id_name) VALUES (". implode(', ', $column_placeholders) .', %d)', $data);
     }
     else {
-      db_query("UPDATE {$table} SET ". implode(', ', $column_assignments) ." WHERE $id_name = %d", $data);
+      db_query("UPDATE {". $table ."} SET ". implode(', ', $column_assignments) ." WHERE $id_name = %d", $data);
     }
   }
   if ($obj->is_new) {
@@ -565,7 +566,7 @@ function object_driver_delete($obj) {
     $table = isset($obj_def['table']) ? $obj_def['table'] : $class;
     $id_name = $class .'_id';
     
-    db_query("DELETE FROM {%s} WHERE %s = %d", $table, $id_name, $obj->$id_name);
+    db_query("DELETE FROM {". $table ."} WHERE %s = %d", $id_name, $obj->$id_name);
     if (isset($obj->type)) {
       if (function_exists($obj->type .'_'. $class .'_delete')) {
         call_user_func($obj->type .'_'. $class .'_delete', $obj);
