For ODBC support, see L<DBIx::Class::Storage::DBI::ODBC::Firebird>.
-To turn on L<DBIx::Class::InflateColumn::DateTime> support, add:
-
- on_connect_call => 'datetime_setup'
-
-to your L<DBIx::Class::Storage::DBI/connect_info>.
+To turn on L<DBIx::Class::InflateColumn::DateTime> support, see
+L</connect_call_datetime_setup>.
=cut
The C<TIMESTAMP> data type supports up to 4 digits after the decimal point for
second precision. The full precision is used.
+The C<DATE> data type stores the date portion only, and it B<MUST> be declared
+with:
+
+ data_type => 'date'
+
+in your Result class.
+
+Timestamp columns can be declared with either C<datetime> or C<timestamp>.
+
You will need the L<DateTime::Format::Strptime> module for inflation to work.
For L<DBIx::Class::Storage::DBI::ODBC::Firebird>, this is a noop and sub-second
$self->_get_dbh->{ib_time_all} = 'ISO';
}
+sub datetime_parser_type {
+ 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format'
+}
-# from MSSQL
+package # hide from PAUSE
+ DBIx::Class::Storage::DBI::InterBase::DateTime::Format;
-sub build_datetime_parser {
- my $self = shift;
- my $type = "DateTime::Format::Strptime";
- eval "use ${type}";
- $self->throw_exception("Couldn't load ${type}: $@") if $@;
- return $type->new(
- pattern => '%Y-%m-%d %H:%M:%S.%4N', # %F %T
+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;
=cut
-# XXX seemingly no equivalent to ib_time_all in DBD::InterBase via ODBC
+# XXX seemingly no equivalent to ib_time_all from DBD::InterBase via ODBC
sub connect_call_datetime_setup { 1 }
-# from MSSQL
-
-sub build_datetime_parser {
- my $self = shift;
- my $type = "DateTime::Format::Strptime";
- eval "use ${type}";
- $self->throw_exception("Couldn't load ${type}: $@") if $@;
- return $type->new(
- pattern => '%Y-%m-%d %H:%M:%S', # %F %T
- on_error => 'croak',
- );
-}
-
# we don't need DBD::InterBase-specific initialization
sub _init { 1 }
# releasing savepoints doesn't work, but that shouldn't matter
sub _svp_release { 1 }
+sub datetime_parser_type {
+ 'DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format'
+}
+
+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'; # %F %T, no fractional part
+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 CAVEATS
This driver (unlike L<DBD::InterBase>) does not currently support reading or
writing C<TIMESTAMP> values with sub-second precision.
-=item *
-
-Releasing savepoints does not work, but you should still be able to safely use
-savepoints.
-
=back
=head1 AUTHOR
my $schema;
foreach my $conn_idx (0..$#info) {
- my ($dsn, $user, $pass) = @{ $info[$conn_idx] };
+ my ($dsn, $user, $pass) = @{ $info[$conn_idx] || [] };
next unless $dsn;
$schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+ quote_char => '"',
+ name_sep => '.',
on_connect_call => [ 'datetime_setup' ],
});
my $sg = Scope::Guard->new(\&cleanup);
- eval { $schema->storage->dbh->do("DROP TABLE event") };
- $schema->storage->dbh->do(<<"SQL");
- CREATE TABLE event (
- id INT PRIMARY KEY,
- created_on TIMESTAMP
+ eval { $schema->storage->dbh->do('DROP TABLE "event"') };
+ $schema->storage->dbh->do(<<'SQL');
+ CREATE TABLE "event" (
+ "id" INT PRIMARY KEY,
+ "starts_at" DATE,
+ "created_on" TIMESTAMP
)
SQL
- my $now = DateTime->now;
- $now->set_nanosecond(555600000);
+ my $rs = $schema->resultset('Event');
+
+ my $dt = DateTime->now;
+ $dt->set_nanosecond($dsn =~ /odbc/i ? 0 : 555600000);
+
+ my $date_only = DateTime->new(
+ year => $dt->year, month => $dt->month, day => $dt->day
+ );
+
my $row;
- ok( $row = $schema->resultset('Event')->create({
- id => 1,
- created_on => $now,
- }));
- ok( $row = $schema->resultset('Event')
- ->search({ id => 1 }, { select => ['created_on'] })
+ ok( $row = $rs->create({
+ id => 1,
+ starts_at => $date_only,
+ created_on => $dt,
+ }));
+ ok( $row = $rs->search({ id => 1 }, { select => [qw/starts_at created_on/] })
->first
);
- is $row->created_on, $now, 'DateTime roundtrip';
+ is $row->created_on, $dt, 'TIMESTAMP as DateTime roundtrip';
- if ($conn_idx == 0) { # skip for ODBC
- cmp_ok $row->created_on->nanosecond, '==', 555600000,
- 'fractional part of a second survived';
- }
+ cmp_ok $row->created_on->nanosecond, '==', $dt->nanosecond,
+ 'fractional part of a second survived' if 0+$dt->nanosecond;
+
+ is $row->starts_at, $date_only, 'DATE as DateTime roundtrip';
}
done_testing;
};
return unless $dbh;
- eval { $dbh->do("DROP TABLE $_") } for qw/event/;
+ eval { $dbh->do(qq{DROP TABLE "$_"}) } for qw/event/;
}
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
- starts_at => { data_type => 'datetime' },
+
+# this MUST be 'date' for the Firebird tests
+ starts_at => { data_type => 'date' },
+
created_on => { data_type => 'timestamp' },
varchar_date => { data_type => 'varchar', inflate_date => 1, size => 20, is_nullable => 1 },
varchar_datetime => { data_type => 'varchar', inflate_datetime => 1, size => 20, is_nullable => 1 },
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Sat Feb 6 08:01:11 2010
+-- Created on Thu Feb 11 07:23:33 2010
--
;
--
CREATE TABLE event (
id INTEGER PRIMARY KEY NOT NULL,
- starts_at datetime NOT NULL,
+ starts_at date NOT NULL,
created_on timestamp NOT NULL,
varchar_date varchar(20),
varchar_datetime varchar(20),