Merge 'storage-interbase' into 'trunk'
Rafael Kitover [Sun, 7 Mar 2010 10:55:06 +0000 (10:55 +0000)]
r23004@hlagh (orig r8530):  moritz | 2010-02-04 07:41:29 -0500
create branch for Storage::DBI::InterBase

r23005@hlagh (orig r8531):  moritz | 2010-02-04 07:44:02 -0500
primitive, non-working and very specific Storage::DBI::InterBase
r23006@hlagh (orig r8532):  moritz | 2010-02-04 08:00:05 -0500
[Storage::DBI::InterBase] remove cruft copied from MSSQL
r23008@hlagh (orig r8534):  moritz | 2010-02-04 08:34:22 -0500
[Storage::DBI::InterBase] remove more cruft
r23014@hlagh (orig r8540):  caelum | 2010-02-04 10:08:27 -0500
test file for firebird, not passing yet
r23015@hlagh (orig r8541):  caelum | 2010-02-04 11:24:51 -0500
Firebird: fix test cleanup, add ODBC wrapper
r23016@hlagh (orig r8542):  caelum | 2010-02-04 13:18:48 -0500
limit and better autoinc for Firebird
r23018@hlagh (orig r8544):  caelum | 2010-02-04 14:19:51 -0500
override quoting columns for RETURNING in Firebird ODBC (where it doesn't work) and generate a RETURNING clause only when necessary
r23022@hlagh (orig r8548):  caelum | 2010-02-05 03:55:43 -0500
fix up my Row code for non-pk autoincs, add pretty crappy DT inflation for Firebird
r23023@hlagh (orig r8549):  caelum | 2010-02-05 04:26:03 -0500
rename a couple of variables
r23024@hlagh (orig r8550):  caelum | 2010-02-05 04:46:31 -0500
check for both NULL and null, rename _fb_auto_incs to _auto_incs
r23025@hlagh (orig r8551):  caelum | 2010-02-05 05:07:14 -0500
support autoinc PKs without is_auto_increment set
r23047@hlagh (orig r8570):  caelum | 2010-02-06 07:35:31 -0500
move Firebird ODBC override for RETURNING to a SQLAHacks class
r23048@hlagh (orig r8571):  caelum | 2010-02-06 08:06:44 -0500
Firebird: add POD, fix BLOB tests
r23085@hlagh (orig r8588):  caelum | 2010-02-08 08:26:41 -0500
better DT inflation for Firebird and _ping
r23087@hlagh (orig r8590):  moritz | 2010-02-08 08:32:26 -0500
test ->update({...}) for firebird
r23088@hlagh (orig r8591):  caelum | 2010-02-08 08:33:09 -0500
test update
r23089@hlagh (orig r8592):  moritz | 2010-02-08 08:43:50 -0500
use quoting in firebird tests
r23115@hlagh (orig r8597):  caelum | 2010-02-10 07:05:21 -0500
default to sql dialect 3 unless overridden
r23116@hlagh (orig r8598):  caelum | 2010-02-10 07:42:17 -0500
turn on ib_softcommit, savepoint tests now pass for DBD::InterBase
r23123@hlagh (orig r8605):  caelum | 2010-02-10 17:38:24 -0500
fix savepoints for Firebird ODBC
r23170@hlagh (orig r8652):  caelum | 2010-02-11 07:27:19 -0500
support the DATE data type for Firebird
r23186@hlagh (orig r8668):  caelum | 2010-02-12 14:43:20 -0500
special bind_param_array move to make DBD::InterBase happy (RT#54561)
r23213@hlagh (orig r8695):  caelum | 2010-02-13 15:15:46 -0500
fix fail in t/72pg.t related to new autoinc retrieval code in ::Row
r23214@hlagh (orig r8696):  caelum | 2010-02-13 15:18:27 -0500
fix multiple cursor test
r23246@hlagh (orig r8728):  caelum | 2010-02-16 09:47:43 -0500
POD fix
r23358@hlagh (orig r8758):  caelum | 2010-02-19 06:25:27 -0500
s/primary_columns/_pri_cols/ for Firebird
r23420@hlagh (orig r8800):  rkitover | 2010-02-22 19:33:13 -0500
don't use ib_softcommit by default
r23496@hlagh (orig r8841):  rkitover | 2010-03-01 04:22:19 -0500
update POD
r23545@hlagh (orig r8855):  rkitover | 2010-03-03 12:59:41 -0500
destroy cached statements in $storage->disconnect too
r23582@hlagh (orig r8892):  rkitover | 2010-03-05 18:06:33 -0500
auto_nextval support for Firebird
r23598@hlagh (orig r8908):  rkitover | 2010-03-06 11:48:41 -0500
remove that code for non-pk autoincs from Row, move to ::DBI::InterBase
r23599@hlagh (orig r8909):  rkitover | 2010-03-06 12:00:15 -0500
remove BindType2 test class
r23601@hlagh (orig r8911):  rkitover | 2010-03-06 12:12:55 -0500
cache autoinc sequence in column_info
r23609@hlagh (orig r8919):  rkitover | 2010-03-06 18:05:24 -0500
remove connect_info from maint/gen-schema.pl
r23610@hlagh (orig r8920):  rkitover | 2010-03-06 18:15:13 -0500
don't die on insert in firebird with no pk
r23612@hlagh (orig r8922):  ribasushi | 2010-03-06 19:18:46 -0500
What I really meant
r23619@hlagh (orig r8929):  rkitover | 2010-03-07 05:46:04 -0500
fix RETURNING for empty INSERT

Changes
lib/DBIx/Class/Row.pm
t/60core.t
t/admin/03data.t
t/lib/DBICTest/Schema/Employee.pm
t/lib/DBICTest/Schema/Encoded.pm
t/lib/sqlite.sql

diff --git a/Changes b/Changes
index 536a54b..08728f8 100644 (file)
--- a/Changes
+++ b/Changes
@@ -6,6 +6,8 @@ Revision history for DBIx::Class
         - Add req_group_list to Opt::Deps (RT#55211)
         - Cascading delete/update are now wrapped in a transaction
           for atomicity
+        - Fix multiple deficiencies when using MultiCreate with
+          data-encoder components (e.g. ::EncodedColumn)
         - Fix regression where SQL files with comments were not
           handled properly by ::Schema::Versioned.
         - Fix regression on not properly throwing when $obj->relationship
index 554d346..2777114 100644 (file)
@@ -105,26 +105,40 @@ with NULL as the default, and save yourself a SELECT.
 
 sub __new_related_find_or_new_helper {
   my ($self, $relname, $data) = @_;
-  if ($self->__their_pk_needs_us($relname, $data)) {
+
+  # create a mock-object so all new/set_column component overrides will run:
+  my $rel_rs = $self->result_source
+                    ->related_source($relname)
+                    ->resultset;
+  my $new_rel_obj = $rel_rs->new_result($data);
+  my $proc_data = { $new_rel_obj->get_columns };
+
+  if ($self->__their_pk_needs_us($relname)) {
     MULTICREATE_DEBUG and warn "MC $self constructing $relname via new_result";
-    return $self->result_source
-                ->related_source($relname)
-                ->resultset
-                ->new_result($data);
+    return $new_rel_obj;
+  }
+  elsif ($self->result_source->_pk_depends_on($relname, $proc_data )) {
+    if (! keys %$proc_data) {
+      # there is nothing to search for - blind create
+      MULTICREATE_DEBUG and warn "MC $self constructing default-insert $relname";
+    }
+    else {
+      MULTICREATE_DEBUG and warn "MC $self constructing $relname via find_or_new";
+      # this is not *really* find or new, as we don't want to double-new the
+      # data (thus potentially double encoding or whatever)
+      my $exists = $rel_rs->find ($proc_data);
+      return $exists if $exists;
+    }
+    return $new_rel_obj;
   }
-  if ($self->result_source->_pk_depends_on($relname, $data)) {
-    MULTICREATE_DEBUG and warn "MC $self constructing $relname via find_or_new";
-    return $self->result_source
-                ->related_source($relname)
-                ->resultset
-                ->find_or_new($data);
+  else {
+    my $us = $self->source_name;
+    $self->throw_exception ("'$us' neither depends nor is depended on by '$relname', something is wrong...");
   }
-  MULTICREATE_DEBUG and warn "MC $self constructing $relname via find_or_new_related";
-  return $self->find_or_new_related($relname, $data);
 }
 
 sub __their_pk_needs_us { # this should maybe be in resultsource.
-  my ($self, $relname, $data) = @_;
+  my ($self, $relname) = @_;
   my $source = $self->result_source;
   my $reverse = $source->reverse_relationship_info($relname);
   my $rel_source = $source->related_source($relname);
@@ -301,12 +315,20 @@ sub insert {
       MULTICREATE_DEBUG and warn "MC $self pre-reconstructing $relname $rel_obj\n";
 
       my $them = { %{$rel_obj->{_relationship_data} || {} }, $rel_obj->get_inflated_columns };
-      my $re = $self->result_source
-                    ->related_source($relname)
-                    ->resultset
-                    ->find_or_create($them);
+      my $existing;
+
+      # if there are no keys - nothing to search for
+      if (keys %$them and $existing = $self->result_source
+                                           ->related_source($relname)
+                                           ->resultset
+                                           ->find($them)
+      ) {
+        %{$rel_obj} = %{$existing};
+      }
+      else {
+        $rel_obj->insert;
+      }
 
-      %{$rel_obj} = %{$re};
       $self->{_rel_in_storage}{$relname} = 1;
     }
 
@@ -366,7 +388,7 @@ sub insert {
       foreach my $obj (@cands) {
         $obj->set_from_related($_, $self) for keys %$reverse;
         my $them = { %{$obj->{_relationship_data} || {} }, $obj->get_inflated_columns };
-        if ($self->__their_pk_needs_us($relname, $them)) {
+        if ($self->__their_pk_needs_us($relname)) {
           if (exists $self->{_ignore_at_insert}{$relname}) {
             MULTICREATE_DEBUG and warn "MC $self skipping post-insert on $relname";
           } else {
index 03fe3b6..69d99ed 100644 (file)
@@ -419,6 +419,47 @@ SKIP: {
   is($en_row->encoded, 'amliw', 'insert does not encode again');
 }
 
+#make sure multicreate encoding still works
+{
+  my $empl_rs = $schema->resultset('Employee');
+
+  my $empl = $empl_rs->create ({
+    name => 'Secret holder',
+    secretkey => {
+      encoded => 'CAN HAZ',
+    },
+  });
+  is($empl->secretkey->encoded, 'ZAH NAC', 'correctly encoding on multicreate');
+
+  my $empl2 = $empl_rs->create ({
+    name => 'Same secret holder',
+    secretkey => {
+      encoded => 'CAN HAZ',
+    },
+  });
+  is($empl2->secretkey->encoded, 'ZAH NAC', 'correctly encoding on preexisting multicreate');
+
+  $empl_rs->create ({
+    name => 'cat1',
+    secretkey => {
+      encoded => 'CHEEZBURGER',
+      keyholders => [
+        {
+          name => 'cat2',
+        },
+        {
+          name => 'cat3',
+        },
+      ],
+    },
+  });
+
+  is($empl_rs->find({name => 'cat1'})->secretkey->encoded, 'REGRUBZEEHC', 'correct secret in database for empl1');
+  is($empl_rs->find({name => 'cat2'})->secretkey->encoded, 'REGRUBZEEHC', 'correct secret in database for empl2');
+  is($empl_rs->find({name => 'cat3'})->secretkey->encoded, 'REGRUBZEEHC', 'correct secret in database for empl3');
+
+}
+
 # make sure we got rid of the compat shims
 SKIP: {
     skip "Remove in 0.082", 3 if $DBIx::Class::VERSION < 0.082;
index 1fe59b7..884b120 100644 (file)
@@ -48,8 +48,8 @@ use_ok 'DBIx::Class::Admin';
 
   my $expected_data = [ 
     [$employee->result_source->columns() ],
-    [1,1,undef,undef,undef,'Trout'],
-    [2,2,undef,undef,undef,'Aran']
+    [1,1,undef,undef,undef,'Trout',undef],
+    [2,2,undef,undef,undef,'Aran',undef]
   ];
   my $data;
   lives_ok { $data = $admin->select('Employee')} 'can retrive data from database';
index 30c2bca..35f6075 100644 (file)
@@ -32,6 +32,10 @@ __PACKAGE__->add_columns(
         size      => 100,
         is_nullable => 1,
     },
+    encoded => {
+        data_type => 'integer',
+        is_nullable => 1,
+    },
 );
 
 __PACKAGE__->set_primary_key('employee_id');
@@ -40,4 +44,8 @@ __PACKAGE__->position_column('position');
 # Do not add unique constraints here - different groups are used throughout
 # the ordered tests
 
+__PACKAGE__->belongs_to (secretkey => 'DBICTest::Schema::Encoded', 'encoded', {
+  join_type => 'left'
+});
+
 1;
index 7fd77dc..234846d 100644 (file)
@@ -21,6 +21,8 @@ __PACKAGE__->add_columns(
 
 __PACKAGE__->set_primary_key('id');
 
+__PACKAGE__->has_many (keyholders => 'DBICTest::Schema::Employee', 'encoded');
+
 sub set_column {
   my ($self, $col, $value) = @_;
   if( $col eq 'encoded' ){
index e521a15..26c06f4 100644 (file)
@@ -35,18 +35,6 @@ CREATE TABLE collection (
 );
 
 --
--- Table: employee
---
-CREATE TABLE employee (
-  employee_id INTEGER PRIMARY KEY NOT NULL,
-  position integer NOT NULL,
-  group_id integer,
-  group_id_2 integer,
-  group_id_3 integer,
-  name varchar(100)
-);
-
---
 -- Table: encoded
 --
 CREATE TABLE encoded (
@@ -253,6 +241,21 @@ CREATE TABLE books (
 CREATE INDEX books_idx_owner ON books (owner);
 
 --
+-- Table: employee
+--
+CREATE TABLE employee (
+  employee_id INTEGER PRIMARY KEY NOT NULL,
+  position integer NOT NULL,
+  group_id integer,
+  group_id_2 integer,
+  group_id_3 integer,
+  name varchar(100),
+  encoded integer
+);
+
+CREATE INDEX employee_idx_encoded ON employee (encoded);
+
+--
 -- Table: forceforeign
 --
 CREATE TABLE forceforeign (
@@ -445,4 +448,4 @@ CREATE INDEX fourkeys_to_twokeys_idx_t_artist_t_cd ON fourkeys_to_twokeys (t_art
 -- View: year2000cds
 --
 CREATE VIEW year2000cds AS
-    SELECT cdid, artist, title, year, genreid, single_track FROM cd WHERE year = "2000"
\ No newline at end of file
+    SELECT cdid, artist, title, year, genreid, single_track FROM cd WHERE year = "2000"