Index: panels_mini/panels_mini.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_mini/Attic/panels_mini.module,v
retrieving revision 1.1.2.26
diff -u -r1.1.2.26 panels_mini.module
--- panels_mini/panels_mini.module	27 May 2008 20:21:14 -0000	1.1.2.26
+++ panels_mini/panels_mini.module	28 May 2008 12:48:39 -0000
@@ -944,6 +944,19 @@
 // Database functions.
 
 /**
+ * A list of the fields used in the panel_mini table.
+ */
+function panels_mini_fields() {
+  return array(
+    "name" => "'%s'",
+    "title" => "'%s'",
+    "contexts" => "'%s'",
+    "requiredcontexts" => "'%s'",
+    "relationships" => "'%s'",
+  );
+}
+
+/**
  * Sanitize a mini panel, to guarantee certain data is as we believe it will be.
  */
 function panels_mini_sanitize($mini) {
@@ -1041,59 +1054,55 @@
  * Save a mini panel.
  */
 function panels_mini_save(&$panel_mini) {
-  $display = panels_save_display($panel_mini->display);
+  // Save the display if one was given to us.
+  if (!empty($panel_mini->display)) {
+    $display = panels_save_display($panel_mini->display);
+  }
+
+  // Ensure empty values get translated correctly.
+  // Also make sure we don't mess up the original.
+  $mini = drupal_clone(panels_mini_sanitize($panel_mini));
+  
+  // Now we can proceed to saving the mini panel itself.
+  $fields = $types = $values = $pairs = array();
+
+  // If pid is set to our "magic value", this is an insert, otherwise an update.
+  $insert = $mini->pid && $mini->pid == 'new';
+
+  // Build arrays of fields and types (resp. pairs of both) and of values.
+  foreach (panels_mini_fields() as $field => $type) {
+    // Skip empty values.
+    if (isset($mini->$field)) {
+      if ($insert) {
+        $fields[] = $field;
+        $types[] = $type;
+      }
+      else {
+        $pairs[] = "$field = $type";
+      }
 
-  if ($panel_mini->pid && $panel_mini->pid != 'new') {
-    db_query(
-      "UPDATE {panels_mini} SET " .
-      "did = %d, " .
-      "name = '%s', " .
-      "title = '%s', " .
-      "relationships = '%s', " .
-      "contexts = '%s', " .
-      "requiredcontexts = '%s' " .
-      "WHERE pid = %d",
-        $panel_mini->did,
-        $panel_mini->name,
-        $panel_mini->title,
-        serialize($panel_mini->relationships),
-        serialize($panel_mini->contexts),
-        serialize($panel_mini->requiredcontexts),
-      $panel_mini->pid
-    );
+      // Build the $values array, serializing some fields.
+      $serialize = in_array($field, array('contexts', 'requiredcontexts', 'relationships'));
+      $values[] = $serialize ? serialize($mini->$field) : $mini->$field;
+    }
+  }
+  
+  if ($insert) {
+    // Determine the new primary key.
+    $mini->pid = db_next_id('{panels_mini}_pid');  
+    // Build the query adding the new primary key and the did.
+    $sql = 'INSERT INTO {panels_mini} (' . implode(', ', $fields) . ', pid, did) VALUES (' . implode(', ', $types) . ', %d, %d)';
+    $values[] = $mini->pid;
+    $values[] = $display->did;
   }
   else {
-    $panel_mini->pid = db_next_id("{panels_mini}_pid");
-    db_query(
-      "INSERT INTO {panels_mini} ( " .
-        "pid, " .
-        "name, " .
-        "did, " .
-        "title, " .
-        "relationships, " .
-        "contexts, " .
-        "requiredcontexts " .
-      ") " .
-      "VALUES (" .
-        "%d, " .
-        "'%s', " .
-        "%d, " .
-        "'%s', " .
-        "'%s', " .
-        "'%s', " .
-        "'%s'" .
-      ")",
-        $panel_mini->pid,
-        $panel_mini->name,
-        $display->did,
-        $panel_mini->title,
-        serialize($panel_mini->relationships),
-        serialize($panel_mini->contexts),
-        serialize($panel_mini->requiredcontexts)
-    );
+    // Build the query filtering by the primary key.
+    $sql = 'UPDATE {panels_mini} SET ' . implode(', ', $pairs) . ' WHERE pid = %d';
+    $values[] = $mini->pid;
   }
+  db_query($sql, $values); 
 
-  return $panel_mini->pid;
+  return $mini->pid;
 }
 
 /**
@@ -1112,7 +1121,7 @@
  */
 function panels_mini_export($panel_mini, $prefix = '') {
   $output = '';
-  $fields = array('name', 'title', 'requiredcontexts', 'contexts', 'relationships');
+  $fields = panels_mini_fields();
   $output .= $prefix . '$mini = new stdClass()' . ";\n";
   $output .= $prefix . '$mini->pid = \'new\'' . ";\n";
   foreach ($fields as $field) {
Index: panels_page/panels_page.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.module,v
retrieving revision 1.1.2.48
diff -u -r1.1.2.48 panels_page.module
--- panels_page/panels_page.module	27 May 2008 20:21:13 -0000	1.1.2.48
+++ panels_page/panels_page.module	28 May 2008 12:48:40 -0000
@@ -1042,8 +1042,8 @@
   if (!empty($panel_page->display)) {
     $display = panels_save_display($panel_page->display);
   }
-  // Ensure empty values get translated correctly. Also make sure we don't
-  // mess up the original.
+  // Ensure empty values get translated correctly.
+  // Also make sure we don't mess up the original.
   $page = drupal_clone(panels_page_sanitize($panel_page));
 
   // Check to see if we need to save any imported displays.
@@ -1054,53 +1054,48 @@
       unset($page->displays[$did]['display']);
     }
   }
-  // serialize the access string.
-  $page->access = $page->access ? implode(', ', $page->access) : '';
 
-  $page->arguments = serialize($page->arguments);
-  $page->displays = serialize($page->displays);
-  $page->contexts = serialize($page->contexts);
-  $page->relationships = serialize($page->relationships);
-  $page->switcher_options = serialize($page->switcher_options);
+  // Now we can proceed to saving the panel page itself.
+  $fields = $types = $values = $pairs = array();
 
-  // Create strings for our query from the list of fields.
-  $fields = panels_page_fields();
-  foreach ($fields as $field => $value) {
-    if (isset($page->$field)) {
-      $f[] = $field;
-      $q[] = $value;
-      $v[] = $page->$field;
-    }
-  }
+  // If pid is set to our "magic value", this is an insert, otherwise an update.
+  $insert = $page->pid && $page->pid == 'new';
 
-  if ($page->pid && $page->pid != 'new') {
-    if (empty($page->name)) {
-      $page->name = 'panel_page_' . $page->pid;
-    }
-    $query = '';
-    foreach ($f as $id => $field) {
-      if ($query) {
-        $query .= ', ';
+  // Serialize the access string.
+  $page->access = $page->access ? implode(', ', $page->access) : '';
+
+  // Build arrays of fields and types (resp. pairs of both) and of values.
+  foreach (panels_page_fields() as $field => $type) {
+    // Skip empty values.
+    if (isset($page->$field)) {
+      if ($insert) {
+        $fields[] = $field;
+        $types[] = $type;
+      }
+      else {
+        $pairs[] = "$field = $type";
       }
-      $query .= "$f[$id] = " . $q[$id];
-    }
 
-    $v[] = $page->pid;
-    db_query("UPDATE {panels_page} SET $query WHERE pid = %d", $v);
+      // Build the $values array, serializing some fields.
+      $serialize = in_array($field, array('arguments', 'displays', 'contexts', 'relationships', 'switcher_options'));
+      $values[] = $serialize ? serialize($page->$field) : $page->$field;
+    }
+  }
+  
+  if ($insert) {
+    // Determine the new primary key.
+    $page->pid = db_next_id('{panels_page}_pid');  
+    // Build the query adding the new primary key and the did.
+    $sql = 'INSERT INTO {panels_page} (' . implode(', ', $fields) . ', pid, did) VALUES (' . implode(', ', $types) . ', %d, %d)';
+    $values[] = $page->pid;
+    $values[] = $display->did;
   }
   else {
-    $page->pid = db_next_id("{panels_page}_pid");
-    // Tack our pid and did onto the query. These aren't listed as 'fields' because
-    // they can't be updated; once set they are permanent.
-    $v[] = $page->pid;
-    $v[] = $display->did;
-
-    if (empty($page->name)) {
-      $page->name = 'panel_page_' . $page->pid;
-    }
-    // Yes, this is kind of long but it's a lot easier to match up values.
-    db_query("INSERT INTO {panels_page} ( " . implode(', ', $f) . ", pid, did) VALUES (" . implode(', ', $q) . ", %d, %d)", $v);
+    // Build the query filtering by the primary key.
+    $sql = 'UPDATE {panels_page} SET ' . implode(', ', $pairs) . ' WHERE pid = %d';
+    $values[] = $page->pid;
   }
+  db_query($sql, $values);
 
   menu_rebuild();
   return $page->pid;
Index: panels_views/panels_views.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_views/Attic/panels_views.module,v
retrieving revision 1.1.2.19
diff -u -r1.1.2.19 panels_views.module
--- panels_views/panels_views.module	27 May 2008 20:21:15 -0000	1.1.2.19
+++ panels_views/panels_views.module	28 May 2008 12:48:40 -0000
@@ -1245,57 +1245,44 @@
 /**
  * Write a view pane to the database.
  */
-function panels_views_save($pv) {
-  $keys = $values = "";
-  $args = array();
-
-  // If we were truly generic, this whole 'pvid' thing would be pulled
-  // from field data. But we're not because it's unnecessary extra
-  // work.
-  $insert = empty($pv->pvid);
+function panels_views_save($panel_view) {
+  $fields = $types = $values = $pairs = array();
 
-  $names = panels_views_pane_fields();
-  // Build SQL for the keys.
-  foreach ($names as $name => $data) {
-    // skip the primary key here.
-    if (!empty($data['primary'])) {
-      if (!$insert) {
-        continue;
+  // If pvid is empty, this is an insert, otherwise an update.
+  $insert = empty($panel_view->pvid);
+
+  // Build arrays of fields and types (resp. pairs of both) and of values.
+  foreach (panels_views_pane_fields() as $field => $data) {
+    $primary = !empty($data['primary']);
+    // Skip primary key and empty values.
+    if (!$primary && isset($panel_view->$field)) {
+      if ($insert) {
+        $fields[] = $field;
+        $types[] = $data['arg'];
       }
       else {
-        $pv->pvid = db_next_id('{panels_views}_pvid');
-      }
-    }
-
-    if ($keys) {
-      $keys .= ', ';
-    }
-    if ($insert) {
-      // $values only used when inserting.
-      if ($values) {
-        $values .= ', ';
+        $pairs[] = "$field = $data[arg]";
       }
-      $keys .= $name;
-      $values .= $data['arg'];
-    }
-    else {
-      $keys .= "$name = $data[arg]";
-    }
-    if (!empty($data['serialize'])) {
-      $args[] = serialize($pv->$name);
-    }
-    else {
-      $args[] = $pv->$name;
+  
+      // Build the $values array, serializing some fields.
+      $serialize = !empty($data['serialize']);
+      $values[] = $serialize ? serialize($panel_view->$field) : $panel_view->$field;
     }
   }
+
   if ($insert) {
-    $sql = "INSERT INTO {panels_views} ($keys) VALUES ($values)";
+    // Determine the new primary key.
+    $panel_view->pvid = db_next_id('{panels_views}_pvid');
+    // Build the query adding the new primary key.
+    $sql = 'INSERT INTO {panels_views} (' . implode(', ', $fields) . ', pvid) VALUES (' . implode(', ', $types) . ', %d)';
+    $values[] = $panel_view->pvid;
   }
   else {
-    $sql = "UPDATE {panels_views} SET $keys WHERE pvid = %d";
-    $args[] = $pv->pvid;
+    // Build the query filtering by the primary key.
+    $sql = "UPDATE {panels_views} SET' . implode(', ', $pairs) . 'WHERE pvid = %d";
+    $values[] = $panel_view->pvid;
   }
-  db_query($sql, $args);
+  db_query($sql, $values);
 }
 
 /**
