Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding support for schemas in PostgreSQL. Though I think this should …

…work,

it is not tested yet.

svn path=/bioperl-db/trunk/; revision=610
  • Loading branch information...
commit 98d0d76287bff6ceb8e83a22086f076bea62a1c9 1 parent d6e85fb
@hlapp hlapp authored
View
30 Bio/DB/DBContextI.pm
@@ -245,4 +245,34 @@ sub dbi{
$self->throw_not_implemented();
}
+=head2 schema
+
+ Title : schema
+ Usage : $dbc->schema($newval)
+ Function: Get/set the schema in which the database tables reside.
+
+ A schema is typically equivalent to a namespace for a
+ collection of tables within a database. In Oracle, the
+ notion of a schema is synonymous with that of the user (all
+ database objects of a user belong to the schema of the same
+ name as the user) and hence can be omitted. In PostgreSQL,
+ since v7.4 schemas can delineate collections of tables
+ within a database (which in concept is more similar to a
+ user in Oracle).
+
+ For most drivers and database instances this will not be
+ needed.
+
+ Example :
+ Returns : value of schema (a scalar)
+ Args : on set, new value (a scalar or undef, optional)
+
+
+=cut
+
+sub schema{
+ my ($self,@args) = @_;
+ $self->throw_not_implemented();
+}
+
1;
View
34 Bio/DB/DBI/Pg.pm
@@ -226,4 +226,38 @@ sub build_dsn{
return $dsn;
}
+=head2 new_connection
+
+ Title : new_connection
+ Usage :
+ Function: Obtains a new connection handle to the database represented by the
+ the DBContextI object, passing additional args to the DBI->connect()
+ method.
+
+ We need to override this here in order to support setting a
+ schema for PostgreSQL.
+
+ Example :
+ Returns : an open DBI database handle
+ Args : A Bio::DB::DBContextI implementing object. Additional hashref
+ parameter to pass to DBI->connect().
+
+
+=cut
+
+sub new_connection{
+ my $self = shift;
+ my ($dbc) = @_; # we don't need the parameter hash here
+
+ my $dbh = $self->SUPER::new_connection(@_);
+ if ($dbc->schema) {
+ my $rv = $dbh->do("SET search_path TO ".$dbc->schema().", public");
+ if (!$rv) {
+ $self->warn("Failed to add schema '".$dbc->schema()
+ ."' to search path; is the server < v7.4?");
+ }
+ }
+ return $dbh;
+}
+
1;
View
25 Bio/DB/SimpleDBContext.pm
@@ -105,6 +105,9 @@ use Bio::DB::DBI;
-dsn the DSN string to use verbatim for connecting;
if supplied, other parameters will not change
or add to the value (see method dsn())
+ -schema the schema under which the database tables
+ reside, if the driver needs this (for example,
+ for PostgreSQL)
=cut
@@ -119,6 +122,7 @@ sub new {
$user,
$password,
$port,
+ $schema,
) = $self->_rearrange([qw(DSN
DBNAME
HOST
@@ -126,6 +130,7 @@ sub new {
USER
PASS
PORT
+ SCHEMA
)],@args);
$self->dsn($dsn) if $dsn;
@@ -135,6 +140,7 @@ sub new {
$self->driver($driver || "mysql") unless $self->driver();
$self->password($password) if defined($password);
$self->port($port) if defined($port);
+ $self->schema($schema) if defined($schema);
return $self;
}
@@ -364,4 +370,23 @@ sub dbi{
return $self->{'dbi'};
}
+=head2 schema
+
+ Title : schema
+ Usage : $dbc->schema($newval)
+ Function: Get/set the schema in which the database tables reside.
+ Example :
+ Returns : value of schema (a scalar)
+ Args : on set, new value (a scalar or undef, optional)
+
+
+=cut
+
+sub schema{
+ my $self = shift;
+
+ return $self->{'schema'} = shift if @_;
+ return $self->{'schema'};
+}
+
1;
View
10 scripts/biosql/load_ontology.pl
@@ -106,6 +106,13 @@ =head1 ARGUMENTS
(for PostgreSQL). Note that the DSN will be specific to the driver
being used.
+=item --schema schemaname
+
+The schema under which the BioSQL tables reside in the database. For
+Oracle and MySQL this is synonymous with the user, and won't have an
+effect. PostgreSQL since v7.4 supports schemas as the namespace for
+collections of tables within a database.
+
=item --initrc paramfile
Instead of, or in addition to, specifying every individual database
@@ -360,6 +367,7 @@ =head1 Authors
my $dbuser;
my $driver;
my $dbpass;
+my $schema;
my $format = 'goflat';
my $fmtargs = '';
my $namespace = "bioperl ontology";
@@ -408,6 +416,7 @@ =head1 Authors
'dbuser:s' => \$dbuser,
'dbpass:s' => \$dbpass,
'dsn=s' => \$dsn,
+ 'schema=s' => \$schema,
'format:s' => \$format,
'fmtargs=s' => \$fmtargs,
'initrc:s' => \$initrc,
@@ -505,6 +514,7 @@ =head1 Authors
-user => $dbuser,
-pass => $dbpass,
-dsn => $dsn,
+ -schema => $schema,
-initrc => $initrc,
);
$db->verbose($debug) if $debug > 0;
View
10 scripts/biosql/load_seqdatabase.pl
@@ -86,6 +86,13 @@ =head1 ARGUMENTS
(for PostgreSQL). Note that the DSN will be specific to the driver
being used.
+=item --schema schemaname
+
+The schema under which the BioSQL tables reside in the database. For
+Oracle and MySQL this is synonymous with the user, and won't have an
+effect. PostgreSQL since v7.4 supports schemas as the namespace for
+collections of tables within a database.
+
=item --initrc paramfile
Instead of, or in addition to, specifying every individual database
@@ -347,6 +354,7 @@ =head1 Authors
my $dbuser;
my $driver;
my $dbpass;
+my $schema;
my $format = 'genbank';
my $fmtargs = '';
my $namespace = 'bioperl';
@@ -395,6 +403,7 @@ =head1 Authors
'dbuser=s' => \$dbuser,
'dbpass=s' => \$dbpass,
'dsn=s' => \$dsn,
+ 'schema=s' => \$schema,
'format=s' => \$format,
'fmtargs=s' => \$fmtargs,
'initrc:s' => \$initrc,
@@ -507,6 +516,7 @@ =head1 Authors
-user => $dbuser,
-pass => $dbpass,
-dsn => $dsn,
+ -schema => $schema,
-initrc => $initrc,
);
$db->verbose($debug) if $debug > 0;
Please sign in to comment.
Something went wrong with that request. Please try again.