use warnings;
use Test::More;
+use Test::Exception;
use DBIx::Class::Schema::Loader;
use Class::Unload;
use File::Path;
$self->{date_datatype} ||= 'DATE';
# Not all DBS do SQL-standard CURRENT_TIMESTAMP
- $self->{default_function} ||= "CURRENT_TIMESTAMP";
- $self->{default_function_def} ||= "TIMESTAMP DEFAULT $self->{default_function}";
+ $self->{default_function} ||= "current_timestamp";
+ $self->{default_function_def} ||= "timestamp default $self->{default_function}";
$self = bless $self, $class;
my $extra_count = $self->{extra}{count} || 0;
- plan tests => @connect_info * (176 + $extra_count + ($self->{data_type_tests}{test_count} || 0));
+ plan tests => @connect_info * (178 + $extra_count + ($self->{data_type_tests}{test_count} || 0));
foreach my $info_idx (0..$#connect_info) {
my $info = $connect_info[$info_idx];
$self->drop_extra_tables_only;
my $dbh = $self->dbconnect(1);
- $dbh->do($_) for @{ $self->{extra}{create} || [] };
- $dbh->do($self->{data_type_tests}{ddl}) if $self->{data_type_tests}{ddl};
+ {
+ # Silence annoying but harmless postgres "NOTICE: CREATE TABLE..."
+ local $SIG{__WARN__} = sub {
+ my $msg = shift;
+ warn $msg unless $msg =~ m{^NOTICE:\s+CREATE TABLE};
+ };
+
+
+ $dbh->do($_) for @{ $self->{extra}{create} || [] };
+ $dbh->do($self->{data_type_tests}{ddl}) if $self->{data_type_tests}{ddl};
+ }
$self->{_created} = 1;
my $file_count = grep /CREATE (?:TABLE|VIEW)/i, @{ $self->{extra}{create} || [] };
'constant integer default',
);
- is(
- $class35->column_info('a_double')->{default_value}, 10.555,
+ cmp_ok(
+ $class35->column_info('a_double')->{default_value}, '==', 10.555,
'constant numeric default',
);
is $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{on_update}, 'CASCADE',
"on_update => 'CASCADE' on belongs_to by default";
- is $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{is_deferrable}, 1,
- "is_deferrable => 1 on belongs_to by default";
+ ok ((not exists $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{is_deferrable}),
+ "is_deferrable => 1 not on belongs_to by default");
ok ((not exists $rsobj4->result_source->relationship_info('fkid_singular')->{attrs}{cascade_delete}),
'belongs_to does not have cascade_delete');
eval { $rsobj5->find({id1 => 1, id2 => 1}) };
die $@ if $@;
- is( $obj5->id2, 1, "Find on multi-col PK" );
+ is( (eval { $obj5->id2 } || eval { $obj5->i_d2 }), 1, "Find on multi-col PK" );
# mulit-col fk def
my $obj6 = $rsobj6->find(1);
}
# rescan and norewrite test
- SKIP: {
+ {
my @statements_rescan = (
qq{
CREATE TABLE loader_test30 (
my $before_digest = $digest->digest;
+ $conn->storage->disconnect; # needed for Firebird and Informix
my $dbh = $self->dbconnect(1);
{
# Silence annoying but harmless postgres "NOTICE: CREATE TABLE..."
local $SIG{__WARN__} = sub {
my $msg = shift;
- print STDERR $msg unless $msg =~ m{^NOTICE:\s+CREATE TABLE};
+ warn $msg unless $msg =~ m{^NOTICE:\s+CREATE TABLE};
};
$dbh->do($_) for @statements_rescan;
}
$dbh->disconnect;
- $conn->storage->disconnect; # needed for Firebird
sleep 1;
my $rsobj30 = $conn->resultset('LoaderTest30');
isa_ok($rsobj30, 'DBIx::Class::ResultSet');
- skip 'no rels', 2 if $self->{skip_rels};
+ SKIP: {
+ skip 'no rels', 2 if $self->{skip_rels};
+
+ my $obj30 = $rsobj30->find(123);
+ isa_ok( $obj30->loader_test2, $class2);
+
+ ok($rsobj30->result_source->column_info('loader_test2')->{is_foreign_key},
+ 'Foreign key detected');
+ }
+
+ $conn->storage->disconnect; # for Firebird
+ $conn->storage->dbh->do("DROP TABLE loader_test30");
- my $obj30 = $rsobj30->find(123);
- isa_ok( $obj30->loader_test2, $class2);
+ @new = do {
+ local $SIG{__WARN__} = sub {};
+ $conn->rescan;
+ };
+ is_deeply(\@new, [], 'no new tables on rescan');
- ok($rsobj30->result_source->column_info('loader_test2')->{is_foreign_key},
- 'Foreign key detected');
+ throws_ok { $conn->resultset('LoaderTest30') }
+ qr/Can't find source/,
+ 'source unregistered for dropped table after rescan';
}
$self->test_data_types($conn);
},
$make_auto_inc->(qw/loader_test11 id11/),
- (q{ ALTER TABLE loader_test10 ADD CONSTRAINT } .
- q{ loader_test11_fk FOREIGN KEY (loader_test11) } .
- q{ REFERENCES loader_test11 (id11) }),
+ (lc($self->{vendor}) ne 'informix' ?
+ (q{ ALTER TABLE loader_test10 ADD CONSTRAINT loader_test11_fk } .
+ q{ FOREIGN KEY (loader_test11) } .
+ q{ REFERENCES loader_test11 (id11) })
+ :
+ (q{ ALTER TABLE loader_test10 ADD CONSTRAINT } .
+ q{ FOREIGN KEY (loader_test11) } .
+ q{ REFERENCES loader_test11 (id11) } .
+ q{ CONSTRAINT loader_test11_fk })
+ ),
);
@statements_advanced_sqlite = (
# Silence annoying but harmless postgres "NOTICE: CREATE TABLE..."
local $SIG{__WARN__} = sub {
my $msg = shift;
- print STDERR $msg unless $msg =~ m{^NOTICE:\s+CREATE TABLE};
+ warn $msg unless $msg =~ m{^NOTICE:\s+CREATE TABLE};
};
$dbh->do($_) for (@statements);
my %seen_col_names;
while (my ($col_def, $expected_info) = each %$types) {
- (my $type_alias = lc($col_def)) =~ s/\( ([^)]+) \)//xg;
+ (my $type_alias = $col_def) =~ s/\( ([^)]+) \)//xg;
my $size = $1;
$size = '' unless defined $size;
my @size = split /,/, $size;
# some DBs don't like very long column names
- if ($self->{vendor} =~ /^firebird|sqlanywhere\z/i) {
+ if ($self->{vendor} =~ /^(?:firebird|sqlanywhere|oracle)\z/i) {
my ($col_def, $default) = $type_alias =~ /^(.*)(default.*)?\z/i;
$type_alias = substr $col_def, 0, 15;
$col_name .= "_sz_$size_name";
}
- $col_name .= "_$seen_col_names{$col_name}" if $seen_col_names{$col_name}++;
+ # XXX would be better to check _loader->preserve_case
+ $col_name = lc $col_name;
+
+ $col_name .= '_' . $seen_col_names{$col_name} if $seen_col_names{$col_name}++;
$ddl .= " $col_name $col_def,\n";