[interchange-cvs] interchange - heins modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Sat Feb 2 13:53:00 2002
User: heins
Date: 2002-02-02 18:52:54 GMT
Modified: lib/Vend/Table Common.pm DBI.pm
Log:
* Do something interesting with:
[query row-count=1 list=1 sql=" ..... "]
[sql-code] = [sql-param count]
[/query]
Previously it always returned a scalar and you could not really
display outside of embedded Perl.
* Fix "UPDATE table SET field1 = 'val1' WHERE foo = 'bar' in DBM.
Revision Changes Path
2.10 +24 -15 interchange/lib/Vend/Table/Common.pm
rev 2.10, prev_rev 2.9
Index: Common.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/Common.pm,v
retrieving revision 2.9
retrieving revision 2.10
diff -u -r2.9 -r2.10
--- Common.pm 8 Jan 2002 04:45:37 -0000 2.9
+++ Common.pm 2 Feb 2002 18:52:54 -0000 2.10
@@ -1,6 +1,6 @@
# Vend::Table::Common - Common access methods for Interchange databases
#
-# $Id: Common.pm,v 2.9 2002/01/08 04:45:37 mheins Exp $
+# $Id: Common.pm,v 2.10 2002/02/02 18:52:54 mheins Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -22,7 +22,7 @@
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
-$VERSION = substr(q$Revision: 2.9 $, 10);
+$VERSION = substr(q$Revision: 2.10 $, 10);
use strict;
package Vend::Table::Common;
@@ -354,11 +354,13 @@
unshift @$fary, $keyname;
unshift @$vary, $key;
}
+ my @current = $s->row($key);
- my $sub = $s->row_settor(@$fary)
- or die "failed to create row slice routine.";
+ @current[ map { $s->column_index($_) } @$fary ] = @$vary;
- return $sub->(@$vary);
+ $s->set_row(@current)
+ or die "failed to create row slice routine.";
+ return $key;
}
sub field_settor {
@@ -724,10 +726,12 @@
}
elsif($update eq 'UPDATE') {
@update_fields = @{$spec->{rf}};
- @na = $codename;
+#::logDebug("update fields: " . uneval(\@update_fields));
+ my $key = $s->config('KEY');
+ @na = ($codename);
$sub = sub {
my $key = shift;
- set_slice($s, $key, \@update_fields, \@_);
+ $s->set_slice($key, [@update_fields], \@_);
};
}
elsif($update eq 'DELETE') {
@@ -775,15 +779,14 @@
die "Bad row settor for columns @na"
if ! $sub;
if($update eq 'INSERT') {
- &$sub(@vals);
+ $sub->(@vals);
$ref = [[ $vals[0] ]];
}
else {
-#::logDebug("Supposed to search..., spec=" . ::uneval($spec));
$ref = $search->array($spec);
-#::logDebug("Returning ref=" . ::uneval($ref) . "updating with vals=" . join ",", @vals);
- for(@{$ref}) {
- &$sub($_->[0], @vals);
+ for(@$ref) {
+#::logDebug("returned =" . uneval($_) . ", update values: " . uneval(\@vals));
+ $sub->($_->[0], @vals);
}
}
}
@@ -806,9 +809,15 @@
$return = $opt->{failure} || undef;
}
- return scalar @{$ref || []}
- if $opt->{row_count};
- return Vend::Interpolate::region($opt, $text)
+ if ($opt->{row_count}) {
+ my $rc = $ref ? scalar @$ref : 0;
+ return $rc unless $opt->{list};
+ $ref = [ [ $rc ] ];
+ @na = [ 'row_count' ];
+ %nh = ( 'rc' => 0, 'count' => 0, 'row_count' => 0 );
+ }
+
+ return Vend::Interpolate::tag_sql_list($text, $ref, \%nh, $opt, \@na)
if $opt->{list};
return Vend::Interpolate::html_table($opt, $ref, \@na)
if $opt->{html};
2.11 +12 -7 interchange/lib/Vend/Table/DBI.pm
rev 2.11, prev_rev 2.10
Index: DBI.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.10
retrieving revision 2.11
diff -u -r2.10 -r2.11
--- DBI.pm 26 Jan 2002 16:48:01 -0000 2.10
+++ DBI.pm 2 Feb 2002 18:52:54 -0000 2.11
@@ -1,6 +1,6 @@
# Vend::Table::DBI - Access a table stored in an DBI/DBD database
#
-# $Id: DBI.pm,v 2.10 2002/01/26 16:48:01 mheins Exp $
+# $Id: DBI.pm,v 2.11 2002/02/02 18:52:54 mheins 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.10 $, 10);
+$VERSION = substr(q$Revision: 2.11 $, 10);
use strict;
@@ -1762,12 +1762,17 @@
}
} # MVSEARCH
#::logDebug("finished query, rc=$rc ref=$ref arrayref=$opt->{arrayref} Tmp=$Vend::Interpolate::Tmp->{$opt->{arrayref}}");
- if(CORE::ref($ref)) {
- # make sure rc is set if we got a ref from MVSEARCH
- $rc = scalar @{$ref};
+
+ if ($opt->{row_count}) {
+ if($rc < 1 and CORE::ref($ref) and scalar(@$ref) ) {
+ $rc = scalar(@$ref);
+ }
+ return $rc unless $opt->{list};
+ $ref = [ [ $rc ] ];
+ @na = [ 'row_count' ];
+ %nh = ( 'rc' => 0, 'count' => 0, 'row_count' => 0 );
}
- return $rc
- if $opt->{row_count};
+
return Vend::Interpolate::tag_sql_list($text, $ref, \%nh, $opt, \@na)
if $opt->{list};
return Vend::Interpolate::html_table($opt, $ref, \@na)