set up v8 relbuilder, strip _ref as well as _id
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / InterBase.pm
index 3fdf44c..61e4733 100644 (file)
@@ -2,17 +2,13 @@ package DBIx::Class::Schema::Loader::DBI::InterBase;
 
 use strict;
 use warnings;
-use namespace::autoclean;
 use Class::C3;
 use base qw/DBIx::Class::Schema::Loader::DBI/;
 use Carp::Clan qw/^DBIx::Class/;
 use List::Util 'first';
+use namespace::clean;
 
-__PACKAGE__->mk_group_ro_accessors('simple', qw/
-    unquoted_ddl
-/);
-
-our $VERSION = '0.06000';
+our $VERSION = '0.08000';
 
 =head1 NAME
 
@@ -21,21 +17,22 @@ Firebird Implementation.
 
 =head1 DESCRIPTION
 
-See L<DBIx::Class::Schema::Loader::Base> for available options.
+See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
 
-By default column names from unquoted DDL will be generated in uppercase, as
-that is the only way they will work with quoting on.
+=head1 COLUMN NAME CASE ISSUES
 
-See the L</unquoted_ddl> option in this driver if you would like to have
-lowercase column names.
+By default column names from unquoted DDL will be generated in lowercase, for
+consistency with other backends. 
 
-=head1 DRIVER OPTIONS
+Set the L<preserve_case|DBIx::Class::Schema::Loader::Base/preserve_case> option
+to true if you would like to have column names in the internal case, which is
+uppercase for DDL that uses unquoted identifiers.
 
