[interchange-cvs] interchange - heins modified 2 files

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Thu Oct 18 01:31:00 2001


User:      heins
Date:      2001-10-18 05:30:04 GMT
Modified:  lib/Vend/Table Tag: STABLE_4_8-branch Common.pm DBI.pm
Log:
	* Bring get_slice() routine and set_slice() improvement into stable.
	* Add NO_ASCII_INDEX check
	* Minor warning removal.
	* This is all tested fairly well.

Revision  Changes    Path
No                   revision



No                   revision



2.0.2.2   +12 -3     interchange/lib/Vend/Table/Common.pm


rev 2.0.2.2, prev_rev 2.0.2.1
Index: Common.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/Common.pm,v
retrieving revision 2.0.2.1
retrieving revision 2.0.2.2
diff -u -r2.0.2.1 -r2.0.2.2
--- Common.pm	2001/10/06 06:22:58	2.0.2.1
+++ Common.pm	2001/10/18 05:30:04	2.0.2.2
@@ -1,6 +1,6 @@
 # Vend::Table::Common - Common access methods for Interchange databases
 #
-# $Id: Common.pm,v 2.0.2.1 2001/10/06 06:22:58 mheins Exp $
+# $Id: Common.pm,v 2.0.2.2 2001/10/18 05:30:04 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.0.2.1 $, 10);
+$VERSION = substr(q$Revision: 2.0.2.2 $, 10);
 use strict;
 
 package Vend::Table::Common;
@@ -322,6 +322,15 @@
 		return undef;
 	}
 
+	if(ref $fary ne 'ARRAY') {
+		my $href = $fary;
+		if(ref $href ne 'HASH') {
+			$href = { $fary, $vary, @_ }
+		}
+		$vary = [ values %$href ];
+		$fary = [ keys   %$href ];
+	}
+
 	my $keyname = $s->[$CONFIG]{KEY};
 
 	my ($found_key) = grep $_ eq $keyname, @$fary;
@@ -978,7 +987,7 @@
 	my @i;  # Array of field names for sort
 	my @o;  # Array of sort options
 	my %comma;
-	if($options->{INDEX}) {
+	if($options->{INDEX} and ! $options->{NO_ASCII_INDEX}) {
 		my @f; my $f;
 		my @n;
 		my $i;



2.0.2.1   +51 -3     interchange/lib/Vend/Table/DBI.pm


rev 2.0.2.1, prev_rev 2.0
Index: DBI.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.0
retrieving revision 2.0.2.1
diff -u -r2.0 -r2.0.2.1
--- DBI.pm	2001/07/18 02:23:20	2.0
+++ DBI.pm	2001/10/18 05:30:04	2.0.2.1
@@ -1,6 +1,6 @@
 # Vend::Table::DBI - Access a table stored in an DBI/DBD database
 #
-# $Id: DBI.pm,v 2.0 2001/07/18 02:23:20 jon Exp $
+# $Id: DBI.pm,v 2.0.2.1 2001/10/18 05:30:04 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.0 $, 10);
+$VERSION = substr(q$Revision: 2.0.2.1 $, 10);
 
 use strict;
 
@@ -888,6 +888,45 @@
 	return $new;
 }
 
+sub get_slice {
+    my ($s, $key, $fary) = @_;
+	$s = $s->import_db() if ! defined $s->[$DBI];
+
+	my $tkey;
+	my $sql;
+	return undef unless $s->record_exists($key);
+
+	$tkey = $s->quote($key, $s->[$KEY]);
+#::logDebug("tkey now $tkey");
+
+	# Better than failing on a bad ref...
+	if(ref $fary ne 'ARRAY') {
+		shift; shift;
+		$fary = [ @_ ];
+	}
+
+	my $fstring = join ",", @$fary;
+	$sql = "SELECT $fstring from $s->[$TABLE] WHERE $s->[$KEY] = $tkey";
+
+#::logDebug("get_slice query: $sql");
+#::logDebug("get_slice key/fields:\nkey=$key\n" . ::uneval($fary));
+	my $sth;
+	my $ary;
+	eval {
+		$sth = $s->[$DBI]->prepare($sql)
+			or die ::errmsg("prepare %s: %s", $sql, $DBI::errstr);
+		$sth->execute();
+	};
+
+	if($@) {
+		my $msg = $@;
+		::logError("failed %s::%s routine: %s", __PACKAGE__, 'get_slice', $msg);
+		return undef;
+	}
+
+	return wantarray ? $sth->fetchrow_array() : $sth->fetchrow_arrayref();
+}
+
 sub set_slice {
     my ($s, $key, $fary, $vary) = @_;
 	$s = $s->import_db() if ! defined $s->[$DBI];
@@ -912,6 +951,15 @@
 	$tkey = $s->quote($key, $s->[$KEY]) if defined $key;
 #::logDebug("tkey now $tkey");
 
+	if(ref $fary ne 'ARRAY') {
+		my $href = $fary;
+		if(ref $href ne 'HASH') {
+			$href = { $fary, $vary, @_ }
+		}
+		$vary = [ values %$href ];
+		$fary = [ keys   %$href ];
+	}
+
 	if(defined $tkey) {
 		my $fstring = join ",", map { "$_=?" } @$fary;
 		$sql = "update $s->[$TABLE] SET $fstring WHERE $s->[$KEY] = $tkey";
@@ -1646,7 +1694,7 @@
 	}
 } # MVSEARCH
 #::logDebug("finished query, rc=$rc ref=$ref arrayref=$opt->{arrayref} Tmp=$Vend::Interpolate::Tmp->{$opt->{arrayref}}");
-	if(ref $ref) {
+	if(CORE::ref($ref)) {
 		# make sure rc is set if we got a ref from MVSEARCH
 		$rc = scalar @{$ref};
 	}