Skip Menu |

This queue is for tickets about the Class-DBI-FromForm CPAN distribution.

Report information
The Basics
Id: 15549
Status: open
Priority: 0/
Queue: Class-DBI-FromForm

People
Owner: Nobody in particular
Requestors: asuffield [...] suffields.me.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: create_from_form puts SQL nulls in unset fields
Assume you have a table where some of the fields have default values and the 'not null' constraint. Normally you can ignore them when you insert tuples - the server will fill them in with default values. Unfortunately create_from_form puts an undef into *every* field, even the ones which are not present in the form - these are treated by DBI as explicit null values, so the server rejects the transaction due to the constraint violation. This should be easy to fix - instead of calling $results->valid($col), call $results->valid in array context and iterate over the list. If the caller wanted an undef then they would have specified the field to Data::FormValidator and set the missing_optional_valid option, which populates the list of valid fields with undefs as needed.
Show quoted text
> This should be easy to fix - instead of calling $results->valid($col), > call $results->valid in array context and iterate over the list. If > the caller wanted an undef then they would have specified the field > to Data::FormValidator and set the missing_optional_valid option, > which populates the list of valid fields with undefs as needed.
And in fact the right behaviour appears to be that of update_from_form. I have this: foreach my $col ( $results->valid ) { if ( $them->find_column($col) ) { $cols->{$col} = $results->valid($col); } } And that seems to do the right thing.
From: sk8boardkid [...] gmail.com
Show quoted text
> > And in fact the right behaviour appears to be that of update_from_form. > I have this: > > foreach my $col ( $results->valid ) { > if ( $them->find_column($col) ) { > $cols->{$col} = $results->valid($col); > } > } > > And that seems to do the right thing.
We should not use the list that the browser sends as the complete list of fields. Here is my workaround for this: sub _run_create { my ( $me, $class, $results ) = @_; my $them = bless {}, $class; my $cols = {}; foreach my $col ( $them->columns('All') ) { my $resultColumn; if($results->isa('HTML::Widget::Result')) { $resultColumn = $results->param($col); } else { $resultColumn = $results->valid($col); } if (defined($resultColumn)) { #column has been specified $cols->{$col} = $resultColumn; } } return $class->create($cols); } Hope this helps.