[interchange-cvs] interchange - jon modified lib/Vend/Table/DBI.pm
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Wed Apr 17 17:43:32 2002
User: jon
Date: 2002-04-17 21:38:30 GMT
Modified: lib/Vend/Table DBI.pm
Log:
DBI patch by Mark Johnson to respect foreign key constraints or NOT NULL
restrictions during INSERT. Instead of doing this:
INSERT INTO table (code) VALUES ('00001');
UPDATE table SET col1=val1, col2=val2;
Do this:
INSERT INTO table (code, col1, col2) VALUES ('00001', val1, val2);
Tested with PostgreSQL, MySQL, and (I believe by Mark) Oracle.
Would be good for stable branch, if it doesn't cause any trouble.
Revision Changes Path
2.16 +9 -11 interchange/lib/Vend/Table/DBI.pm
rev 2.16, prev_rev 2.15
Index: DBI.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.15
retrieving revision 2.16
diff -u -u -r2.15 -r2.16
--- DBI.pm 5 Mar 2002 00:45:00 -0000 2.15
+++ DBI.pm 17 Apr 2002 21:38:30 -0000 2.16
@@ -1,6 +1,6 @@
# Vend::Table::DBI - Access a table stored in an DBI/DBD database
#
-# $Id: DBI.pm,v 2.15 2002/03/05 00:45:00 jon Exp $
+# $Id: DBI.pm,v 2.16 2002/04/17 21:38:30 jon Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -20,7 +20,7 @@
# MA 02111-1307 USA.
package Vend::Table::DBI;
-$VERSION = substr(q$Revision: 2.15 $, 10);
+$VERSION = substr(q$Revision: 2.16 $, 10);
use strict;
@@ -989,14 +989,6 @@
my $tkey;
my $sql;
- unless($s->record_exists($key)) {
-#::logDebug("record $key doesn't exist");
- $key = $s->set_row($key);
-#::logDebug("key now '$key'");
- }
-
- $tkey = $s->quote($key, $s->[$KEY]) if defined $key;
-#::logDebug("tkey now $tkey");
if(ref $fary ne 'ARRAY') {
my $href = $fary;
@@ -1007,7 +999,11 @@
$fary = [ keys %$href ];
}
- if(defined $tkey) {
+ $tkey = $s->quote($key, $s->[$KEY]) if defined $key;
+#::logDebug("tkey now $tkey");
+
+
+ if ( defined $tkey and $s->record_exists($key) ) {
my $fstring = join ",", map { "$_=?" } @$fary;
$sql = "update $s->[$TABLE] SET $fstring WHERE $s->[$KEY] = $tkey";
}
@@ -1019,6 +1015,8 @@
splice @$vary, $i;
last;
}
+ unshift @$fary, $s->[$KEY];
+ unshift @$vary, $key;
my $fstring = join ",", @$fary;
my $vstring = join ",", map {"?"} @$vary;
$sql = "insert into $s->[$TABLE] ($fstring) VALUES ($vstring)";