added preserve_case option
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / DB2.pm
index b3a1c23..886a45b 100644 (file)
@@ -9,7 +9,7 @@ use base qw/
 use Carp::Clan qw/^DBIx::Class/;
 use Class::C3;
 
-our $VERSION = '0.05003';
+our $VERSION = '0.07000';
 
 =head1 NAME
 
@@ -37,6 +37,10 @@ sub _setup {
 
     my $dbh = $self->schema->storage->dbh;
     $self->{db_schema} ||= $dbh->selectrow_array('VALUES(CURRENT_USER)', {});
+
+    if (not defined $self->preserve_case) {
+        $self->preserve_case(0);
+    }
 }
 
 sub _table_uniq_info {
@@ -49,7 +53,8 @@ sub _table_uniq_info {
     my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare(
         q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ
         FROM SYSCAT.TABCONST as tc
-        JOIN SYSCAT.KEYCOLUSE as kcu ON tc.CONSTNAME = kcu.CONSTNAME
+        JOIN SYSCAT.KEYCOLUSE as kcu
+        ON tc.CONSTNAME = kcu.CONSTNAME AND tc.TABSCHEMA = kcu.TABSCHEMA
         WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'}
     ) or die $DBI::errstr;
 
@@ -103,29 +108,35 @@ sub _table_fk_info {
 }
 
 sub _columns_info_for {
-    my ($self, $table) = @_;
-    return $self->next::method(uc $table);
-}
+    my $self = shift;
+    my ($table) = @_;
 
-sub _extra_column_info {
-    my ($self, $table, $column, $info, $dbi_info) = @_;
-    my %extra_info;
+    my $result = $self->next::method(uc $table);
 
     my $dbh = $self->schema->storage->dbh;
-    my $sth = $dbh->prepare_cached(
-        q{
-            SELECT COUNT(*)
-            FROM syscat.columns
-            WHERE tabschema = ? AND tabname = ? AND colname = ?
-            AND identity = 'Y' AND generated != ''
-        },
-        {}, 1);
-    $sth->execute($self->db_schema, $table, $column);
-    if ($sth->fetchrow_array) {
-        $extra_info{is_auto_increment} = 1;
+
+    while (my ($col, $info) = each %$result) {
+        # check for identities
+        my $sth = $dbh->prepare_cached(
+            q{
+                SELECT COUNT(*)
+                FROM syscat.columns
+                WHERE tabschema = ? AND tabname = ? AND colname = ?
+                AND identity = 'Y' AND generated != ''
+            },
+            {}, 1);
+        $sth->execute($self->db_schema, uc $table, uc $col);
+        if ($sth->fetchrow_array) {
+            $info->{is_auto_increment} = 1;
+        }
+
+        if (eval { lc ${ $info->{default_value} } }||'' eq 'current timestamp') {
+            ${ $info->{default_value} } = 'CURRENT_TIMESTAMP';
+            delete $info->{size};
+        }
     }
 
-    return \%extra_info;
+    return $result;
 }
 
 =head1 SEE ALSO
@@ -145,3 +156,4 @@ the same terms as Perl itself.
 =cut
 
 1;
+# vim:et sts=4 sw=4 tw=0: