Fix ORMRow::insert() on PostgreSQL.
authorTim Landscheidt <tim@tim-landscheidt.de>
Fri, 28 Dec 2012 04:56:49 +0000 (04:56 +0000)
committeraude <aude.wiki@gmail.com>
Fri, 28 Dec 2012 22:00:06 +0000 (22:00 +0000)
When inserting a new row, ORMRow explicitly passed NULL as the value for
the id field which in MySQL means "use next value in sequence", but in
PostgreSQL means "use NULL".  With this change, for id fields no value
is passed if it isn't set to non-null.  This fixes bug #43475.

This effectively bars the possibility to set the id field of an existing
row to NULL, but the current code already disallows any changes in id
fields.

Change-Id: I29d86fa6fc38ff1852821658e4927b4d7d4a72b6

includes/db/ORMRow.php

index 5c730fb..5fd99af 100644 (file)
@@ -261,6 +261,11 @@ abstract class ORMRow implements IORMRow {
                        if ( array_key_exists( $name, $this->fields ) ) {
                                $value = $this->fields[$name];
 
+                               // Skip null id fields so that the DBMS can set the default.
+                               if ( $name === 'id' && is_null ( $value ) ) {
+                                       continue;
+                               }
+
                                switch ( $type ) {
                                        case 'array':
                                                $value = (array)$value;