-=head2 unquoted_ddl
+Do not use quoting (the L<quote_char|DBIx::Class::Storage::DBI/quote_char>
+option in L<connect_info|DBIx::Class::Storage::DBI/connect_info> when in the
+default C<< preserve_case => 0 >> mode.
 
-Set this loader option if your DDL uses unquoted identifiers and you will not
-use quoting (the L<quote_char|DBIx::Class::Storage::DBI/quote_char> option in
-L<connect_info|DBIx::Class::Storage::DBI/connect_info>.)
+Be careful to also not use any SQL reserved words in your DDL.
 
 This will generate lowercase column names (as opposed to the actual uppercase
 names) in your Result classes that will only work with quoting off.
@@ -45,49 +42,34 @@ will not work with quoting turned off.
 
 =cut
 
-sub _is_case_sensitive {
-    my $self = shift;
-
-    return $self->unquoted_ddl ? 0 : 1;
-}
-
 sub _setup {
     my $self = shift;
 
-    $self->next::method;
-
-    $self->schema->storage->sql_maker->name_sep('.');
+    $self->next::method(@_);
 
-    if (not defined $self->unquoted_ddl) {
+    if (not defined $self->preserve_case) {
         warn <<'EOF';
 
-WARNING: Assuming mixed-case Firebird DDL, see the unquoted_ddl option in
+WARNING: Assuming unquoted Firebird DDL, see
 perldoc DBIx::Class::Schema::Loader::DBI::InterBase
+and the 'preserve_case' option in
+perldoc DBIx::Class::Schema::Loader::Base
 for more information.
 
 EOF
+        $self->preserve_case(0);
     }
 
-    if (not $self->unquoted_ddl) {
+    if ($self->preserve_case) {
         $self->schema->storage->sql_maker->quote_char('"');
+        $self->schema->storage->sql_maker->name_sep('.');
     }
     else {
         $self->schema->storage->sql_maker->quote_char(undef);
+        $self->schema->storage->sql_maker->name_sep(undef);
     }
 }
 
-sub _lc {
-    my ($self, $name) = @_;
-
-    return $self->unquoted_ddl ? lc($name) : $name;
-}
-
-sub _uc {
-    my ($self, $name) = @_;
-
-    return $self->unquoted_ddl ? uc($name) : $name;
-}
-
 sub _table_pk_info {
     my ($self, $table) = @_;
 
@@ -213,8 +195,8 @@ EOF
 SELECT f.rdb$field_precision, f.rdb$field_scale, f.rdb$field_type, f.rdb$field_sub_type, t.rdb$type_name, st.rdb$type_name
 FROM rdb$fields f
 JOIN rdb$relation_fields rf ON rf.rdb$field_source = f.rdb$field_name
-JOIN rdb$types t  ON f.rdb$field_type     = t.rdb$type  AND t.rdb$field_name  = 'RDB$FIELD_TYPE'
-JOIN rdb$types st ON f.rdb$field_sub_type = st.rdb$type AND st.rdb$field_name = 'RDB$FIELD_SUB_TYPE'
+LEFT JOIN rdb$types t  ON f.rdb$field_type     = t.rdb$type  AND t.rdb$field_name  = 'RDB$FIELD_TYPE'
+LEFT JOIN rdb$types st ON f.rdb$field_sub_type = st.rdb$type AND st.rdb$field_name = 'RDB$FIELD_SUB_TYPE'
 WHERE rf.rdb$relation_name = ?
     AND rf.rdb$field_name  = ?
 EOF
@@ -226,11 +208,11 @@ EOF
             s/\s+\z// for $type_name, $sub_type_name;
 
             # fixups primarily for DBD::InterBase
-            if ($info->{data_type} =~ /^integer|int|smallint|bigint|-9581\z/) {
-                if ($precision && $type_name =~ /^LONG|INT64\z/ && $sub_type_name eq 'BLR') {
+            if ($info->{data_type} =~ /^(?:integer|int|smallint|bigint|-9581)\z/) {
+                if ($precision && $type_name =~ /^(?:LONG|INT64)\z/ && $sub_type_name eq 'BLR') {
                     $info->{data_type} = 'decimal';
                 }
-                elsif ($precision && $type_name =~ /^LONG|SHORT|INT64\z/ && $sub_type_name eq 'TEXT') {
+                elsif ($precision && $type_name =~ /^(?:LONG|SHORT|INT64)\z/ && $sub_type_name eq 'TEXT') {
                     $info->{data_type} = 'numeric';
                 }
                 elsif ((not $precision) && $type_name eq 'INT64' && $sub_type_name eq 'BINARY') {
@@ -248,7 +230,7 @@ EOF
             }
         }
 
-        if ($info->{data_type} =~ /^decimal|numeric\z/ && defined $precision && defined $scale) {
+        if ($info->{data_type} =~ /^(?:decimal|numeric)\z/ && defined $precision && defined $scale) {
             if ($precision == 9 && $scale == 0) {
                 delete $info->{size};
             }
@@ -272,8 +254,8 @@ EOF
         elsif ($info->{data_type} eq 'character') {
             $info->{data_type} = 'char';
         }
-        elsif ($info->{data_type} eq 'real') {
-            $info->{data_type} = 'float';
+        elsif ($info->{data_type} eq 'float') {
+            $info->{data_type} = 'real';
         }
         elsif ($info->{data_type} eq 'int64' || $info->{data_type} eq '-9581') {
             # the constant is just in case, the query should pick up the type
@@ -281,10 +263,10 @@ EOF
         }
 
         # DBD::InterBase sets scale to '0' for some reason for char types
-        if ($info->{data_type} =~ /^char|varchar\z/ && ref($info->{size}) eq 'ARRAY') {
+        if ($info->{data_type} =~ /^(?:char|varchar)\z/ && ref($info->{size}) eq 'ARRAY') {
             $info->{size} = $info->{size}[0];
         }
-        elsif ($info->{data_type} !~ /^char|varchar|numeric|decimal\z/) {
+        elsif ($info->{data_type} !~ /^(?:char|varchar|numeric|decimal)\z/) {
             delete $info->{size};
         }
 
@@ -305,9 +287,12 @@ EOF
                 $info->{default_value} = $quoted;
             }
             else {
-                $info->{default_value} = $def =~ /^\d/ ? $def : \$def;
+                $info->{default_value} = $def =~ /^-?\d/ ? $def : \$def;
             }
         }
+
+        ${ $info->{default_value} } = 'current_timestamp'
+            if ref $info->{default_value} && ${ $info->{default_value} } eq 'CURRENT_TIMESTAMP';
     }
 
     return $result;