Skip Menu |

This queue is for tickets about the Class-DBI-Plugin-DateTime CPAN distribution.

Report information
The Basics
Id: 36035
Status: new
Priority: 0/
Queue: Class-DBI-Plugin-DateTime

People
Owner: Nobody in particular
Requestors: jozef [...] kutej.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.04
Fixed in: (no value)



Subject: Class::DBI::Plugin::DateTime::Oracle
Hi Daisuke, Can you please add also this Oracle.pm to the Class::DBI::Plugin::DateTime? It's 99% copy&paste from Pg.pm. Thank you, Jozef.
Subject: Class-DBI-Plugin-DateTime-Oracle.patch
diff -Naur Class-DBI-Plugin-DateTime-0.04/lib/Class/DBI/Plugin/DateTime/Oracle.pm Class-DBI-Plugin-DateTime/lib/Class/DBI/Plugin/DateTime/Oracle.pm --- Class-DBI-Plugin-DateTime-0.04/lib/Class/DBI/Plugin/DateTime/Oracle.pm 1970-01-01 01:00:00.000000000 +0100 +++ Class-DBI-Plugin-DateTime/lib/Class/DBI/Plugin/DateTime/Oracle.pm 2008-05-20 10:09:06.000000000 +0200 @@ -0,0 +1,111 @@ +# $Id: $ +# +# Copyright (c) 2005 Daisuke Maki <dmaki@cpan.org> +# All rights reserved. + +package Class::DBI::Plugin::DateTime::Oracle; +use strict; +use base qw(Class::DBI::Plugin::DateTime::Base); +use DateTime::Format::Oracle; + +BEGIN +{ + # Look ma, I can auto-generate all these :) + my @types = qw(datetime timestamp timestamptz time timetz date duration); + foreach my $type (@types) { + my @args = ($type) x 3; + push @args, $type eq 'duration' ? ", 'DateTime::Duration'" : ''; + eval sprintf(<<' EOM', @args); + sub has_%s + { + my $class = shift; + my $column = shift; + my $opts = shift || {}; + + my @args = exists $opts->{constructor_args} ? + @{$opts->{constructor_args}} : (); + + my $fmt_parse = DateTime::Format::Oracle->can('parse_%s'); + my $fmt_format = DateTime::Format::Oracle->can('format_%s'); + my $inflate = sub { $fmt_parse->('DateTime::Format::Oracle', shift) }; + my $deflate = sub { $fmt_format->('DateTime::Format::Oracle', shift) }; + __PACKAGE__->_setup_column($class, $column, $inflate, $deflate%s); + } + EOM + } + + { + no strict 'refs'; + *has_interval = \&has_duration; + + my @methods = map { ("has_$_") } @types; + *_export_methods = sub { @methods }; + } +} + +1; + +__END__ + +=head1 NAME + +Class::DBI::Plugin::DateTime::Oracle - Use DateTime With Oracle + +=head1 SYNOPSIS + + package MyCDBI; + use base qw(Class::DBI); + use Class::DBI::Plugin::DateTime::Oracle; + + __PACKAGE__->set_db(...); + __PACKAGE__->table(...); + __PACKAGE__->has_timestamp('a_timestamp'); + __PACKAGE__->has_date('a_date'); + __PACKAGE__->has_time('a_time'); + +=head1 DESCRIPTION + +Class::DBI::Plugin::DateTime::Oracle provides methods to work with DateTime +objects in a Class::DBI + Oracle environment. + +=head1 METHODS + +All methods take the target column name. You may optionally specify a hashref +as the second argument. For this module, you may specify the following: + +=over 4 + +=item constructor_args + +An arrayref of arguments to be passed to the DateTime::Format::Oracle object +that is used to parse/format the field. + +=back + +=head2 has_timestamp + +=head2 has_datetime + +=head2 has_date + +=head2 has_time + +=head2 has_timestamptz + +=head2 has_timetz + +=head2 has_interval + +=head2 has_duration + +=head1 SEE ALSO + +L<DateTime|DateTime> L<DateTime::Format::Oracle|DateTime::Format::Oracle> L<Class::DBI> + +=head1 AUTHOR + +Copyright (c) 2005 Daisuke Maki E<lt>dmaki@cpan.orgE<gt>. All rights reserved. + +Development funded by Brazil Ltd E<lt>http://b.razil.jpE<gt> + +=cut diff -Naur Class-DBI-Plugin-DateTime-0.04/t/08-oracle-basic.t Class-DBI-Plugin-DateTime/t/08-oracle-basic.t --- Class-DBI-Plugin-DateTime-0.04/t/08-oracle-basic.t 1970-01-01 01:00:00.000000000 +0100 +++ Class-DBI-Plugin-DateTime/t/08-oracle-basic.t 2008-05-20 12:00:37.000000000 +0200 @@ -0,0 +1,74 @@ +use strict; +BEGIN +{ + my @args; + if (grep { ! exists $ENV{$_} } + map { "ORACLE_${_}" } qw(DSN USER PASSWORD)) + { + push @args, (skip_all => "Need to define ORACLE_DSN ORACLE_USER ORACLE_PASSWORD"); + } else { + @args = (tests => 8); + } + + require Test::More; + Test::More->import(@args); +} + +package PluginTest::Oracle; +use strict; +use base qw(Class::DBI); +use Class::DBI::Plugin::DateTime::Oracle; + +my $table = "cdbi_plugin_dt_oracle"; +my $dsn = 'dbi:Oracle:' . $ENV{ORACLE_DSN}; +my $user = $ENV{ORACLE_USER}; +my $password = $ENV{ORACLE_PASSWORD}; + +PluginTest::Oracle->set_db(Main => ($dsn, $user, $password)); +PluginTest::Oracle->db_Main->do(qq{ + CREATE TABLE $table ( + id INTEGER PRIMARY KEY, + a_timestamp TIMESTAMP, + a_date DATE + ) +}); +PluginTest::Oracle->db_Main->do( + "alter session set nls_date_format = '" + .DateTime::Format::Oracle->nls_date_format + ."'" +); +PluginTest::Oracle->db_Main->do( + "alter session set nls_timestamp_format = '" + .DateTime::Format::Oracle->nls_timestamp_format + ."'" +); + +__PACKAGE__->table($table); +__PACKAGE__->columns(All => qw(id a_timestamp a_date)); +__PACKAGE__->has_timestamp('a_timestamp'); +__PACKAGE__->has_date('a_date'); + +package main; +use strict; + +eval { + my $dt = DateTime->now; + my $obj = PluginTest::Oracle->create({ + id => 1, + a_timestamp => $dt, + a_date => $dt, + }); + ok($obj, "Object creation"); + is($obj->a_timestamp, $dt, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt->clone->truncate(to => 'day'), "date match"); + + my $dt2 = DateTime->new(year => 2005, month => 7, day => 13, hour => 7, minute => 13, second => 20); + ok($obj->a_timestamp($dt2), 'set timestamp'); + ok($obj->a_date($dt2), 'set date'); + ok($obj->update, 'update database row'); + is($obj->a_timestamp, $dt2, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt2->clone->truncate(to => 'day'), "date match"); +}; +diag $@ if $@; + +PluginTest::Oracle->db_Main->do("DROP TABLE $table"); diff -Naur Class-DBI-Plugin-DateTime-0.04/t/09-oracle-explicit.t Class-DBI-Plugin-DateTime/t/09-oracle-explicit.t --- Class-DBI-Plugin-DateTime-0.04/t/09-oracle-explicit.t 1970-01-01 01:00:00.000000000 +0100 +++ Class-DBI-Plugin-DateTime/t/09-oracle-explicit.t 2008-05-20 12:03:27.000000000 +0200 @@ -0,0 +1,74 @@ +use strict; +BEGIN +{ + my @args; + if (grep { ! exists $ENV{$_} } + map { "ORACLE_${_}" } qw(DSN USER PASSWORD)) + { + push @args, (skip_all => "Need to define ORACLE_DSN ORACLE_USER ORACLE_PASSWORD"); + } else { + @args = (tests => 8); + } + + require Test::More; + Test::More->import(@args); +} + +package PluginTest::Oracle; +use strict; +use base qw(Class::DBI); +use Class::DBI::Plugin::DateTime 'Oracle'; + +my $table = "cdbi_plugin_dt_oracle"; +my $dsn = 'dbi:Oracle:' . $ENV{ORACLE_DSN}; +my $user = $ENV{ORACLE_USER}; +my $password = $ENV{ORACLE_PASSWORD}; + +PluginTest::Oracle->set_db(Main => ($dsn, $user, $password)); +PluginTest::Oracle->db_Main->do(qq{ + CREATE TABLE $table ( + id INTEGER PRIMARY KEY, + a_timestamp TIMESTAMP, + a_date DATE + ) +}); +PluginTest::Oracle->db_Main->do( + "alter session set nls_date_format = '" + .DateTime::Format::Oracle->nls_date_format + ."'" +); +PluginTest::Oracle->db_Main->do( + "alter session set nls_timestamp_format = '" + .DateTime::Format::Oracle->nls_timestamp_format + ."'" +); + +__PACKAGE__->table($table); +__PACKAGE__->columns(All => qw(id a_timestamp a_date)); +__PACKAGE__->has_timestamp('a_timestamp'); +__PACKAGE__->has_date('a_date'); + +package main; +use strict; + +eval { + my $dt = DateTime->now; + my $obj = PluginTest::Oracle->create({ + id => 1, + a_timestamp => $dt, + a_date => $dt, + }); + ok($obj, "Object creation"); + is($obj->a_timestamp, $dt, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt->clone->truncate(to => 'day'), "date match"); + + my $dt2 = DateTime->new(year => 2005, month => 7, day => 13, hour => 7, minute => 13, second => 20); + ok($obj->a_timestamp($dt2), 'set timestamp'); + ok($obj->a_date($dt2), 'set date'); + ok($obj->update, 'update database row'); + is($obj->a_timestamp, $dt2, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt2->clone->truncate(to => 'day'), "date match"); +}; +diag $@ if $@; + +PluginTest::Oracle->db_Main->do("DROP TABLE $table"); diff -Naur Class-DBI-Plugin-DateTime-0.04/t/10-oracle-auto.t Class-DBI-Plugin-DateTime/t/10-oracle-auto.t --- Class-DBI-Plugin-DateTime-0.04/t/10-oracle-auto.t 1970-01-01 01:00:00.000000000 +0100 +++ Class-DBI-Plugin-DateTime/t/10-oracle-auto.t 2008-05-20 12:07:21.000000000 +0200 @@ -0,0 +1,78 @@ +use strict; +BEGIN +{ + my @args; + if (grep { ! exists $ENV{$_} } + map { "ORACLE_${_}" } qw(DSN USER PASSWORD)) + { + push @args, (skip_all => "Need to define ORACLE_DSN ORACLE_USER ORACLE_PASSWORD"); + } else { + @args = (tests => 8); + } + + require Test::More; + Test::More->import(@args); +} + +package PluginTest::Oracle; +use strict; +use base qw(Class::DBI); + +my $table; +BEGIN { + $table = "cdbi_plugin_dt_oracle"; + my $dsn = 'dbi:Oracle:' . $ENV{ORACLE_DSN}; + my $user = $ENV{ORACLE_USER}; + my $password = $ENV{ORACLE_PASSWORD}; + + PluginTest::Oracle->set_db(Main => ($dsn, $user, $password)); + PluginTest::Oracle->db_Main->do(qq{ + CREATE TABLE $table ( + id INTEGER PRIMARY KEY, + a_timestamp TIMESTAMP, + a_date DATE + ) + }); + use DateTime::Format::Oracle; + PluginTest::Oracle->db_Main->do( + "alter session set nls_date_format = '" + .DateTime::Format::Oracle->nls_date_format + ."'" + ); + PluginTest::Oracle->db_Main->do( + "alter session set nls_timestamp_format = '" + .DateTime::Format::Oracle->nls_timestamp_format + ."'" + ); +} +use Class::DBI::Plugin::DateTime; + +__PACKAGE__->table($table); +__PACKAGE__->columns(All => qw(id a_timestamp a_date)); +__PACKAGE__->has_timestamp('a_timestamp'); +__PACKAGE__->has_date('a_date'); + +package main; +use strict; + +eval { + my $dt = DateTime->now; + my $obj = PluginTest::Oracle->create({ + id => 1, + a_timestamp => $dt, + a_date => $dt, + }); + ok($obj, "Object creation"); + is($obj->a_timestamp, $dt, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt->clone->truncate(to => 'day'), "date match"); + + my $dt2 = DateTime->new(year => 2005, month => 7, day => 13, hour => 7, minute => 13, second => 20); + ok($obj->a_timestamp($dt2), 'set timestamp'); + ok($obj->a_date($dt2), 'set date'); + ok($obj->update, 'update database row'); + is($obj->a_timestamp, $dt2, "Timestamp match"); + is($obj->a_date->clone->truncate(to => 'day'), $dt2->clone->truncate(to => 'day'), "date match"); +}; +diag $@ if $@; + +PluginTest::Oracle->db_Main->do("DROP TABLE $table");