[interchange-cvs] interchange - heins modified 5 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Wed Aug 7 04:04:02 2002


User:      heins
Date:      2002-08-07 08:03:04 GMT
Modified:  lib/Vend Data.pm Interpolate.pm Scan.pm
Modified:  lib/Vend/Table Common.pm InMemory.pm
Log:
* Add new "instant database", which allows you to build a database for
  editing or any other use by specifying a file name.

  The file name must be relative, even if NoAbsolute is not set, and
  it must end in .txt or .asc. (Add .csv?)

  Imported every time, of course, but only written when something
  has been changed (by flagging a _Dirty bit).

    [flag type=3Dwrite table=3DContent_txt]
    [data include/menus/Content.txt page 001]

    [data table=3Dinclude/menus/Content.txt col=3Dpage key=3D001 value=3D"Y=
ES!"]
    [data include/menus/Content.txt page 001]

    [perl tables=3D"Content_txt"]
        my $db =3D $Db{Content_txt};

        my $ary =3D $db->query('select code,page,name from Content_txt');

        my $count =3D 0;
        for(@$ary) {
            push @out, uneval($_) . "\n";
            $count++;
        }

        return join "\n", "Showed $count records in Content_txt.", @out;
    [/perl]

   All normal database operations seem to work.

* Fix a bug in escape_form that didn't unescape %NN parms.

Revision  Changes    Path
2.14      +53 -3     interchange/lib/Vend/Data.pm


rev 2.14, prev_rev 2.13
Index: Data.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/Data.pm,v
retrieving revision 2.13
retrieving revision 2.14
diff -u -r2.13 -r2.14
--- Data.pm	2 Aug 2002 11:44:55 -0000	2.13
+++ Data.pm	7 Aug 2002 08:02:59 -0000	2.14
@@ -1,6 +1,6 @@
 # Vend::Data - Interchange databases
 #
-# $Id: Data.pm,v 2.13 2002/08/02 11:44:55 racke Exp $
+# $Id: Data.pm,v 2.14 2002/08/07 08:02:59 mheins Exp $
 #=20
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -90,12 +90,50 @@
=20
 my ($Products, $Item_price);
=20
+sub instant_database {
+	my($file) =3D @_;
+	return undef unless $file =3D~ /\.(txt|asc)$/;
+	my $dir   =3D File::Basename::dirname($file);
+	my $fname =3D File::Basename::basename($file);
+	my $dbname =3D $fname;
+	$dbname =3D~ s:\W:_:g;
+=09
+	$Vend::Database{$dbname}
+		and return $Vend::Database{$dbname}->ref();
+	if( file_name_is_absolute($_[0]) ) {
+		my $msg =3D errmsg(
+						"Instant database (%s): no absolute file names.",
+						$_[0],
+					);
+		logError($msg);
+		logGloba($msg);
+		return undef;
+	}
+	elsif (! -f $_[0]) {
+		my $msg =3D errmsg(
+						"Instant database (%s): no file found.",
+						$_[0],
+					);
+		logError($msg);
+		return undef;
+	}
+	return $Vend::Database{$dbname} =3D import_database({
+													name =3D> $dbname,
+													DIR =3D> $dir,
+													type =3D> 'AUTO',
+													file =3D> $fname,
+													Class =3D> 'TRANSIENT',
+													EXPORT_ON_CLOSE =3D> 1,
+												});
+}
+
 sub database_exists_ref {
 	return $_[0]->ref() if ref $_[0];
 	return $Vend::Interpolate::Db{$_[0]}
 			if $Vend::Interpolate::Db{$_[0]};
-	return undef unless defined $Vend::Database{$_[0]};
-	return $Vend::Database{$_[0]}->ref() || undef;
+	$Vend::Database{$_[0]}
+		and return $Vend::Database{$_[0]}->ref();
+	return instant_database(@_);
 }
=20
 sub database_key_exists {
@@ -517,6 +555,9 @@
 	CSV =3D> ["CSV","\n"],
 	PIPE =3D> ['|', "\n"],
 	TAB =3D> ["\t", "\n"],
+	"\t" =3D> ["\t", "\n"],
+	'|'  =3D> ['|', "\n"],
+	"\n%%\n" =3D> ["\n%%\n", "\n%%%\n"],
=20
 	);
=20
@@ -619,6 +660,14 @@
 					Class                Vend::Table::Shadow
 				/
 				},
+		'TRANSIENT' =3D> {
+				qw/
+					Cacheable			 0
+					Tagged_write		 1
+					Class                Vend::Table::InMemory
+					Export_on_close		 1
+				/
+				},
 		'MEMORY' =3D> {
 				qw/
 					Cacheable			 1
@@ -1161,6 +1210,7 @@
 	}
