Lucas Nussbaum wrote:
> On 24/11/05 at 10:52 +0100, Stefan Hornburg wrote:
>> package: interchange-ui
>> severity: grave
>> tags: confirmed
>>
>> Creating a new item in the interchange UI with the sku of an existing
>> record overwrites this record.
>>
>> Bye
>>      Racke
> 
> Hi Stefan,
> 
> This bug has been opened for nearly 2 years, without any change. What
> about removing the package from Debian if it's unusable?
> 
> Note that because of this bug, your package never migrated to testing.

OK, the attached patch is experimental code in order to fix this problem.
It has the following flaws right now:

* works only with DBI databases 
* pragma needs to be set
* confusing error message from DBI in the UI

Any comments and suggestions for improvements ?

Regards
          Racke



-- 
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team

Index: lib/Vend/Data.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Data.pm,v
retrieving revision 2.63
diff -u -r2.63 Data.pm
--- lib/Vend/Data.pm	30 Mar 2007 11:39:44 -0000	2.63
+++ lib/Vend/Data.pm	9 Oct 2007 12:57:17 -0000
@@ -1907,10 +1907,17 @@
 
 	my %data;
 	my %sneakdata;
+	my %set_opts;
+	
 	for(@fields) {
 		$data{$_} = [];
 	}
 
+	if ($function eq 'insert' && $::Pragma->{no_update_on_insert}) {
+		# prevent overwriting of existing entries
+		$set_opts{insert_only} = 1;
+	}
+	
 	my $count;
 	my $multi = $CGI::values{$prikey} =~ tr/\0/\0/;
 	my $max = 0;
@@ -2280,7 +2287,7 @@
 			for(keys %$qd) {
 #::logDebug("update_data: Getting ready to set_slice");
 				my $k = $multikey ? undef : $key;
-				$qret = $qd->{$_}->set_slice($k, $qf->{$_}, $qv->{$_});
+				$qret = $qd->{$_}->set_slice($k, $qf->{$_}, $qv->{$_}, \%set_opts);
 				$rows_set[$i] = $qret unless $rows_set[$i];
 			}
 			if($blob) {
Index: lib/Vend/Table/DBI.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.81
diff -u -r2.81 DBI.pm
--- lib/Vend/Table/DBI.pm	8 Oct 2007 15:37:49 -0000	2.81
+++ lib/Vend/Table/DBI.pm	9 Oct 2007 12:57:18 -0000
@@ -1198,7 +1198,7 @@
 }
 
 sub set_slice {
-    my ($s, $key, $fin, $vin) = @_;
+    my ($s, $key, $fin, $vin, $opt) = @_;
 	my ($fary, $vary);
 	
 	$s = $s->import_db() if ! defined $s->[$DBI];
@@ -1222,6 +1222,11 @@
 	else {
 		my $href = $fin;
 		if(ref $href ne 'HASH') {
+			if (@_ % 2 && ref($_[$#_] eq 'HASH')) {
+				$opt = pop(@_);
+			} else {
+				$opt = {};
+			}
 			$href = { splice (@_, 2) };
 		}
 		$vary = [ values %$href ];
@@ -1257,7 +1262,7 @@
 #::logDebug("tkey now $tkey");
 
 
-	if ( defined $tkey and $s->record_exists($key) ) {
+	if ( defined $tkey and ! $opt->{insert_only} and $s->record_exists($key) ) {
 		unless (@$fary) {
 			# as there are no data columns, we can safely skip the update
 			return $key;

Reply via email to