[interchange-cvs] interchange - jon modified lib/Vend/Table/DBI.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Mon Jul 15 16:19:00 2002


User:      jon
Date:      2002-07-15 20:18:47 GMT
Modified:  lib/Vend/Table DBI.pm
Log:
Fix set_slice bug that removed all values from array after code, if
code was passed in array (separately from code parameter in sub call).

A bug still remains: Since the initial call to set_row with nothing but a
key was removed to make databases with foreign key constraints happy,
auto_number doesn't work, since that was being done in set_row. I haven't
thought of an elegant solution yet and don't want to just cut and paste
the auto_number code ...

Revision  Changes    Path
2.23      +7 -12     interchange/lib/Vend/Table/DBI.pm


rev 2.23, prev_rev 2.22
Index: DBI.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.22
retrieving revision 2.23
diff -u -u -r2.22 -r2.23
--- DBI.pm	9 Jul 2002 17:42:12 -0000	2.22
+++ DBI.pm	15 Jul 2002 20:18:46 -0000	2.23
@@ -1,6 +1,6 @@
 # Vend::Table::DBI - Access a table stored in an DBI/DBD database
 #
-# $Id: DBI.pm,v 2.22 2002/07/09 17:42:12 mheins Exp $
+# $Id: DBI.pm,v 2.23 2002/07/15 20:18:46 jon Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -20,7 +20,7 @@
 # MA  02111-1307  USA.
=20
 package Vend::Table::DBI;
-$VERSION =3D substr(q$Revision: 2.22 $, 10);
+$VERSION =3D substr(q$Revision: 2.23 $, 10);
=20
 use strict;
=20
@@ -1019,23 +1019,18 @@
 	$tkey =3D $s->quote($key, $s->[$KEY]) if defined $key;
 #::logDebug("tkey now $tkey");
=20
-
 	if ( defined $tkey and $s->record_exists($key) ) {
 		my $fstring =3D join ",", map { "$_=3D?" } @$fary;
 		$sql =3D "update $s->[$TABLE] SET $fstring WHERE $s->[$KEY] =3D $tkey";
 	}
 	else {
-		my $found;
-		for(my $i =3D 0; $i < @$fary; $i++) {
-			next unless $fary->[$i] eq $s->[$KEY];
-			splice @$fary, $i;
-			splice @$vary, $i;
-			last;
+		my ($found_key) =3D grep $_ eq $s->[$KEY], @$fary;
+		unless ($found_key) {
+			unshift @$fary, $s->[$KEY];
+			unshift @$vary, $key;
 		}
-		unshift @$fary, $s->[$KEY];
-		unshift @$vary, $key;
 		my $fstring =3D join ",", @$fary;
-		my $vstring	=3D join ",", map {"?"} @$vary;
+		my $vstring =3D join ",", map {"?"} @$vary;
 		$sql =3D "insert into $s->[$TABLE] ($fstring) VALUES ($vstring)";
 	}
=20