=20
 	my ($delim, $record_delim) =3D find_delimiter($type || $db->config('type'=
));
+	$delim or ($delim, $record_delim) =3D find_delimiter($db->config('delimit=
er'));
=20
 	$file =3D $file || $db->config('file');
 	my $dir =3D $db->config('DIR');



2.102     +10 -7     interchange/lib/Vend/Interpolate.pm


rev 2.102, prev_rev 2.101
Index: Interpolate.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/Interpolate.pm,v
retrieving revision 2.101
retrieving revision 2.102
diff -u -r2.101 -r2.102
--- Interpolate.pm	6 Aug 2002 22:08:04 -0000	2.101
+++ Interpolate.pm	7 Aug 2002 08:02:59 -0000	2.102
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 #=20
-# $Id: Interpolate.pm,v 2.101 2002/08/06 22:08:04 mheins Exp $
+# $Id: Interpolate.pm,v 2.102 2002/08/07 08:02:59 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.101 $, 10);
+$VERSION =3D substr(q$Revision: 2.102 $, 10);
=20
 @EXPORT =3D qw (
=20
@@ -711,8 +711,10 @@
=20
 	local($Safe_data);
 	$Safe_data =3D 1 if $opt->{safe_data};
+=09
+	my $db;
=20
-	if ( not defined $Vend::Database{$selector}) {
+	if ( not $db =3D database_exists_ref($selector) ) {
 		if($selector eq 'session') {
 			$CacheInvalid =3D 1;
 			if(defined $opt->{value}) {
@@ -751,7 +753,6 @@
 	}
 	elsif (defined $opt->{value}) {
 #::logDebug("alter table: table=3D$selector alter=3D$opt->{alter} field=3D=
$field value=3D$opt->{value}");
-		my $db =3D $Vend::Database{$selector};
 		$CacheInvalid =3D 1;
 		if ($opt->{alter}) {
 			$opt->{alter} =3D~ s/\W+//g;
@@ -804,7 +805,6 @@
 				);
 	}
 	elsif ($opt->{hash}) {
-		my $db =3D ::database_exists_ref($selector);
 		return undef unless $db->record_exists($key);
 		return $db->row_hash($key);
 	}
@@ -1638,7 +1638,7 @@
 		$opt->{joiner} =3D '<BR>' if ! $opt->{joiner};
 	}
=20
-	my $db =3D $Db{$table} || Vend::Data::database_exists_ref($table);
+	my $db =3D $Db{$table} || database_exists_ref($table);
 	$db->record_exists($sku)
 		or return;
 	my $record =3D $db->row_hash($sku)
@@ -2053,7 +2053,7 @@
 		my (@tab) =3D grep /\S/, split /\s+/, $tables;
 		foreach my $tab (@tab) {
 			next if $Db{$tab};
-			my $db =3D Vend::Data::database_exists_ref($tab);
+			my $db =3D database_exists_ref($tab);
 			next unless $db;
 			$db =3D $db->ref();
 			if($hole) {
@@ -2963,6 +2963,9 @@
 		$val =3D~ s/^\s+//mg;
 		$val =3D~ s/\s+$//mg;
 		@args =3D split /\n+/, $val;
+		for(@args) {
+			s/^(.*?=3D)(.+)/$1 . Vend::Util::unhexify($2)/ge;
+		}
 	}
=20
 	for(@args) {



2.15      +3 -3      interchange/lib/Vend/Scan.pm


rev 2.15, prev_rev 2.14
Index: Scan.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/Scan.pm,v
retrieving revision 2.14
retrieving revision 2.15
diff -u -r2.14 -r2.15
--- Scan.pm	15 Jul 2002 14:08:14 -0000	2.14
+++ Scan.pm	7 Aug 2002 08:02:59 -0000	2.15
@@ -1,6 +1,6 @@
 # Vend::Scan - Prepare searches for Interchange
 #
-# $Id: Scan.pm,v 2.14 2002/07/15 14:08:14 mheins Exp $
+# $Id: Scan.pm,v 2.15 2002/08/07 08:02:59 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -29,7 +29,7 @@
 			perform_search
 			);
=20
-$VERSION =3D substr(q$Revision: 2.14 $, 10);
+$VERSION =3D substr(q$Revision: 2.15 $, 10);
=20
 use strict;
 use Vend::Util;
@@ -625,7 +625,7 @@
 		if($db) {
 			$codename =3D $db->config('KEY') || 'code';
 			$nuhash =3D $db->config('NUMERIC') || undef;
-			push_spec( 'fi', $Vend::Cfg->{Database}{$t}{file}, $ary, $hash);
+			push_spec( 'fi', $db->config('file'), $ary, $hash);
 		}
 # GLIMPSE
 		elsif ("\L$t" eq 'glimpse') {



2.19      +16 -3     interchange/lib/Vend/Table/Common.pm


rev 2.19, prev_rev 2.18
Index: Common.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/Common.pm,v
retrieving revision 2.18
retrieving revision 2.19
diff -u -r2.18 -r2.19
--- Common.pm	18 Jul 2002 19:27:57 -0000	2.18
+++ Common.pm	7 Aug 2002 08:03:02 -0000	2.19
@@ -1,6 +1,6 @@
 # Vend::Table::Common - Common access methods for Interchange databases
 #
-# $Id: Common.pm,v 2.18 2002/07/18 19:27:57 mheins Exp $
+# $Id: Common.pm,v 2.19 2002/08/07 08:03:02 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -22,7 +22,7 @@
 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 # MA  02111-1307  USA.
=20
-$VERSION =3D substr(q$Revision: 2.18 $, 10);
+$VERSION =3D substr(q$Revision: 2.19 $, 10);
 use strict;
=20
 package Vend::Table::Common;
@@ -717,7 +717,19 @@
 	for (@tabs) {
 		s/\..*//;
 	}
-	if (! defined $s || $tabs[0] ne $s->[$CONFIG]{name}) {
+
+	my $reroute;
+	my $tname =3D $s->[$CONFIG]{name};
+	if ($tabs[0] ne $tname) {
+		if("$tabs[0]_txt" eq $tname or "$tabs[0]_asc" eq $tname) {
+			$tabs[0] =3D $spec->{fi}[0] =3D $tname;
+		}
+		else {
+			$reroute =3D 1;
+		}
+	}
+
+	if($reroute) {
 		unless ($s =3D $Vend::Database{$tabs[0]}) {
 			::logError("Table %s not found in databases", $tabs[0]);
 			return $opt->{failure} || undef;
@@ -1302,6 +1314,7 @@
 		}
 	}
 	delete $out->[$CONFIG]{Clean_start};
+	delete $out->[$CONFIG]{_Dirty};
 	unlockfile(\*IN) or die "unlock\n";
     close(IN);
 	if($numeric_guess) {



2.8       +8 -3      interchange/lib/Vend/Table/InMemory.pm


rev 2.8, prev_rev 2.7
Index: InMemory.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/InMemory.pm,v
retrieving revision 2.7
retrieving revision 2.8
diff -u -r2.7 -r2.8
--- InMemory.pm	27 Jun 2002 22:24:10 -0000	2.7
+++ InMemory.pm	7 Aug 2002 08:03:02 -0000	2.8
@@ -1,6 +1,6 @@
 # Vend::Table::InMemory - Store an Interchange table in memory
 #
-# $Id: InMemory.pm,v 2.7 2002/06/27 22:24:10 jon Exp $
+# $Id: InMemory.pm,v 2.8 2002/08/07 08:03:02 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -25,7 +25,7 @@
 package Vend::Table::InMemory;
 use Vend::Table::Common qw(!config !columns);
 @ISA =3D qw/Vend::Table::Common/;
-$VERSION =3D substr(q$Revision: 2.7 $, 10);
+$VERSION =3D substr(q$Revision: 2.8 $, 10);
 use strict;
=20
 # 0: column names
@@ -96,7 +96,10 @@
 }
=20
 sub close_table {
-	1;
+	my $s =3D shift;
+	return 1 unless $s->[$CONFIG]{_Dirty};
+	Vend::Data::export_database($s->[$CONFIG]{name});
+	delete $s->[$CONFIG]{_Dirty};
 }
=20
 sub row {
@@ -132,6 +135,7 @@
 		my $a =3D $s->[$TIE_HASH]{$key};
 		$a =3D $s->[$TIE_HASH]{$key} =3D [] unless defined $a;
 		$a->[$index] =3D $value;
+		$s->[$CONFIG]{_Dirty} =3D 1;
 		return undef;
 	};
 }
@@ -139,6 +143,7 @@
 sub set_row {
 	my ($s, @fields) =3D @_;
 	my $key =3D $fields[$s->[$KEY_INDEX]];
+	$s->[$CONFIG]{_Dirty} =3D 1;
 	$s->[$TIE_HASH]{$key} =3D [@fields];
 }
=20