Pg reverse-engineering fix: now sets default DBIx_DBSchema_0_21
authorivan <ivan>
Thu, 19 Sep 2002 12:05:34 +0000 (12:05 +0000)
committerivan <ivan>
Thu, 19 Sep 2002 12:05:34 +0000 (12:05 +0000)
Changes
DBSchema.pm
DBSchema/DBD/Pg.pm
DBSchema/Table.pm

diff --git a/Changes b/Changes
index 0edd7d8..83dd3ef 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension DBIx::DBSchema.
 
+0.21 Thu Sep 19 05:04:18 PDT 2002
+       - Pg reverse-engineering fix: now sets default
+
 0.20 Mon Mar  4 04:58:34 2002
        - documentation updates
        - fix Column->new when using named params
index c914a94..ef975b6 100644 (file)
@@ -14,7 +14,7 @@ use DBIx::DBSchema::ColGroup::Index;
 #@ISA = qw(Exporter);
 @ISA = ();
 
-$VERSION = "0.20";
+$VERSION = "0.21";
 
 =head1 NAME
 
index 047a6c5..20bd721 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use vars qw($VERSION @ISA %typemap);
 use DBIx::DBSchema::DBD;
 
-$VERSION = '0.04';
+$VERSION = '0.05';
 @ISA = qw(DBIx::DBSchema::DBD);
 
 %typemap = (
@@ -33,15 +33,29 @@ This module implements a PostgreSQL-native driver for DBIx::DBSchema.
 sub columns {
   my($proto, $dbh, $table) = @_;
   my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
-    SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull
+    SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull,
+           a.atthasdef, a.attnum
     FROM pg_class c, pg_attribute a, pg_type t
     WHERE c.relname = '$table'
       AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
     ORDER BY a.attnum
 END
   $sth->execute or die $sth->errstr;
+
   map {
 
+    my $default = '';
+    if ( $_->{atthasdef} ) {
+      my $attnum = $_->{attnum};
+      my $d_sth = $dbh->prepare(<<END) or die $dbh->errstr;
+        SELECT substring(d.adsrc for 128) FROM pg_attrdef d, pg_class c
+        WHERE c.relname = '$table' AND c.oid = d.adrelid AND d.adnum = $attnum
+END
+      $d_sth->execute or die $d_sth->errstr;
+
+      $default = $d_sth->fetchrow_arrayref->[0];
+    };
+
     my $len = '';
     if ( $_->{attlen} == -1 && $_->{typname} ne 'text' ) {
       $len = $_->{atttypmod} - 4;
@@ -58,7 +72,7 @@ END
       $type,
       ! $_->{'attnotnull'},
       $len,
-      '', #default
+      $default,
       ''  #local
     ];
 
index 0479de7..2d6272e 100644 (file)
@@ -144,6 +144,9 @@ primary key and (unique) index information will only be imported from databases
 with DBIx::DBSchema::DBD drivers (currently MySQL and PostgreSQL), import of
 column names and attributes *should* work for any database.
 
+Note: the _odbc refers to the column types used and nothing else - you do not
+have to have ODBC installed or connect to the database via ODBC.
+
 =cut
 
 %create_params = (