[interchange-cvs] interchange - jon modified lib/Vend/Table/DBI.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Thu Oct 13 01:47:02 EDT 2005


User:      jon
Date:      2005-10-13 05:47:01 GMT
Modified:  lib/Vend/Table DBI.pm
Log:
Add support for DBI's table_info catalog, schema, name, and type options.

This allows specifying a particular schema so that e.g. PostgreSQL won't
see unwanted tables from other schemas, and the DatabaseAutoIgnore
directive can be avoided, as it may exclude tables that are wanted in
other schemas.

This also allows views to be included when specifically request with the
type option.

Also moved DBIx::DBSchema check till after other checks.

Should have no effect on directives using the older syntax.

Revision  Changes    Path
2.67      +16 -16    interchange/lib/Vend/Table/DBI.pm


rev 2.67, prev_rev 2.66
Index: DBI.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/DBI.pm,v
retrieving revision 2.66
retrieving revision 2.67
diff -u -u -r2.66 -r2.67
--- DBI.pm	30 Sep 2005 20:56:58 -0000	2.66
+++ DBI.pm	13 Oct 2005 05:47:01 -0000	2.67
@@ -1,6 +1,6 @@
 # Vend::Table::DBI - Access a table stored in an DBI/DBD database
 #
-# $Id: DBI.pm,v 2.66 2005/09/30 20:56:58 jon Exp $
+# $Id: DBI.pm,v 2.67 2005/10/13 05:47:01 jon Exp $
 #
 # Copyright (C) 2002-2004 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -21,7 +21,7 @@
 # MA  02111-1307  USA.
 
 package Vend::Table::DBI;
-$VERSION = substr(q$Revision: 2.66 $, 10);
+$VERSION = substr(q$Revision: 2.67 $, 10);
 
 use strict;
 no warnings qw(uninitialized numeric);
@@ -2129,23 +2129,17 @@
 
 sub auto_config {
 	my $string = shift;
-	my ($dsn, $user, $pass) = Text::ParseWords::shellwords($string);
+	my ($dsn, $user, $pass, $catalog, $schema, $name, $type) = Text::ParseWords::shellwords($string);
 	my $handle = DBI->connect($dsn, $user, $pass)
 		or ::logDebug(::errmsg("DatabaseAuto DSN '%s' does not connect.", $dsn));
-	my $schema;
 	my @tabs;
 	my @out;
-	eval {
-		require DBIx::DBSchema;
-		$schema = new_native DBIx::DBSchema $handle;
-	};
-
 	my $sth;
 	eval {
-		$sth = $handle->table_info()
+		$sth = $handle->table_info($catalog, $schema, $name, $type)
 			or die "Table info not enabled for this driver.\n";
 		while(my $ref = $sth->fetchrow_arrayref) {
-			next unless $ref->[3] eq 'TABLE';
+			next unless $ref->[3] eq 'TABLE' or $type;
 			push @tabs, $ref->[2];
 		}
 	};
@@ -2157,8 +2151,8 @@
 	elsif(exists $Vend::Config::C->{DatabaseAutoIgnore}) {
 		 $re = $Vend::Config::C->{DatabaseAutoIgnore};
 	}
-	$re and $re = qr/$re/;
 #::logDebug("ignore re=$re");
+	$re and $re = qr/$re/;
 
 	my %found;
 	return undef unless @tabs;
@@ -2170,15 +2164,21 @@
 		push @out, [$t, "PASS $pass"] if $pass;
 	}
 
-	if($schema) {
-		for my $create ($schema->sql($handle)) {
-			$create =~ /^CREATE\s+TABLE\s+(\w+)\s+/
+	my $dbschema;
+	eval {
+		require DBIx::DBSchema;
+		$dbschema = DBIx::DBSchema->new_native($handle);
+	};
+	if ($dbschema) {
+		for my $sql ($dbschema->sql($handle)) {
+			$sql =~ /^CREATE\s+TABLE\s+(\w+)\s+/
 				or next;
 			my $t = $1;
 			next unless $found{$t};
-			push @out, [ $t, "CREATE_SQL $create"];
+			push @out, [ $t, "CREATE_SQL $sql" ];
 		}
 	}
+
 	return @out;
 }
 








More information about the interchange-cvs mailing list