From: Rafael Kitover Date: Tue, 21 Dec 2010 20:01:32 +0000 (-0500) Subject: Remove small_datetime from the main schema - it is not a standard datatype X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d98c75e2c45cbd5ddd995cbeb48810f6ad7e1ca;p=dbsrgits%2FDBIx-Class-Historic.git Remove small_datetime from the main schema - it is not a standard datatype --- diff --git a/t/72pg.t b/t/72pg.t index 2394bed..6505507 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -487,8 +487,7 @@ CREATE TABLE dbic_t_schema.track ( position int, title varchar(255), last_updated_on date, - last_updated_at date, - small_dt date + last_updated_at date ) EOS diff --git a/t/73oracle.t b/t/73oracle.t index 4627624..f2dea6a 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -454,7 +454,7 @@ sub do_creates { $dbh->do("CREATE TABLE cd (${q}cdid${q} NUMBER(12), ${q}artist${q} NUMBER(12), ${q}title${q} VARCHAR(255), ${q}year${q} VARCHAR(4), ${q}genreid${q} NUMBER(12), ${q}single_track${q} NUMBER(12))"); $dbh->do("ALTER TABLE cd ADD (CONSTRAINT ${q}cd_pk${q} PRIMARY KEY (${q}cdid${q}))"); - $dbh->do("CREATE TABLE ${q}track${q} (${q}trackid${q} NUMBER(12), ${q}cd${q} NUMBER(12) REFERENCES CD(${q}cdid${q}) DEFERRABLE, ${q}position${q} NUMBER(12), ${q}title${q} VARCHAR(255), ${q}last_updated_on${q} DATE, ${q}last_updated_at${q} DATE, ${q}small_dt${q} DATE)"); + $dbh->do("CREATE TABLE ${q}track${q} (${q}trackid${q} NUMBER(12), ${q}cd${q} NUMBER(12) REFERENCES CD(${q}cdid${q}) DEFERRABLE, ${q}position${q} NUMBER(12), ${q}title${q} VARCHAR(255), ${q}last_updated_on${q} DATE, ${q}last_updated_at${q} DATE)"); $dbh->do("ALTER TABLE ${q}track${q} ADD (CONSTRAINT ${q}track_pk${q} PRIMARY KEY (${q}trackid${q}))"); $dbh->do("CREATE TABLE ${q}bindtype_test${q} (${q}id${q} integer NOT NULL PRIMARY KEY, ${q}bytea${q} integer NULL, ${q}blob${q} blob NULL, ${q}clob${q} clob NULL)"); diff --git a/t/inflate/datetime_mssql.t b/t/inflate/datetime_mssql.t index e9c003e..3c425e7 100644 --- a/t/inflate/datetime_mssql.t +++ b/t/inflate/datetime_mssql.t @@ -4,9 +4,12 @@ use warnings; use Test::More; use Test::Exception; use Scope::Guard (); +use Try::Tiny; use lib qw(t/lib); use DBICTest; +DBICTest::Schema->load_classes('EventSmallDT'); + # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else BEGIN { if (my $lib_dirs = $ENV{DBICTEST_MSSQL_PERL5LIB}) { @@ -21,7 +24,7 @@ if (not ($dsn || $dsn2)) { plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN} and/or $ENV{DBICTEST_MSSQL_DSN} _USER ' .'and _PASS to run this test' . - "\nWarning: This test drops and creates a table called 'track'"; + "\nWarning: This test drops and creates a table called 'small_dt'"; } plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt') @@ -55,10 +58,30 @@ for my $connect_info (@connect_info) { my $guard = Scope::Guard->new(\&cleanup); -# coltype, column, datehash + try { $schema->storage->dbh->do("DROP TABLE track") }; + $schema->storage->dbh->do(<<"SQL"); +CREATE TABLE track ( + trackid INT IDENTITY PRIMARY KEY, + cd INT, + position INT, + last_updated_at DATETIME, +) +SQL + try { $schema->storage->dbh->do("DROP TABLE event_small_dt") }; + $schema->storage->dbh->do(<<"SQL"); +CREATE TABLE event_small_dt ( + id INT IDENTITY PRIMARY KEY, + small_dt SMALLDATETIME, +) +SQL + +# coltype, column, source, pk, create_extra, datehash my @dt_types = ( ['DATETIME', 'last_updated_at', + 'Track', + 'trackid', + { cd => 1 }, { year => 2004, month => 8, @@ -70,6 +93,9 @@ for my $connect_info (@connect_info) { }], ['SMALLDATETIME', # minute precision 'small_dt', + 'EventSmallDT', + 'id', + {}, { year => 2004, month => 8, @@ -80,26 +106,17 @@ for my $connect_info (@connect_info) { ); for my $dt_type (@dt_types) { - my ($type, $col, $sample_dt) = @$dt_type; + my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type; - eval { $schema->storage->dbh->do("DROP TABLE track") }; - $schema->storage->dbh->do(<<"SQL"); -CREATE TABLE track ( - trackid INT IDENTITY PRIMARY KEY, - cd INT, - position INT, - $col $type, -) -SQL ok(my $dt = DateTime->new($sample_dt)); my $row; - ok( $row = $schema->resultset('Track')->create({ + ok( $row = $schema->resultset($source)->create({ $col => $dt, - cd => 1, + %$create_extra, })); - ok( $row = $schema->resultset('Track') - ->search({ trackid => $row->trackid }, { select => [$col] }) + ok( $row = $schema->resultset($source) + ->search({ $pk => $row->$pk }, { select => [$col] }) ->first ); is( $row->$col, $dt, "$type roundtrip" ); @@ -116,5 +133,6 @@ done_testing; sub cleanup { if (my $dbh = eval { $schema->storage->dbh }) { $dbh->do('DROP TABLE track'); + $dbh->do('DROP TABLE event_small_dt'); } } diff --git a/t/inflate/datetime_oracle.t b/t/inflate/datetime_oracle.t index d118a0c..a9148a4 100644 --- a/t/inflate/datetime_oracle.t +++ b/t/inflate/datetime_oracle.t @@ -38,7 +38,7 @@ my $dbh = $schema->storage->dbh; eval { $dbh->do("DROP TABLE track"); }; -$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at TIMESTAMP, small_dt DATE)"); +$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at TIMESTAMP)"); # insert a row to play with my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07', last_updated_at => '2009-05-03 21:17:18.5' }); diff --git a/t/inflate/datetime_sybase.t b/t/inflate/datetime_sybase.t index ab64136..1531cac 100644 --- a/t/inflate/datetime_sybase.t +++ b/t/inflate/datetime_sybase.t @@ -3,9 +3,13 @@ use warnings; use Test::More; use Test::Exception; +use Scope::Guard (); +use Try::Tiny; use lib qw(t/lib); use DBICTest; +DBICTest::Schema->load_classes('EventSmallDT'); + my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/}; if (not ($dsn && $user)) { @@ -30,66 +34,97 @@ for my $storage_type (@storage_types) { $schema->storage_type("::$storage_type"); } $schema->connection($dsn, $user, $pass, { - AutoCommit => 1, - on_connect_call => [ 'datetime_setup' ], + on_connect_call => 'datetime_setup', }); + my $guard = Scope::Guard->new(\&cleanup); + $schema->storage->ensure_connected; isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" ); -# coltype, col, date + eval { $schema->storage->dbh->do("DROP TABLE track") }; + $schema->storage->dbh->do(<<"SQL"); +CREATE TABLE track ( + trackid INT IDENTITY PRIMARY KEY, + cd INT NULL, + position INT NULL, + last_updated_at DATETIME NULL +) +SQL + eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") }; + $schema->storage->dbh->do(<<"SQL"); +CREATE TABLE event_small_dt ( + id INT IDENTITY PRIMARY KEY, + small_dt SMALLDATETIME NULL, +) +SQL + +# coltype, column, source, pk, create_extra, datehash my @dt_types = ( - ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'], -# minute precision - ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'], + ['DATETIME', + 'last_updated_at', + 'Track', + 'trackid', + { cd => 1 }, + { + year => 2004, + month => 8, + day => 21, + hour => 14, + minute => 36, + second => 48, + nanosecond => 500000000, + }], + ['SMALLDATETIME', # minute precision + 'small_dt', + 'EventSmallDT', + 'id', + {}, + { + year => 2004, + month => 8, + day => 21, + hour => 14, + minute => 36, + }], ); for my $dt_type (@dt_types) { - my ($type, $col, $sample_dt) = @$dt_type; + my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type; - eval { $schema->storage->dbh->do("DROP TABLE track") }; - $schema->storage->dbh->do(<<"SQL"); -CREATE TABLE track ( - trackid INT IDENTITY PRIMARY KEY, - cd INT NULL, - position INT NULL, - $col $type NULL -) -SQL - ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt)); + ok(my $dt = DateTime->new($sample_dt)); my $row; - ok( $row = $schema->resultset('Track')->create({ + ok( $row = $schema->resultset($source)->create({ $col => $dt, - cd => 1, + %$create_extra, })); - ok( $row = $schema->resultset('Track') - ->search({ trackid => $row->trackid }, { select => [$col] }) + ok( $row = $schema->resultset($source) + ->search({ $pk => $row->$pk }, { select => [$col] }) ->first ); is( $row->$col, $dt, "$type roundtrip" ); - is( $row->$col->nanosecond, $dt->nanosecond, - 'fractional DateTime portion roundtrip' ) - if $dt->nanosecond > 0; + cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond}, + 'DateTime fractional portion roundtrip' ) + if exists $sample_dt->{nanosecond}; } # test a computed datetime column eval { $schema->storage->dbh->do("DROP TABLE track") }; $schema->storage->dbh->do(<<"SQL"); CREATE TABLE track ( - trackid INT IDENTITY PRIMARY KEY, - cd INT NULL, - position INT NULL, - title VARCHAR(100) NULL, - last_updated_on DATETIME NULL, - last_updated_at AS getdate(), - small_dt SMALLDATETIME NULL + trackid INT IDENTITY PRIMARY KEY, + cd INT NULL, + position INT NULL, + title VARCHAR(100) NULL, + last_updated_on DATETIME NULL, + last_updated_at AS getdate(), ) SQL - my $now = DateTime->now; + my $now = DateTime->now; sleep 1; my $new_row = $schema->resultset('Track')->create({}); $new_row->discard_changes; @@ -102,8 +137,9 @@ SQL done_testing; # clean up our mess -END { - if (my $dbh = eval { $schema->storage->_dbh }) { +sub cleanup { + if (my $dbh = eval { $schema->storage->dbh }) { $dbh->do('DROP TABLE track'); + $dbh->do('DROP TABLE event_small_dt'); } } diff --git a/t/lib/DBICTest/Schema/EventSmallDT.pm b/t/lib/DBICTest/Schema/EventSmallDT.pm new file mode 100644 index 0000000..560581d --- /dev/null +++ b/t/lib/DBICTest/Schema/EventSmallDT.pm @@ -0,0 +1,18 @@ +package DBICTest::Schema::EventSmallDT; + +use strict; +use warnings; +use base qw/DBICTest::BaseResult/; + +__PACKAGE__->load_components(qw/InflateColumn::DateTime/); + +__PACKAGE__->table('event_small_dt'); + +__PACKAGE__->add_columns( + id => { data_type => 'integer', is_auto_increment => 1 }, + small_dt => { data_type => 'smalldatetime', is_nullable => 1 }, +); + +__PACKAGE__->set_primary_key('id'); + +1; diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index de3f3c1..7a738a1 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -30,10 +30,6 @@ __PACKAGE__->add_columns( data_type => 'datetime', is_nullable => 1 }, - small_dt => { # for mssql and sybase DT tests - data_type => 'smalldatetime', - is_nullable => 1 - }, ); __PACKAGE__->set_primary_key('trackid'); diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 9178263..ea5891b 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Sun Oct 17 01:51:06 2010 +-- Created on Thu Nov 18 08:18:15 2010 -- -- @@ -298,8 +298,7 @@ CREATE TABLE track ( position int NOT NULL, title varchar(100) NOT NULL, last_updated_on datetime, - last_updated_at datetime, - small_dt smalldatetime + last_updated_at datetime ); CREATE INDEX track_idx_cd ON track (cd); diff --git a/t/multi_create/in_memory.t b/t/multi_create/in_memory.t index cbd5309..83341b1 100644 --- a/t/multi_create/in_memory.t +++ b/t/multi_create/in_memory.t @@ -112,7 +112,6 @@ my $schema = DBICTest->init_schema(); last_updated_at => undef, last_updated_on => undef, position => 1, - small_dt => undef, title => "$reldir: First track of latest cd", trackid => 19 } diff --git a/t/prefetch/double_prefetch.t b/t/prefetch/double_prefetch.t index d82f4c4..f16ace6 100644 --- a/t/prefetch/double_prefetch.t +++ b/t/prefetch/double_prefetch.t @@ -1,4 +1,4 @@ -use warnings; +use warnings; use Test::More; use Test::Exception; @@ -23,8 +23,8 @@ is_same_sql( '( SELECT cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track, - single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at, single_track.small_dt, - single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at, single_track_2.small_dt, + single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at, + single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at, cd.cdid, cd.artist, cd.title, cd.year, cd.genreid, cd.single_track FROM artist me JOIN cd cds ON cds.artist = me.artistid diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 8c84462..d0b8e6c 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -161,7 +161,7 @@ for ($cd_rs->all) { $most_tracks_rs->as_query, '( SELECT me.cdid, me.track_count, me.maxtr, - tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, tracks.small_dt, + tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, liner_notes.liner_id, liner_notes.notes FROM ( SELECT me.cdid, COUNT( tracks.trackid ) AS track_count, MAX( tracks.trackid ) AS maxtr diff --git a/t/prefetch/o2m_o2m_order_by_with_limit.t b/t/prefetch/o2m_o2m_order_by_with_limit.t index c593379..c77530a 100644 --- a/t/prefetch/o2m_o2m_order_by_with_limit.t +++ b/t/prefetch/o2m_o2m_order_by_with_limit.t @@ -26,7 +26,7 @@ is_same_sql_bind( $filtered_cd_rs->as_query, q{( SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track, - tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, tracks.small_dt + tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at FROM artist me JOIN ( SELECT cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track @@ -71,7 +71,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '1', - 'small_dt' => undef, 'title' => 'Boring Name', 'trackid' => '10' }, @@ -80,7 +79,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '2', - 'small_dt' => undef, 'title' => 'Boring Song', 'trackid' => '11' }, @@ -89,7 +87,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '3', - 'small_dt' => undef, 'title' => 'No More Ideas', 'trackid' => '12' } @@ -108,7 +105,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '1', - 'small_dt' => undef, 'title' => 'Sad', 'trackid' => '13' }, @@ -117,7 +113,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '3', - 'small_dt' => undef, 'title' => 'Suicidal', 'trackid' => '15' }, @@ -126,7 +121,6 @@ is_deeply ( 'last_updated_at' => undef, 'last_updated_on' => undef, 'position' => '2', - 'small_dt' => undef, 'title' => 'Under The Weather', 'trackid' => '14' } diff --git a/t/prefetch/with_limit.t b/t/prefetch/with_limit.t index 9c1f067..bc035de 100644 --- a/t/prefetch/with_limit.t +++ b/t/prefetch/with_limit.t @@ -102,7 +102,7 @@ is_same_sql_bind ( '( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, - tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, tracks.small_dt, + tracks.trackid, tracks.cd, tracks.position, tracks.title, tracks.last_updated_on, tracks.last_updated_at, artist.artistid, artist.name, artist.rank, artist.charfield FROM ( SELECT