From 15bb5bfd9f80f1e23b1a34b28730b4736ebc4f35 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Sep 2000 11:51:37 +0000 Subject: [PATCH] get rid of superfluous _from_dsn methods --- DBSchema.pm | 70 +++++++++++++++-------------------------------- DBSchema/Table.pm | 3 +- 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/DBSchema.pm b/DBSchema.pm index e052bd6..327a0cc 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -22,9 +22,10 @@ DBIx::DBSchema - Database-independent schema objects use DBIx::DBSchema; $schema = new DBIx::DBSchema @dbix_dbschema_table_objects; - $schema = new_from_dsn DBIx::DBSchema $dsn, $user, $pass; $schema = new_odbc DBIx::DBSchema $dbh; + $schema = new_odbc DBIx::DBSchema $dsn, $user, $pass; $schema = new_native DBIx::DBSchema $dbh; + $schema = new_native DBIx::DBSchema $dsn, $user, $pass; $schema->save("filename"); $schema = load DBIx::DBSchema "filename"; @@ -69,68 +70,41 @@ sub new { } -=item new_odbc_from_dsn DATA_SOURCE USERNAME PASSWORD +=item new_odbc DATABASE_HANDLE || DATA_SOURCE USERNAME PASSWORD [ ATTR ] -Connects to the specified DBI data source and creates a DBIx::DBSchema object -from it using new_odbc. - -=cut - -sub new_odbc_from_dsn { - my($proto, $dsn, $user, $pass ) = @_; - my $dbh = DBI->connect( $dsn, $user, $pass ) or die $DBI::errstr; - my $self = $proto->new_odbc($dbh); - $dbh->disconnect; #silly DBI - $self; -} - -=item new_odbc DATABASE_HANDLE - -Creates a new DBIx::DBSchema object from the supplied DBI database handle. -This uses the experimental DBI type_info method to create a schema with -standard (ODBC) SQL column types that most closely correspond to any -non-portable column types. Use this to import a schema that you wish to use -with many different database engines. Although primary key and (unique) index -information will only be read from databases with DBIx::DBSchema::DBD drivers -(currently MySQL and PostgreSQL), import of column names and attributes -*should* work for any database. +Creates a new DBIx::DBSchema object from an existing data source, which can be +specified by passing an open DBI database handle, or by passing the DBI data +source name, username, and password. This uses the experimental DBI type_info +method to create a schema with standard (ODBC) SQL column types that most +closely correspond to any non-portable column types. Use this to import a +schema that you wish to use with many different database engines. Although +primary key and (unique) index information will only be read from databases +with DBIx::DBSchema::DBD drivers (currently MySQL and PostgreSQL), import of +column names and attributes *should* work for any database. =cut sub new_odbc { - my($proto, $dbh) = @_; + my($proto, $dbh) = (shift, shift); + $dbh = DBI->connect( $dbh, @_ ) or die $DBI::errstr unless ref($dbh); $proto->new( map { new_odbc DBIx::DBSchema::Table $dbh, $_ } _tables_from_dbh($dbh) ); } -=item new_native_from_dsn DATA_SOURCE USERNAME PASSWORD - -Connects to the specified DBI data source and creates a DBIx::DBSchema object -from it using new_native. - -=cut - -sub new_native_from_dsn { - my($proto, $dsn, $user, $pass) = @_; - my $dbh = DBI->connect( $dsn, $user, $pass ) or die $DBI::errstr; - my $self = $proto->new_native($dbh); - $dbh->disconnect; #silly DBI - $self; -} - -=item new_native DATABASE_HANDLE +=item new_native DATABASE_HANDLE || DATA_SOURCE USERNAME PASSWORD [ ATTR ] -Creates a new DBIx::DBSchema object from the supplied DBI database handle. This -uses database-native methods to read the schema, and will preserve any -non-portable column types. The method is only available if there is a -DBIx::DBSchema::DBD for the corresponding database engine (currently, MySQL and -PostgreSQL). +Creates a new DBIx::DBSchema object from an existing data source, which can be +specified by passing an open DBI database handle, or by passing the DBI data +source name, username and password. This uses database-native methods to read +the schema, and will preserve any non-portable column types. The method is +only available if there is a DBIx::DBSchema::DBD for the corresponding database engine (currently, MySQL and PostgreSQL). =cut sub new_native { - my($proto, $dbh) = @_; + my($proto, $dbh) = (shift, shift); + $dbh = DBI->connect( $dbh, @_ ) or die $DBI::errstr unless ref($dbh); $proto->new( map { new_native DBIx::DBSchema::Table ( $dbh, $_ ) } _tables_from_dbh($dbh) ); diff --git a/DBSchema/Table.pm b/DBSchema/Table.pm index b4f66b6..56852a4 100644 --- a/DBSchema/Table.pm +++ b/DBSchema/Table.pm @@ -131,7 +131,8 @@ sub new_odbc { ), map { my $type_info = scalar($dbh->type_info($sth->{TYPE}->[$sthpos])) - or die "null return from DBI::type_info"; + or die "DBI::type_info ". $dbh->{Driver}->{Name}. " driver ". + "returned no results for type ". $sth->{TYPE}->[$sthpos]; new DBIx::DBSchema::Column $_, $type_info->{'TYPE_NAME'}, -- 2.20.1