[Bast-commits] r8548 - in DBIx-Class/0.08/branches/storage-interbase: lib/DBIx/Class lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/ODBC t/inflate

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Fri Feb 5 08:55:45 GMT 2010


Author: caelum
Date: 2010-02-05 08:55:43 +0000 (Fri, 05 Feb 2010)
New Revision: 8548

Added:
   DBIx-Class/0.08/branches/storage-interbase/t/inflate/datetime_firebird.t
Modified:
   DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/InterBase.pm
   DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm
Log:
fix up my Row code for non-pk autoincs, add pretty crappy DT inflation for Firebird

Modified: DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Row.pm	2010-02-05 07:59:04 UTC (rev 8547)
+++ DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Row.pm	2010-02-05 08:55:43 UTC (rev 8548)
@@ -352,19 +352,17 @@
 
   # get non-PK auto-incs
   {
+    my $rsrc = $self->result_source;
     my %pk;
-    @pk{ $self->primary_columns } = (); 
+    @pk{ $rsrc->primary_columns } = (); 
 
     my @non_pk_autoincs = grep {
       (not exists $pk{$_})
-      && $self->column_info($_)->{is_auto_increment}
-    } $self->columns;
+      && $rsrc->column_info($_)->{is_auto_increment}
+    } $rsrc->columns;
 
     if (@non_pk_autoincs) {
-      my @ids = $self->result_source->storage->last_insert_id(
-        $self->result_source,
-        @non_pk_autoincs
-      );
+      my @ids = $rsrc->storage->last_insert_id($rsrc, @non_pk_autoincs);
 
       if (@ids == @non_pk_autoincs) {
         $self->store_column($non_pk_autoincs[$_] => $ids[$_]) for 0 .. $#ids;

Modified: DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/InterBase.pm
===================================================================
--- DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/InterBase.pm	2010-02-05 07:59:04 UTC (rev 8547)
+++ DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/InterBase.pm	2010-02-05 08:55:43 UTC (rev 8548)
@@ -56,7 +56,7 @@
 
   my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
 
-  if ($op eq 'insert') {
+  if ($op eq 'insert' && $self->_fb_auto_incs) {
     local $@;
     my (@auto_incs) = eval {
       local $SIG{__WARN__} = sub {};
@@ -94,4 +94,29 @@
   return { limit_dialect => 'FirstSkip', %{$self->{_sql_maker_opts}||{}} };
 }
 
+sub datetime_parser_type { __PACKAGE__ }
+
+my ($parser, $formatter);
+
+sub parse_datetime {
+    shift;
+    require DateTime::Format::Strptime;
+    $parser ||= DateTime::Format::Strptime->new(
+        pattern => '%a %d %b %Y %r',
+# there should be a %Z (TZ) on the end, but it's ambiguous and not parsed
+        on_error => 'croak',
+    );
+    $parser->parse_datetime(shift);
+}
+
+sub format_datetime {
+    shift;
+    require DateTime::Format::Strptime;
+    $formatter ||= DateTime::Format::Strptime->new(
+        pattern => '%F %H:%M:%S.%4N',
+        on_error => 'croak',
+    );
+    $formatter->format_datetime(shift);
+}
+
 1;

Modified: DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm
===================================================================
--- DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm	2010-02-05 07:59:04 UTC (rev 8547)
+++ DBIx-Class/0.08/branches/storage-interbase/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm	2010-02-05 08:55:43 UTC (rev 8548)
@@ -22,6 +22,20 @@
   return $_[1];
 }
 
+sub datetime_parser_type { __PACKAGE__ }
+
+my $parser;
+
+sub parse_datetime {
+    shift;
+    require DateTime::Format::Strptime;
+    $parser ||= DateTime::Format::Strptime->new(
+        pattern => '%F %H:%M:%S',
+        on_error => 'croak',
+    );
+    $parser->parse_datetime(shift);
+}
+
 1;
 
 =head1 AUTHOR

Added: DBIx-Class/0.08/branches/storage-interbase/t/inflate/datetime_firebird.t
===================================================================
--- DBIx-Class/0.08/branches/storage-interbase/t/inflate/datetime_firebird.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/storage-interbase/t/inflate/datetime_firebird.t	2010-02-05 08:55:43 UTC (rev 8548)
@@ -0,0 +1,80 @@
+use strict;
+use warnings;  
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+use Scope::Guard ();
+
+# XXX we're only testing TIMESTAMP here
+
+my ($dsn, $user, $pass)    = @ENV{map { "DBICTEST_FIREBIRD_${_}" }      qw/DSN USER PASS/};
+my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_FIREBIRD_ODBC_${_}" } qw/DSN USER PASS/};
+
+if (not ($dsn || $dsn2)) {
+  plan skip_all => <<'EOF';
+Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN}
+_USER and _PASS to run this test'.
+Warning: This test drops and creates a table called 'event'";
+EOF
+} else {
+  eval "use DateTime; use DateTime::Format::Strptime;";
+  if ($@) {
+    plan skip_all => 'needs DateTime and DateTime::Format::Strptime for testing';
+  }
+}
+
+my @info = (
+  [ $dsn,  $user,  $pass  ],
+  [ $dsn2, $user2, $pass2 ],
+);
+
+my $schema;
+
+foreach my $info (@info) {
+  my ($dsn, $user, $pass) = @$info;
+
+  next unless $dsn;
+
+  $schema = DBICTest::Schema->clone;
+
+  $schema->connection($dsn, $user, $pass, {
+    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
+  )
+SQL
+  my $now = DateTime->now;
+  my $row;
+  ok( $row = $schema->resultset('Event')->create({
+        id => 1,
+        created_on => $now,
+      }));
+  ok( $row = $schema->resultset('Event')
+    ->search({ id => 1 }, { select => ['created_on'] })
+    ->first
+  );
+  is( $row->created_on, $now, 'DateTime roundtrip' );
+}
+
+done_testing;
+
+# clean up our mess
+sub cleanup {
+  my $dbh; 
+  eval {
+    $schema->storage->disconnect; # to avoid object FOO is in use errors
+    $dbh = $schema->storage->dbh;
+  };
+  return unless $dbh;
+
+  eval { $dbh->do("DROP TABLE $_") } for qw/event/;
+}




More information about the Bast-commits mailing list