[interchange-cvs] interchange - heins modified 2 files

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Fri Nov 2 08:27:00 2001


User:      heins
Date:      2001-11-02 13:26:57 GMT
Modified:  lib/Vend/Table Tag: STABLE_4_8-branch Common.pm DBI.pm
Log:
	* Add hash_query and get_slice methods to both Common and DBI.

	* Add Stefan's query/@arg method to Common.pm.

Revision  Changes    Path
No                   revision



No                   revision



2.0.2.3   +26 -3     interchange/lib/Vend/Table/Common.pm


rev 2.0.2.3, prev_rev 2.0.2.2
Index: Common.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/Common.pm,v
retrieving revision 2.0.2.2
retrieving revision 2.0.2.3
diff -u -r2.0.2.2 -r2.0.2.3
--- Common.pm	2001/10/18 05:30:04	2.0.2.2
+++ Common.pm	2001/11/02 13:26:57	2.0.2.3
@@ -1,6 +1,6 @@
 # Vend::Table::Common - Common access methods for Interchange databases
 #
-# $Id: Common.pm,v 2.0.2.2 2001/10/18 05:30:04 mheins Exp $
+# $Id: Common.pm,v 2.0.2.3 2001/11/02 13:26:57 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.2 $, 10);
+$VERSION = substr(q$Revision: 2.0.2.3 $, 10);
 use strict;
 
 package Vend::Table::Common;
@@ -309,6 +309,21 @@
     };
 }
 
+sub get_slice {
+    my ($s, $key, $fary) = @_;
+	$s = $s->import_db() if ! defined $s->[$TIE_HASH];
+
+	return undef unless $s->record_exists($key);
+
+	if(ref $fary ne 'ARRAY') {
+		shift; shift;
+		$fary = [ @_ ];
+	}
+
+	my @result = ($s->row($key))[ map { $s->column_index($_) } @$fary ];
+	return wantarray ? @result : \@result;
+}
+
 sub set_slice {
     my ($s, $key, $fary, $vary) = @_;
 	$s = $s->import_db() if ! defined $s->[$TIE_HASH];
@@ -600,11 +615,19 @@
 	return sprintf $query, @$fields;
 }
 
+sub hash_query {
+	my ($s, $query, $opt) = @_;
+	$opt ||= {};
+	$opt->{query} = $query;
+	$opt->{hashref} = 1;
+	return scalar $s->query($opt);
+}
+
 sub query {
     my($s, $opt, $text, @arg) = @_;
 
     if(! CORE::ref($opt)) {
-        unshift @arg, $text;
+        unshift @arg, $text if defined $text;
         $text = $opt;
         $opt = {};
     }



2.0.2.3   +12 -3     interchange/lib/Vend/Table/DBI.pm


rev 2.0.2.3, prev_rev 2.0.2.2
Index: DBI.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.0.2.2
retrieving revision 2.0.2.3
diff -u -r2.0.2.2 -r2.0.2.3
--- DBI.pm	2001/11/02 08:29:54	2.0.2.2
+++ DBI.pm	2001/11/02 13:26:57	2.0.2.3
@@ -1,6 +1,6 @@
 # Vend::Table::DBI - Access a table stored in an DBI/DBD database
 #
-# $Id: DBI.pm,v 2.0.2.2 2001/11/02 08:29:54 racke Exp $
+# $Id: DBI.pm,v 2.0.2.3 2001/11/02 13:26:57 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.2.2 $, 10);
+$VERSION = substr(q$Revision: 2.0.2.3 $, 10);
 
 use strict;
 
@@ -586,7 +586,8 @@
 sub columns {
 	my ($s) = shift;
 	$s = $s->import_db() if ! defined $s->[$DBI];
-    return @{$s->[$NAME]};
+	return unless ref $s->[$NAME] eq 'ARRAY';
+	return @{$s->[$NAME]};
 }
 
 sub test_column {
@@ -1498,6 +1499,14 @@
 		}
 	}
 	return sprintf $query, @$fields;
+}
+
+sub hash_query {
+	my ($s, $query, $opt) = @_;
+	$opt ||= {};
+	$opt->{query} = $query;
+	$opt->{hashref} = 1;
+	return scalar $s->query($opt);
 }
 
 sub query {