[Maypole] Maypole::Base::CDBI will not create a record with a manually supplied primary key

Matt Adams matt.adams@morcor.com
Sat, 09 Oct 2004 13:39:45 -0400


Okay: here's a good one for you:

I'm using MySQL and have some tables where I can't use auto_increment on the 
primary keys (for some weird reason I won't bother to explain) and want to 
control the sequence of said primary keys manually.

Sounds simple enough.

Imagine I have the following table:

book
=============
id (INT)
name (TEXT)
author (TEXT)

Which gives me Library::Book to work with.

I've overridden do_edit to read:

sub do_edit :Exported {
	my ($self, $r) = @_;

         $r->{params}{$self->primary_columns} = &some_value;

	....
	# the rest of this is the same as the original do_edit
	....
}

I then perform do_edit on Library::Book and pass it $r->{params} which consists 
of values for $r->{params}{name} and $r->{params}{author}.

Unfortunately somewhere in the bowels of Maypole (perhaps in CGI::Untaint, 
CDBI::FromCGI or DBIx::ContextualFetch) the value that I set in do_edit for the 
primary key is lost and I receive the following error:

Can't insert new Library::Book: DBD::mysql::st execute failed:
Column 'id' cannot be null [for Statement "INSERT INTO book (name, author, id) 
VALUES (?, ?, ?)"]
at
/usr/local/lib/perl5/site_perl/5.8.5/DBIx/ContextualFetch.pm line 51, <GEN2> 
line 7. at /usr/local/lib/perl5/site_perl/5.8.5/Class/DBI/FromCGI.pm line 246

Does anyone have any idea where in the Maypole framework I can force it to 
accept a manually created primary key?


Thank you,

Matt
-- 
Matt Adams <matt.adams@morcor.com>
Development Specialist
Morcor Solutions Inc. <http://www.morcor.com/>
(613) 354-2912 x228

GnuPG public key at <http://staff.morcor.com/~madams/>
Key fingerprint: BED5 B4F7 CCF5 D7B5 7C56  0505 9A0A A0FB C937 5975