Revision history for DBIx::Class
+ - Deprecate $storage->datetime_parser_type in favor of new method
+ datetime_parse_via, which also accepts strptime formats (see docs in
+ ::Storage::DBI.) This only affects storage driver writers.
+
0.08200 2012-08-24 (UTC)
* Fixes
- Change one of the new tests for the previous release to not require
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor');
__PACKAGE__->mk_group_accessors('inherited' => qw/
- sql_limit_dialect sql_quote_char sql_name_sep
+ sql_limit_dialect sql_quote_char sql_name_sep datetime_strptime_formats
/);
-__PACKAGE__->mk_group_accessors('component_class' => qw/sql_maker_class datetime_parser_type/);
+__PACKAGE__->mk_group_accessors('component_class' => qw/sql_maker_class datetime_parser_class/);
__PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker');
-__PACKAGE__->datetime_parser_type('DateTime::Format::MySQL'); # historic default
+__PACKAGE__->datetime_parser_class('DateTime::Format::MySQL'); # historic default
__PACKAGE__->sql_name_sep('.');
sqlt_type
sql_maker
build_datetime_parser
+ datetime_parser_class
datetime_parser_type
+ datetime_parse_via
txn_begin
insert
=head2 datetime_parser_type
-Defines the datetime parser class - currently defaults to L<DateTime::Format::MySQL>
+B<*DEPRECATED*>
+
+Defines the datetime parser class - currently defaults to
+L<DateTime::Format::MySQL>. Use L</datetime_parse_via> instead.
+
+=cut
+
+sub datetime_parser_type {
+ my $self = shift;
+ carp_unique 'this method is deprecated, use datetime_parse_via instead';
+ return $self->datetime_parse_via(@_);
+}
+
+=head2 datetime_parse_via
+
+Sets or returns the class used for parsing datetimes.
+
+Can also take a hashref specifying L<DateTime::Format::Strptime> formats, in
+which case the parser class will be generated dynamically (and returned.)
+
+The format of the hashref entries is C<< type => strptime_format >> or
+C<< type => { format => strptime_format, parse => strptime_format } >>.
+
+For example:
+
+ {
+ datetime => '%Y-%m-%d %H:%M:%S.%3N',
+ smalldatetime => '%Y-%m-%d %H:%M:%S',
+ }
+
+or
+
+ {
+ datetime => {
+ parse => '%Y-%m-%dT%H:%M:%S.%3NZ',
+ format => '%Y-%m-%d %H:%M:%S.%3N',
+ }
+ }
+
+=cut
+
+sub datetime_parse_via {
+ my $self = shift;
+
+ return $self->datetime_parser_class if not @_;
+
+ my $via = shift;
+
+ if (not ref $via) {
+ $self->datetime_parser_class($via);
+ return $via;
+ }
+ elsif (ref $via ne 'HASH') {
+ $self->throw_exception(
+'datetime_parse_via argument must be class name or hashref of Strptime formats'
+ );
+ }
+
+ my $class = ref $self || $self;
+ my ($class_basename) = $class =~ /^@{[__PACKAGE__]}::(.*)\z/;
+
+ $class_basename ||= $class; # custom storage
+
+ my $parser_class = "DBIx::Class::DateTime::Format::${class_basename}";
+
+ while (my ($type, $format) = each %$via) {
+ $format = { parse => $format, format => $format } if not ref $format;
+
+ for my $action (qw/parse format/) {
+ my $method = "${parser_class}::${action}_$type";
+
+ {
+ no strict 'refs';
+
+ my $parser;
+ my $strptime_method;
+
+ *$method = subname $method => sub {
+ shift;
+ $parser ||= DateTime::Format::Strptime->new(
+ pattern => $format->{$action},
+ on_error => 'croak',
+ );
+ $strptime_method ||= $parser->can("${action}_datetime");
+ return $parser->$strptime_method(shift);
+ };
+ }
+ }
+ }
+
+ $self->datetime_strptime_formats($via);
+ $self->datetime_parser_class($parser_class);
+
+ return $parser_class;
+}
=head2 build_datetime_parser
sub build_datetime_parser {
my $self = shift;
- my $type = $self->datetime_parser_type(@_);
- return $type;
+
+ my $parser_class = $self->datetime_parse_via(@_);
+
+ if ($self->datetime_strptime_formats) {
+ require DateTime::Format::Strptime;
+ }
+
+ return $parser_class;
}
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::ADO::MS_Jet::Cursor');
+__PACKAGE__->datetime_parse_via({
+ datetime => '%m/%d/%Y %I:%M:%S %p',
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::ADO::MS_Jet - Support for MS Access over ADO
return @row;
}
-sub datetime_parser_type {
- 'DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format'
-}
-
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::ADO::MS_Jet::DateTime::Format;
-
-my $datetime_format = '%m/%d/%Y %I:%M:%S %p';
-my $datetime_parser;
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
return $guid;
});
+__PACKAGE__->datetime_parse_via({
+ datetime => '%m/%d/%Y %I:%M:%S %p',
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft
}
}
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format;
-
-my $datetime_format = '%m/%d/%Y %I:%M:%S %p';
-my $datetime_parser;
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
use Try::Tiny;
use namespace::clean;
-__PACKAGE__->datetime_parser_type('DateTime::Format::DB2');
+__PACKAGE__->datetime_parse_via('DateTime::Format::DB2');
__PACKAGE__->sql_quote_char ('"');
# lazy-default kind of thing
__PACKAGE__->sql_limit_dialect ('SkipFirst');
__PACKAGE__->sql_quote_char ('"');
-__PACKAGE__->datetime_parser_type (
- 'DBIx::Class::Storage::DBI::Informix::DateTime::Format'
-);
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S.%5N',
+ date => '%m/%d/%Y',
+});
__PACKAGE__->mk_group_accessors('simple' => '__last_insert_id');
$ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5";
}
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::Informix::DateTime::Format;
-
-my $timestamp_format = '%Y-%m-%d %H:%M:%S.%5N'; # %F %T
-my $date_format = '%m/%d/%Y';
-
-my ($timestamp_parser, $date_parser);
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->format_datetime(shift);
-}
-
-sub parse_date {
- shift;
- require DateTime::Format::Strptime;
- $date_parser ||= DateTime::Format::Strptime->new(
- pattern => $date_format,
- on_error => 'croak',
- );
- return $date_parser->parse_datetime(shift);
-}
-
-sub format_date {
- shift;
- require DateTime::Format::Strptime;
- $date_parser ||= DateTime::Format::Strptime->new(
- pattern => $date_format,
- on_error => 'croak',
- );
- return $date_parser->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
use Try::Tiny;
use namespace::clean;
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S.%4N',
+ date => '%Y-%m-%d',
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::InterBase - Driver for the Firebird RDBMS via
=cut
-__PACKAGE__->datetime_parser_type(
- 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format'
-);
-
sub _ping {
my $self = shift;
$self->_get_dbh->{ib_time_all} = 'ISO';
}
-
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::InterBase::DateTime::Format;
-
-my $timestamp_format = '%Y-%m-%d %H:%M:%S.%4N'; # %F %T
-my $date_format = '%Y-%m-%d';
-
-my ($timestamp_parser, $date_parser);
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->format_datetime(shift);
-}
-
-sub parse_date {
- shift;
- require DateTime::Format::Strptime;
- $date_parser ||= DateTime::Format::Strptime->new(
- pattern => $date_format,
- on_error => 'croak',
- );
- return $date_parser->parse_datetime(shift);
-}
-
-sub format_date {
- shift;
- require DateTime::Format::Strptime;
- $date_parser ||= DateTime::Format::Strptime->new(
- pattern => $date_format,
- on_error => 'croak',
- );
- return $date_parser->format_datetime(shift);
-}
-
1;
=head1 CAVEATS
__PACKAGE__->sql_quote_char([qw/[ ]/]);
-__PACKAGE__->datetime_parser_type (
- 'DBIx::Class::Storage::DBI::MSSQL::DateTime::Format'
-);
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S.%3N', # %F %T
+ smalldatetime => '%Y-%m-%d %H:%M:%S',
+});
__PACKAGE__->new_guid('NEWID()');
};
}
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::MSSQL::DateTime::Format;
-
-my $datetime_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
-my $smalldatetime_format = '%Y-%m-%d %H:%M:%S';
-
-my ($datetime_parser, $smalldatetime_parser);
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->format_datetime(shift);
-}
-
-sub parse_smalldatetime {
- shift;
- require DateTime::Format::Strptime;
- $smalldatetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $smalldatetime_format,
- on_error => 'croak',
- );
- return $smalldatetime_parser->parse_datetime(shift);
-}
-
-sub format_smalldatetime {
- shift;
- require DateTime::Format::Strptime;
- $smalldatetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $smalldatetime_format,
- on_error => 'croak',
- );
- return $smalldatetime_parser->format_datetime(shift);
-}
-
1;
=head1 NAME
__PACKAGE__->disable_sth_caching_for_image_insert_or_update(1);
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S', # %F %T, no fractional part
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC
return $self->next::method(@_);
}
-sub datetime_parser_type {
- 'DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format'
-}
-
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::ODBC::ACCESS::DateTime::Format;
-
-my $datetime_format = '%Y-%m-%d %H:%M:%S'; # %F %T, no fractional part
-my $datetime_parser;
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format,
- on_error => 'croak',
- );
- return $datetime_parser->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
use Try::Tiny;
use namespace::clean;
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S.%4N',
+ date => '%Y-%m-%d',
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::ODBC::Firebird - Driver for using the Firebird RDBMS
=cut
-__PACKAGE__->datetime_parser_type ('DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format');
-
# batch operations in DBD::ODBC 1.35 do not work with the official ODBC driver
sub _run_connection_actions {
my $self = shift;
};
}
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format;
-
-# inherit parse/format date
-our @ISA = 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format';
-
-my $timestamp_format = '%Y-%m-%d %H:%M:%S.%4N'; # %F %T
-my $timestamp_parser;
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $timestamp_parser ||= DateTime::Format::Strptime->new(
- pattern => $timestamp_format,
- on_error => 'croak',
- );
- return $timestamp_parser->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
__PACKAGE__->sql_limit_dialect ('RowNum');
__PACKAGE__->sql_quote_char ('"');
__PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::Oracle');
-__PACKAGE__->datetime_parser_type('DateTime::Format::Oracle');
+__PACKAGE__->datetime_parse_via('DateTime::Format::Oracle');
sub __cache_queries_with_max_lob_parts { 2 }
__PACKAGE__->sql_limit_dialect ('LimitOffset');
__PACKAGE__->sql_quote_char ('"');
-__PACKAGE__->datetime_parser_type ('DateTime::Format::Pg');
+__PACKAGE__->datetime_parse_via('DateTime::Format::Pg');
__PACKAGE__->_use_multicolumn_in (1);
sub _determine_supports_insert_returning {
deployment_statements
datetime_parser
datetime_parser_type
+ datetime_parser_class
+ datetime_strptime_formats
+ datetime_parse_via
build_datetime_parser
last_insert_id
insert
Based on code originated by:
- Norbert Csongrádi <bert@cpan.org>
- Peter Siklósi <einon@einon.hu>
+ Norbert Csongr?di <bert@cpan.org>
+ Peter Sikl?si <einon@einon.hu>
=head1 LICENSE
# default to the UUID decoding cursor, overridable by the user
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::SQLAnywhere::Cursor');
+__PACKAGE__->datetime_parse_via({
+ datetime => '%Y-%m-%d %H:%M:%S.%6N'
+});
+
=head1 NAME
DBIx::Class::Storage::DBI::SQLAnywhere - Driver for SQL Anywhere
return @row;
}
-# this sub stolen from MSSQL
-
-sub build_datetime_parser {
- my $self = shift;
- my $type = "DateTime::Format::Strptime";
- try {
- eval "require ${type}"
- }
- catch {
- $self->throw_exception("Couldn't load ${type}: $_");
- };
-
- return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
-}
-
=head2 connect_call_datetime_setup
Used as:
__PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite');
__PACKAGE__->sql_limit_dialect ('LimitOffset');
__PACKAGE__->sql_quote_char ('"');
-__PACKAGE__->datetime_parser_type ('DateTime::Format::SQLite');
+__PACKAGE__->datetime_parse_via ('DateTime::Format::SQLite');
=head1 NAME
__PACKAGE__->sql_limit_dialect ('RowCountOrGenericSubQ');
__PACKAGE__->sql_quote_char ([qw/[ ]/]);
-__PACKAGE__->datetime_parser_type(
- 'DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format'
-);
+
+__PACKAGE__->datetime_parse_via({
+ datetime => {
+ parse => '%Y-%m-%dT%H:%M:%S.%3NZ',
+ format => '%m/%d/%Y %H:%M:%S.%3N',
+ },
+});
__PACKAGE__->mk_group_accessors('simple' =>
qw/_identity _identity_method _blob_log_on_update _parent_storage
# of format. Not changing as a bugwards compat, though in reality
# the only piece that sees the results of $dt object formatting
# (as opposed to parsing) is the database itself, so theoretically
- # changing both this SET command and the formatter definition of
- # ::S::D::Sybase::ASE::DateTime::Format below should be safe and
- # transparent
+ # changing both this SET command and the formatter definition
+ # should be safe and transparent
$dbh->do('SET DATEFORMAT mdy');
}
$self->_dbh->do("ROLLBACK TRANSACTION $name");
}
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::Sybase::ASE::DateTime::Format;
-
-my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ';
-my $datetime_format_format = '%m/%d/%Y %H:%M:%S.%3N';
-
-my ($datetime_parser, $datetime_formatter);
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_parse_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_formatter ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format_format,
- on_error => 'croak',
- );
- return $datetime_formatter->format_datetime(shift);
-}
-
1;
=head1 Schema::Loader Support
DBIx::Class::Storage::DBI::MSSQL
/;
use mro 'c3';
-
use DBIx::Class::Carp;
+use namespace::clean;
+
+__PACKAGE__->datetime_parse_via({
+ datetime => {
+ parse => '%Y-%m-%dT%H:%M:%S.%3NZ',
+ format => '%Y-%m-%d %H:%M:%S.%3N',
+ },
+});
=head1 NAME
=cut
-__PACKAGE__->datetime_parser_type(
- 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format'
-);
-
sub _rebless {
my $self = shift;
my $dbh = $self->_get_dbh;
}
}
-
-package # hide from PAUSE
- DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format;
-
-my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ';
-my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
-
-my ($datetime_parser, $datetime_formatter);
-
-sub parse_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_parser ||= DateTime::Format::Strptime->new(
- pattern => $datetime_parse_format,
- on_error => 'croak',
- );
- return $datetime_parser->parse_datetime(shift);
-}
-
-sub format_datetime {
- shift;
- require DateTime::Format::Strptime;
- $datetime_formatter ||= DateTime::Format::Strptime->new(
- pattern => $datetime_format_format,
- on_error => 'croak',
- );
- return $datetime_formatter->format_datetime(shift);
-}
-
1;
=head1 AUTHOR
my $no_class = '_DBICTEST_NONEXISTENT_CLASS_';
my $schema = DBICTest->init_schema();
-$schema->storage->datetime_parser_type($no_class);
+$schema->storage->datetime_parse_via($no_class);
my $event = $schema->resultset('Event')->find(1);
unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt')
&& DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_ase');
+$ENV{DBIC_SYBASE_FREETDS_NOWARN} = 1;
+
my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
if (not ($dsn && $user)) {