From: Rafael Kitover Date: Thu, 9 Jun 2011 13:44:50 +0000 (-0400) Subject: fix is_nullable detection on MS Access X-Git-Tag: 0.07011~80 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=2ae19e70a562eae7d346d247fbdba10c81a13a67 fix is_nullable detection on MS Access --- diff --git a/Changes b/Changes index da4dc7a..baf4363 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - fix is_nullable detection on MS Access - remove '$table has no primary key' warning - added uniq_to_primary option to promote unique keys to primary keys (RT#25944) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ADO/MS_Jet.pm b/lib/DBIx/Class/Schema/Loader/DBI/ADO/MS_Jet.pm index 4ae3407..b802b78 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ADO/MS_Jet.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ADO/MS_Jet.pm @@ -124,23 +124,7 @@ sub _columns_info_for { while (my ($col, $info) = each %$result) { my $data_type = $info->{data_type}; - my $col_obj; - - my $cols = $self->_adox_catalog->Tables->Item($table)->Columns; - - for my $col_idx (0..$cols->Count-1) { - $col_obj = $cols->Item($col_idx); - if ($self->preserve_case) { - last if $col_obj->Name eq $col; - } - else { - last if lc($col_obj->Name) eq lc($col); - } - } - - if ($col_obj->Attributes | 2 == 2) { - $info->{is_nullable} = 1; - } + my $col_obj = $self->_adox_column($table, $col); if ($data_type eq 'long') { $info->{data_type} = 'integer'; @@ -194,7 +178,6 @@ sub _columns_info_for { $info->{data_type} = 'binary'; last; } - } $info->{size} = $col_obj->DefinedSize; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm index 34ded3c..8040b2e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm @@ -158,6 +158,26 @@ sub _adox_catalog { return $cat; } +sub _adox_column { + my ($self, $table, $col) = @_; + + my $col_obj; + + my $cols = $self->_adox_catalog->Tables->Item($table)->Columns; + + for my $col_idx (0..$cols->Count-1) { + $col_obj = $cols->Item($col_idx); + if ($self->preserve_case) { + last if $col_obj->Name eq $col; + } + else { + last if lc($col_obj->Name) eq lc($col); + } + } + + return $col_obj; +} + sub rescan { my $self = shift; @@ -256,6 +276,10 @@ sub _columns_info_for { while (my ($col, $info) = each %$result) { my $data_type = $info->{data_type}; + my $col_obj = $self->_adox_column($table, $col); + + $info->{is_nullable} = ($col_obj->Attributes & 2) == 2 ? 1 : 0; + if ($data_type eq 'counter') { $info->{data_type} = 'integer'; $info->{is_auto_increment} = 1; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index affa207..306860a 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -120,7 +120,7 @@ sub run_tests { $num_rescans++ if $self->{vendor} eq 'Firebird'; plan tests => @connect_info * - (207 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); + (209 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); foreach my $info_idx (0..$#connect_info) { my $info = $connect_info[$info_idx]; @@ -588,6 +588,12 @@ sub test_schema { is( $class2->column_info('crumb_crisp_coating')->{accessor}, 'trivet', 'col_accessor_map is being run' ); + is $class1->column_info('dat')->{is_nullable}, 0, + 'is_nullable=0 detection'; + + is $class2->column_info('set_primary_key')->{is_nullable}, 1, + 'is_nullable=1 detection'; + SKIP: { skip $self->{skip_rels}, 131 if $self->{skip_rels};