[interchange-cvs] interchange - heins modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Wed Jul 30 01:00:00 EDT 2003


User:      heins
Date:      2003-07-30 04:00:45 GMT
Modified:  lib/Vend Scan.pm SQL_Parser.pm
Log:
* Improve SQL_Parser to recognize individual "distinct" fields
  and the header value of "column as 'Title'".

* Reserve mv_header_fields in search spec, not handled in search
  specs yet.

Revision  Changes    Path
2.25      +6 -5      interchange/lib/Vend/Scan.pm


rev 2.25, prev_rev 2.24
Index: Scan.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Scan.pm,v
retrieving revision 2.24
retrieving revision 2.25
diff -u -r2.24 -r2.25
--- Scan.pm	12 Jul 2003 04:47:10 -0000	2.24
+++ Scan.pm	30 Jul 2003 04:00:45 -0000	2.25
@@ -1,6 +1,6 @@
 # Vend::Scan - Prepare searches for Interchange
 #
-# $Id: Scan.pm,v 2.24 2003/07/12 04:47:10 mheins Exp $
+# $Id: Scan.pm,v 2.25 2003/07/30 04:00:45 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -30,7 +30,7 @@
 			perform_search
 			);
 
-$VERSION = substr(q$Revision: 2.24 $, 10);
+$VERSION = substr(q$Revision: 2.25 $, 10);
 
 use strict;
 use Vend::Util;
@@ -114,6 +114,7 @@
 
 ## Place marker, not used in search specs but is reserved
 ##  rt  mv_real_table
+##  hf  mv_header_fields
 ##
 my %Scan = ( qw(
 	ac  mv_all_chars
@@ -650,8 +651,6 @@
 #::logDebug("t=$t obj=$_ db=$db nuhash=" . ::uneval($nuhash));
 	}
 
-	$text =~ /\bselect\s+distinct\s+/i and push_spec( 'un', 'yes', $ary, $hash);
-
 	if(my $l = $stmt->limit()) {
 #::logDebug("found limit=" . $l->limit());
 		push_spec('ml', $l->limit(), $ary, $hash);
@@ -661,10 +660,13 @@
 		}
 	}
 
+	my $distincted;
 	for($stmt->columns()) {
 		my $name = $_->name();
 #::logDebug("found column=$name");
+		push_spec('un', 1, $ary, $hash) if $_->distinct() and ! $distincted++;
 		push_spec('rf', $name, $ary, $hash);
+		push_spec('hf', $_->as(), $ary, $hash);
 		last if $name eq '*';
 #::logDebug("column name=" . $_->name() . " table=" . $_->table());
 	}
@@ -690,7 +692,6 @@
 		push_spec('to', $d, $ary, $hash);
 	}
 
-	push_spec('un', 1, $ary, $hash) if $stmt->distinct();
 #::logDebug("ary spec to this point=" . ::uneval($ary));
 #::logDebug("hash spec to this point=" . ::uneval($hash));
 	my @where;



2.5       +24 -10    interchange/lib/Vend/SQL_Parser.pm


rev 2.5, prev_rev 2.4
Index: SQL_Parser.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/SQL_Parser.pm,v
retrieving revision 2.4
retrieving revision 2.5
diff -u -r2.4 -r2.5
--- SQL_Parser.pm	7 Jul 2003 00:00:30 -0000	2.4
+++ SQL_Parser.pm	30 Jul 2003 04:00:45 -0000	2.5
@@ -1,6 +1,6 @@
 # Vend::SQL_Parser - Interchange SQL parser class
 #
-# $Id: SQL_Parser.pm,v 2.4 2003/07/07 00:00:30 mheins Exp $
+# $Id: SQL_Parser.pm,v 2.5 2003/07/30 04:00:45 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1997-2002 Red Hat, Inc.
@@ -38,7 +38,7 @@
 use Vend::Util;
 use Text::ParseWords;
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.4 $, 10);
+$VERSION = substr(q$Revision: 2.5 $, 10);
 
 sub new {
 	my $class = shift;
@@ -174,8 +174,6 @@
 			push @try, $_;
 			last if $last;
 		}
-		$s->{raw_columns} =~ s/^\s*distinct\s+//i
-			and $s->{distinct} = 1;
 	}
 	elsif ($s->{command} eq 'UPDATE') {
 		$st =~ s/(\w+(?:\s*,\s*\w+)*)\s+set\s+//is;
@@ -203,12 +201,6 @@
 	return @tab;
 }
 
-sub distinct {
-	my $s = shift;
-	$s->tables() unless $s->{tables};
-	return $s->{distinct};
-}
-
 sub limit {
 	my $s = shift;
 	return $s->{limit} if $s->{limit};
@@ -795,6 +787,15 @@
 	return shift->{name};
 }
 
+sub distinct {
+	my $s = shift;
+	return $s->{distinct};
+}
+
+sub as {
+	return shift->{as};
+}
+
 sub new {
 	my $class = shift;
 	my $self = { @_ };
@@ -813,6 +814,19 @@
 		elsif ($space =~ /^c/i) {
 			$name = $CGI::values{$sel};
 		}
+	}
+	elsif($raw =~ /\s/) {
+		$self->{distinct} = 1 if s/^distinct\s+//i;
+		my $title;
+		$title = $1 if $raw =~ s/\s+as\s+(.*)//;
+		if($title) {
+			my $match;
+			$title =~ s/^(["']?)(.*)\1$/$2/
+				and $match = $1
+				and $title =~ s/$match$match/$match/g;
+			$self->{as} = $title;
+		}
+		$name = $raw;
 	}
 	else {
 		$name = $raw;







More information about the interchange-cvs mailing list