Calling a set_sql created method after a create() has NULL __IDENTIFIER__.

[prev] [thread] [next] [Date index for 2004/06/21]

From: Rob Andrews
Subject: Calling a set_sql created method after a create() has NULL __IDENTIFIER__.
Date: 19:31 on 21 Jun 2004
I have some peculiarity that I don't seem to be able to overcome.
(Firstly, I'm using v0.96, and MySQL 4.0.20)

Imagine I have the table 'test', with the following details:

foo int(11) not null auto_increment
bar datetime
baz text

I have the following database class:

package Test;

use base 'TestDB';

Test->table('test');
Test->columns(All => qw/foo bar baz/);
Test->set_sql('refresh_bar' => qq{
  UPDATE __TABLE__
     SET bar=NOW()
   WHERE __IDENTIFIER__
});

And am calling the following code:

my $test=Test->create({ baz => 'test data goes here' });
warn $test->foo;
$test->sql_refresh_timestamp->execute;

Now, after executing, the create() call comes through, as expected:
040621 20:26:33      29 Connect     test@localhost on testdb
                     29 Query       INSERT INTO test (baz, foo)
VALUES ('test data goes here', NULL)

And, as expected, the 'warn $test->foo' line returns the auto_increment
value as expected.

What I wasn't expecting was the '$test->sql_refresh_timestamp->execute'
to produce the following SQL:

                     29 Query       UPDATE test
           SET bar=NOW()
         WHERE foo=NULL

This seems to indicate that whilst the auto_increment value made it back
into the object, it didn't reach the __IDENTIFIER__ clause.

Am I doing something wrong or is this a bug?

        -- 
        rob                               <e> rob@xxxxxx.xxx.xx <pgp> 0x8bb5c71e
                "This Basil. This Basil's hand. This smack on the head."

Calling a set_sql created method after a create() has NULL __IDENTIFIER__.
Rob Andrews 19:31 on 21 Jun 2004

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