--- /export/lib/perl5/site_perl/5.8.0/Class/DBI/Pg.pm.orig 2005-07-08 16:49:15.000000000 -0700 +++ /export/lib/perl5/site_perl/5.8.0/Class/DBI/Pg.pm 2005-07-08 17:34:01.000000000 -0700 @@ -58,14 +58,40 @@ This is almost the same as the following __PACKAGE__->columns(All => qw(id title artist release_date)); __PACKAGE__->sequence('cd_id_seq'); +=head2 SPECIFYING SCHEMA FROM WHICH TABLES ARE SELECTED + +If your database has the 'cd' table defined above, as well as another +table named 'cd' in a separate schema called 'mycollection', + + CREATE SCHEMA mycollection; + CREATE TABLE mycollection.cd ( + id SERIAL NOT NULL PRIMARY KEY, + title TEXT, + artist TEXT, + release_date DATE + ); + +you'll need to specify which 'cd' table is being set up. This is +achieved by passing a second argument to set_up_table(). For example: + + # the default schema is 'public' + __PACKAGE__->set_up_table('cd'); + + # ergo, this command is equivalent to the above + __PACKAGE__->set_up_table('cd','public'); + + # this command set's up the 'cd' table from 'myschema' + __PACKAGE__->set_up_table('cd','myschema'); + =cut sub _croak { require Carp; Carp::croak(@_); } sub set_up_table { - my ( $class, $table ) = @_; + my ( $class, $table, $schema ) = @_; my $dbh = $class->db_Main; my $catalog = ""; + $schema ||= 'public'; if ( $class->pg_version >= 7.3 ) { $catalog = 'pg_catalog.'; } @@ -74,8 +100,8 @@ sub set_up_table { my $sth = $dbh->prepare(<<"SQL"); SELECT indkey FROM ${catalog}pg_index WHERE indisprimary=true AND indrelid=( -SELECT oid FROM ${catalog}pg_class -WHERE relname = ?) +SELECT ${catalog}pg_class.oid FROM ${catalog}pg_class, ${catalog}pg_namespace +WHERE relnamespace = ${catalog}pg_namespace.oid AND nspname = '$schema' AND relname = ?) SQL $sth->execute($table); my %prinum = map { $_ => 1 } split ' ', $sth->fetchrow_array; @@ -84,8 +110,8 @@ SQL # find all columns $sth = $dbh->prepare(<<"SQL"); SELECT a.attname, a.attnum -FROM ${catalog}pg_class c, ${catalog}pg_attribute a -WHERE c.relname = ? +FROM ${catalog}pg_class c, ${catalog}pg_attribute a, ${catalog}pg_namespace n +WHERE c.relnamespace = n.oid AND nspname = '$schema' AND c.relname = ? AND a.attnum > 0 AND a.attrelid = c.oid ORDER BY a.attnum SQL @@ -98,7 +124,7 @@ SQL $sth = $dbh->prepare(<<"SQL"); SELECT adsrc FROM ${catalog}pg_attrdef WHERE -adrelid=(SELECT oid FROM ${catalog}pg_class WHERE relname=?) +adrelid=(SELECT ${catalog}pg_class.oid FROM ${catalog}pg_class, ${catalog}pg_namespace WHERE relnamespace = ${catalog}pg_namespace.oid AND nspname = '$schema' AND relname=?) SQL $sth->execute($table); my ($nextval_str) = $sth->fetchrow_array;