[Solar-svn] Revision 2721

pmjones at solarphp.com pmjones at solarphp.com
Thu Aug 16 16:41:52 CDT 2007


Branch: Solar_Sql_Model:

* [CHG] Method insertRecord() now removes empty autoincrement cols from the data to be inserted, to soothe Postgres requirements about explicit NULLs on SERIAL cols.

* [CHG] Method insertRecord() now uses new lastInsertId() signature ("$table, $col").


Modified: branches/orm/Solar/Sql/Model.php
===================================================================
--- branches/orm/Solar/Sql/Model.php	2007-08-16 21:39:42 UTC (rev 2720)
+++ branches/orm/Solar/Sql/Model.php	2007-08-16 21:41:52 UTC (rev 2721)
@@ -1369,16 +1369,22 @@
         // convert to array for the SQL command
         $data = $record->toArray();
         
-        // remove non-existent ("virtual") columns from the data, such as
-        // related fields.
+        // remove some data elements before inserting
         foreach ($data as $key => $val) {
+            // remove non-existent ("virtual") columns from the data, such as
+            // related fields.  
             if (empty($this->_table_cols[$key])) {
                 unset($data[$key]);
             }
+            
+            // remove empty autoinc columns to soothe postgres, which won't
+            // take explicit NULLs in SERIAL cols.
+            if ($this->_table_cols[$key]['autoinc'] && empty($val)) {
+                unset($data[$key]);
+            }
         }
         
-        // apply serializing to the data elements as needed, then attempt the
-        // insert.
+        // apply serializing to the data elements as needed
         $this->_serializeCols($data);
         
         // attempt to insert the record, and catch SQL exceptions.
@@ -1394,7 +1400,7 @@
                 if ($val['autoinc']) {
                     // set the value and leave the loop (only one autoinc
                     // should be here anyway)
-                    $data[$key] = $this->_sql->lastInsertId();
+                    $data[$key] = $this->_sql->lastInsertId($this->_table_name, $key);
                     break;
                 }
             }
@@ -1411,6 +1417,7 @@
         // note that we reload even if there was an SQL exception
         $record->load($data);
         
+        
         /**
          * Done!  If clean, the save actually worked, otherwise it failed.
          */




More information about the Solar-svn mailing list