From: Peter Rabbitson Date: Tue, 26 May 2009 14:29:55 +0000 (+0000) Subject: Merge 'top_limit_altfix' into 'trunk' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=172d3fe62815e87e7ac3bdf3c5cc4c9a515b11a8;hp=79e2de1a991e42b80fcccb338eed16b4abb2bbbb;p=dbsrgits%2FDBIx-Class-Historic.git Merge 'top_limit_altfix' into 'trunk' --- diff --git a/Changes b/Changes index 20ca87a..af51dae 100644 --- a/Changes +++ b/Changes @@ -31,6 +31,8 @@ Revision history for DBIx::Class - Sybase now supports autoinc PKs (RT#40265) - Prefetch on joins over duplicate relations now works correctly (RT#28451) + - "timestamp with time zone" columns (for Pg) now get inflated with a + time zone information preserved 0.08102 2009-04-30 08:29:00 (UTC) - Fixed two subtle bugs when using columns or select/as diff --git a/Makefile.PL b/Makefile.PL index 8b730ca..8033b36 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -72,6 +72,9 @@ my %force_requires_if_author = ( # t/60core.t 'DateTime::Format::MySQL' => 0, + + # t/89inflate_datetime.t + 'DateTime::Format::Pg' => 0, # t/72pg.t $ENV{DBICTEST_PG_DSN} diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 5b1b313..54e66f5 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -107,6 +107,10 @@ sub register_column { unless ($type) { $type = lc($info->{data_type}); + if ($type eq "timestamp with time zone" || $type eq "timestamptz") { + $type = "timestamp"; + $info->{_ic_dt_method} ||= "timestamp_with_timezone"; + } } my $timezone; diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 4a6eaa8..c657c3a 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -113,7 +113,7 @@ NULL values. This is currently only used by L. Set this to a true value for a column whose value is somehow automatically set. This is used to determine which columns to empty -when cloning objects using C. It is also used by +when cloning objects using L. It is also used by L. =item is_foreign_key @@ -1198,7 +1198,7 @@ sub _resolve_condition { $self->throw_exception( "Column ${v} not loaded or not passed to new() prior to insert()" ." on ${for} trying to resolve relationship (maybe you forgot " - ."to call ->reload_from_storage to get defaults from the db)" + ."to call ->discard_changes to get defaults from the db)" ); } return $UNRESOLVABLE_CONDITION; diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 7a77169..2aca425 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -5,7 +5,6 @@ use base qw/SQL::Abstract::Limit/; use strict; use warnings; use Carp::Clan qw/^DBIx::Class/; -use Scalar::Util(); sub new { my $self = shift->SUPER::new(@_); diff --git a/t/89inflate_datetime.t b/t/89inflate_datetime.t index f3c0e01..5a77195 100644 --- a/t/89inflate_datetime.t +++ b/t/89inflate_datetime.t @@ -8,14 +8,17 @@ use DBICTest; { local $SIG{__WARN__} = sub { warn @_ if $_[0] !~ /extra \=\> .+? has been deprecated/ }; DBICTest::Schema->load_classes('EventTZDeprecated'); + DBICTest::Schema->load_classes('EventTZPg'); } my $schema = DBICTest->init_schema(); -eval { require DateTime::Format::MySQL }; -plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@; +plan tests => 53; + +SKIP: { + eval { require DateTime::Format::MySQL }; + skip "Need DateTime::Format::MySQL for inflation tests", 50 if $@; -plan tests => 50; # inflation test my $event = $schema->resultset("Event")->find(1); @@ -142,3 +145,17 @@ is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); ## skip inflation field my $skip_inflation = $event->skip_inflation; is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time'); + +} # Skip if no MySQL DT::Formatter + +SKIP: { + + skip "ENV{DBIC_FLOATING_TZ_OK} was set, skipping", 3 unless eval { require DateTime::Format::Pg; 1}; + my $event = $schema->resultset("EventTZPg")->find(1); + $event->update({created_on => '2009-01-15 17:00:00+00'}); + $event->discard_changes; + isa_ok($event->created_on, "DateTime") or diag $event->created_on; + is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed"); + # Time zone difference -> -6hours + is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct"); +} diff --git a/t/delete/related.t b/t/delete/related.t index f3fb78b..49cd88f 100644 --- a/t/delete/related.t +++ b/t/delete/related.t @@ -4,12 +4,13 @@ use warnings; use lib qw(t/lib); use DBICTest; -plan tests => 3; +plan tests => 4; my $schema = DBICTest->init_schema(); my $ars = $schema->resultset('Artist'); my $cdrs = $schema->resultset('CD'); +my $cd2pr_rs = $schema->resultset('CD_to_Producer'); # create some custom entries $ars->populate ([ @@ -18,6 +19,7 @@ $ars->populate ([ [qw/72 a2/], [qw/73 a3/], ]); + $cdrs->populate ([ [qw/cdid artist title year/], [qw/70 71 delete0 2005/], @@ -28,6 +30,13 @@ $cdrs->populate ([ [qw/75 73 delete5 2008/], ]); +my $prod = $schema->resultset('Producer')->create ({ name => 'deleter' }); +my $prod_cd = $cdrs->find (70); +my $cd2pr = $cd2pr_rs->create ({ + producer => $prod, + cd => $prod_cd, +}); + my $total_cds = $cdrs->count; # test that delete_related w/o conditions deletes all related records only @@ -43,3 +52,10 @@ is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok'); # test that related deletion with limit condition works $a2_cds->search ({}, { rows => 1})->delete; is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok'); + +TODO: { + local $TODO = 'delete_related is based on search_related which is based on search which does not understand object arguments'; + my $cd2pr_count = $cd2pr_rs->count; + $prod_cd->delete_related('cd_to_producer', { producer => $prod } ); + is ($cd2pr_rs->count, $cd2pr_count -= 1, 'm2m link deleted succesfully'); +} diff --git a/t/lib/DBICTest/Schema/EventTZPg.pm b/t/lib/DBICTest/Schema/EventTZPg.pm new file mode 100644 index 0000000..e2b512e --- /dev/null +++ b/t/lib/DBICTest/Schema/EventTZPg.pm @@ -0,0 +1,24 @@ +package DBICTest::Schema::EventTZPg; + +use strict; +use warnings; +use base qw/DBICTest::BaseResult/; + +__PACKAGE__->load_components(qw/InflateColumn::DateTime/); + +__PACKAGE__->table('event'); + +__PACKAGE__->add_columns( + id => { data_type => 'integer', is_auto_increment => 1 }, + starts_at => { data_type => 'datetime', timezone => "America/Chicago", locale => 'de_DE' }, + created_on => { data_type => 'timestamp with time zone', timezone => "America/Chicago" }, +); + +__PACKAGE__->set_primary_key('id'); + +sub _datetime_parser { + require DateTime::Format::Pg; + DateTime::Format::Pg->new(); +} + +1;