[PATCH mogilefs 4/7] Using NULL during an INSERT for the AUTO_INCREMENT column does not work outside of MySQL.

Robin H. Johnson robbat2 at gentoo.org
Tue Jun 5 13:38:12 UTC 2007


From: Robin H. Johnson <robbat2 at gentoo.org>

Signed-off-by: Robin H. Johnson <robbat2 at gentoo.org>
---
 server/lib/MogileFS/Store.pm |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/server/lib/MogileFS/Store.pm b/server/lib/MogileFS/Store.pm
index 5b1eaea..0906cb3 100644
--- a/server/lib/MogileFS/Store.pm
+++ b/server/lib/MogileFS/Store.pm
@@ -761,9 +761,16 @@ sub register_tempfile {
     # one.  that should be fine.
     my $ins_tempfile = sub {
         my $rv = eval {
-            $dbh->do("INSERT INTO tempfile (fid, dmid, dkey, classid, devids, createtime) VALUES ".
-                     "(?,?,?,?,?," . $self->unix_timestamp . ")",
-                     undef, $fid || undef, $arg{dmid}, $arg{key}, $arg{classid} || 0, $arg{devids});
+            # We must only pass the correct number of bind parameters
+            # Using 'NULL' for the AUTO_INCREMENT/SERIAL column
+            # Fails on Postgres
+            my $sql = "INSERT INTO tempfile (".
+            ($explicit_fid_used ? "fid, " : "") ." dmid, dkey, classid, devids, createtime) ".
+            "VALUES (".
+            ($explicit_fid_used ? "?, " : "") . "?, ?, ?, ?, ".$self->unix_timestamp.")";
+            my @bind_values = ($arg{dmid}, $arg{key}, $arg{classid} || 0, $arg{devids});
+            unshift @bind_values, $fid if $explicit_fid_used;
+            $dbh->do($sql, undef, @bind_values);
         };
         if (!$rv) {
             return undef if $self->was_duplicate_error;
-- 
1.5.2



More information about the mogilefs mailing list