[PATCH] population bug in create()?

[prev] [thread] [next] [Date index for 2004/10/19]

From: Tatsuhiko Miyagawa
Subject: [PATCH] population bug in create()?
Date: 08:24 on 19 Oct 2004
With newer DBD::SQLite, the newest Class::DBI::SQLite test gives me
following warnings:

  Use of uninitialized value in subroutine entry at
  /usr/local/share/perl/5.8.2/DBIx/ContextualFetch.pm line 51.

The test code goes like this.

  package Foo;
  # Foo has a column "id", "foo" and "bar"

  Foo->create({
      foo => $i,
      bar => 'bar'. $i
  });

It seems that Class::DBI's create() method automatically populates 
id => undef entry on $data hash before _insert_row(), thus
DBIx::ContextualFetch gives me "uninitialized value" warnings in its
execute(). (Earlier DBD::SQLite doesn't warn me about this. So I CC this
mail to Matt)

I've followed Class::DBI's code around and found that in _init() method,

519:   if (@primary_columns == grep defined, @{$data}{@primary_columns})

grep defined, @{$data}{qw(id)} automatically populates id => undef on
$data hashref. So here's a patch.

--- lib/Class/DBI.pm~ 2004-04-30 16:22:12.000000000 +0900
+++ lib/Class/DBI.pm 2004-10-19 17:23:02.000000000 +0900
@@ -516,7 +516,11 @@
  my $obj_key = "";

  my @primary_columns = $class->primary_columns;
- if (@primary_columns == grep defined, @{$data}{@primary_columns}) {
+ my $num = 0;
+ for my $pk (@primary_columns) {
+     $num++ if defined $data->{$pk};
+ }
+ if (@primary_columns == $num) {

   # create single unique key for this object
   $obj_key = join "|", $class, map { $_ . '=' . $data->{$_} }



        -- 
        Tatsuhiko Miyagawa <miyagawa@xxxxxxxx.xx>

[PATCH] population bug in create()?
Tatsuhiko Miyagawa 08:24 on 19 Oct 2004

Re: [PATCH] population bug in create()?
Tony Bowden 11:31 on 19 Oct 2004

Re: [PATCH] population bug in create()?
Tim Bunce 14:06 on 19 Oct 2004

Re: [PATCH] population bug in create()?
William McKee 13:26 on 20 Oct 2004

Re: [PATCH] population bug in create()?
Ricardo SIGNES 17:35 on 20 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52