Re: [CDBI] Odd behaviour under RedHat vs Debian

Mike Whitaker <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
On 17 Nov 2006, at 10:48, Mike Whitaker wrote:

> I have a chunk of code which works fine under Debian etch (CDBI  
> 3.0.14, DBI 1.52, CDBI::Loader 0.33, CDBI::L::mysql 0.30,  
> DBIx::ContextualFetch 1.03), and fails under Redhat (CDBI 3.0.16,  
> DBI 1.40 OR 1.53, CDBI::Loader 0.32 being the only differences)...
>
> Basically, it's screwing up an add_to_xxx on a has_many, viz:
>
> Can't insert new MCD::SQL::PointAward: DBD::mysql::st execute  
> failed: You have an error in your SQL syntax; check the manual that  
> corresponds to your MySQL server version for the right syntax to  
> use near '1210220 (table_id, reason, points, player_id, table_name)
> VALUES ('1210220', 'So' at line 1 [for Statement "INSERT INTO  
> 1210220 (table_id, reason, points, player_id, table_name)
> VALUES (?, ?, ?, ?, ?)
> " with ParamValues: 4='uid_solve', 1='Solved card 40', 3='46151',  
> 0='1210220', 2=10
>
> Note that the first param value (1210220) seems to have got somehow  
> inserted as the TABLE name in the generated SQL.

Well. I found it. If someone can explain why it works under 3.0.14  
and fails under 3.0.16, that would be shiny:

Oversimplifying a bit: deep down in the bowels of Class::DBI, it  
takes a template piece of SQL that looks like this:
    INSERT INTO __TABLE__ (%s) VALUES (%s)
and runs a quick substitution over it that replaces
    __TABLE__
with $class->table.

I've been overriding accessor names with:

sub accessor_name
{
     my ($class, $column) = @_;
     $column =~ s/_id$//;
     return $column;
}

which basically strips trailing '_id' off any accessor name, so that  
for example $class->player will work just as well as $class->player_id

Which is all fine and shiny. Except that the table referenced by  
MCD::SQL::PointAward has a column called table_id...
-- 
Mike Whitaker - [email protected]
Tel: +44 (0) 20 7501 1920 - Mob: +44 (0) 7971 977375
Skype: FleetfootMike; AIM: FleetfootMike
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.