hopefully finally get rid of the
[DBIx-DBSchema.git] / DBSchema.pm
index 37a3252..420d44f 100644 (file)
@@ -3,7 +3,7 @@ package DBIx::DBSchema;
 use strict;
 use vars qw(@ISA $VERSION);
 #use Exporter;
-#use Carp qw(verbose);
+use Carp qw(confess);
 use DBI;
 use FreezeThaw qw(freeze thaw cmpStr);
 use DBIx::DBSchema::Table;
@@ -14,7 +14,7 @@ use DBIx::DBSchema::ColGroup::Index;
 #@ISA = qw(Exporter);
 @ISA = ();
 
-$VERSION = "0.13";
+$VERSION = "0.19";
 
 =head1 NAME
 
@@ -58,9 +58,10 @@ schema from an existing database.  You can save the schema to disk and restore
 it a different process.  Most importantly, DBIx::DBSchema can write SQL
 CREATE statements statements for different databases from a single source.
 
-Currently supported databases are MySQL and PostgreSQL.  DBIx::DBSchema will
-attempt to use generic SQL syntax for other databases.  Assistance adding
-support for other databases is welcomed.
+Currently supported databases are MySQL and PostgreSQL.  Sybase support is
+partially implemented.  DBIx::DBSchema will attempt to use generic SQL syntax
+for other databases.  Assistance adding support for other databases is
+welcomed.  See L<DBIx::DBSchema::DBD>, "Driver Writer's Guide and Base Class".
 
 =head1 METHODS
 
@@ -214,9 +215,14 @@ specified database, will attempt to use generic SQL syntax.
 
 sub sql {
   my($self, $dbh) = (shift, shift);
-  $dbh = DBI->connect( $dbh, @_ ) or die $DBI::errstr
-    unless ref($dbh) || ! @_;
-  map { $self->table($_)->sql_create_table($dbh); } $self->tables;
+  my $created_dbh = 0;
+  unless ( ref($dbh) || ! @_ ) {
+    $dbh = DBI->connect( $dbh, @_ ) or die $DBI::errstr;
+    $created_dbh = 1;
+  }
+  my @r = map { $self->table($_)->sql_create_table($dbh); } $self->tables;
+  $dbh->disconnect if $created_dbh;
+  @r;
 }
 
 =item pretty_print
@@ -301,7 +307,7 @@ sub _load_driver {
   } else {
     $dbh =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i #nicked from DBI->connect
                         or '' =~ /()/; # ensure $1 etc are empty if match fails
-    $driver = $1 or die "can't parse data source: $dbh";
+    $driver = $1 or confess "can't parse data source: $dbh";
   }
 
   #require "DBIx/DBSchema/DBD/$driver.pm";
@@ -324,6 +330,9 @@ sub _tables_from_dbh {
 
 Ivan Kohler <ivan-dbix-dbschema@420.am>
 
+Charles Shapiro <charles.shapiro@numethods.com> and Mitchell Friedman
+<mitchell.friedman@numethods.com> contributed the start of a Sybase driver.
+
 =head1 COPYRIGHT
 
 Copyright (c) 2000 Ivan Kohler
@@ -346,8 +355,9 @@ qw(:sql_types) here instead of externally.
 
 L<DBIx::DBSchema::Table>, L<DBIx::DBSchema::ColGroup>,
 L<DBIx::DBSchema::ColGroup::Unique>, L<DBIx::DBSchema::ColGroup::Index>,
-L<DBIx::DBSchema::Column>, L<DBIx::DBSchema::DBD>, L<DBIx::DBSchema::mysql>,
-L<DBIx::DBSchema::Pg>, L<FS::Record>, L<DBI>
+L<DBIx::DBSchema::Column>, L<DBIx::DBSchema::DBD>,
+L<DBIx::DBSchema::DBD::mysql>, L<DBIx::DBSchema::DBD::Pg>, L<FS::Record>,
+L<DBI>
 
 =cut