[interchange-cvs] interchange - kwalsh modified 2 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Tue Aug 14 09:42:09 EDT 2007


User:      kwalsh
Date:      2007-08-14 13:42:08 GMT
Modified:  lib/Vend/Table DBI.pm
Modified:  .        WHATSNEW-5.5
Log:
    * Allow table comments to be defined on PostgreSQL and Oracle too.
      (The earlier implementation only recognised MySQL.)

Revision  Changes    Path
2.80      +26 -7     interchange/lib/Vend/Table/DBI.pm


rev 2.80, prev_rev 2.79
Index: DBI.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.79
retrieving revision 2.80
diff -u -r2.79 -r2.80
--- DBI.pm	9 Aug 2007 17:43:28 -0000	2.79
+++ DBI.pm	14 Aug 2007 13:42:08 -0000	2.80
@@ -1,6 +1,6 @@
 # Vend::Table::DBI - Access a table stored in an DBI/DBD database
 #
-# $Id: DBI.pm,v 2.79 2007/08/09 17:43:28 kwalsh Exp $
+# $Id: DBI.pm,v 2.80 2007/08/14 13:42:08 kwalsh Exp $
 #
 # Copyright (C) 2002-2007 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -21,7 +21,7 @@
 # MA  02110-1301  USA.
 
 package Vend::Table::DBI;
-$VERSION = substr(q$Revision: 2.79 $, 10);
+$VERSION = substr(q$Revision: 2.80 $, 10);
 
 use strict;
 no warnings qw(uninitialized numeric);
@@ -186,7 +186,12 @@
 	HAS_TABLE_TYPE	 => { 
 		mysql => 1,
 	},
-	HAS_TABLE_COMMENT => { 
+	TABLE_COMMENT_SQL => { 
+		mysql  => 'COMMENT=_COMMENT_',
+		Pg     => 'COMMENT ON _TABLE_ IS _COMMENT_',
+		Oracle => 'COMMENT ON _TABLE_ IS _COMMENT_',
+	},
+	TABLE_COMMENT_DURING_CREATE => { 
 		mysql => 1,
 	},
 	SEQUENCE_QUERY	 => { 
@@ -298,14 +303,28 @@
 	my $query = "create table $tablename ( \n";
 	$query .= join ",\n", @cols;
 	$query .= "\n)\n";
-	if($config->{HAS_TABLE_TYPE} and $config->{TABLE_TYPE} ) {
+
+	if ($config->{TABLE_TYPE} && $config->{HAS_TABLE_TYPE} ) {
 		$query =~ s/\s*$/ TYPE=$config->{TABLE_TYPE}\n/;
 	}
-	if($config->{HAS_TABLE_COMMENT} and $config->{TABLE_COMMENT} ) {
+
+	if ($config->{TABLE_COMMENT} && $config->{TABLE_COMMENT_SQL}) {
 		my $comment = $config->{TABLE_COMMENT};
-		$comment =~ s/^['"]+// && $comment =~ s/['"]+$//;
+		$comment =~ s/^\s*(["'])\s*(.*?)\s*\1\s*$/$2/;
 		$comment =~ s/'/''/g;
-		$query =~ s/\s*$/ COMMENT='$comment'\n/;
+
+		my $template = $config->{TABLE_COMMENT_SQL};
+		$template =~ s/\b_COMMENT_\b/'$comment'/;
+
+		if ($config->{TABLE_COMMENT_DURING_CREATE}) {
+			$query =~ s/\s*$/ $template\n/;
+		}
+		else {
+			$template =~ s/\b_TABLE_\b/$tablename/;
+
+			$config->{POSTCREATE} ||= [];
+			push(@{$config->{POSTCREATE}},$template);
+		}
 	}
 	return $query;
 }



1.57      +1 -1      interchange/WHATSNEW-5.5


rev 1.57, prev_rev 1.56
Index: WHATSNEW-5.5
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.5,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- WHATSNEW-5.5	13 Aug 2007 11:30:46 -0000	1.56
+++ WHATSNEW-5.5	14 Aug 2007 13:42:08 -0000	1.57
@@ -91,7 +91,7 @@
   Require directive tests.
 
 * Added a new TABLE_COMMENT modifier to the Database directive to allow
-  a short comment to be attached to MySQL tables.
+  a short comment to be attached to MySQL and PostgreSQL tables.
 
 * Delay "Server started" message as long as possible.
 








More information about the interchange-cvs mailing list