More Baby Moose
Well just another post-ette day here in the Moose-pen
Just another quick post-ette today as I want to quickly add in a feature to the results class that will help end uses with de-bugging.
Presently the results class look like thin when it is dumped
$VAR1 = bless( {
'is_error' => 0,
'DAD' => 'Database::Accessor::Driver::DBI',
'query' => 'UPDATE people SET people.first_name = ?, people.last_name = ? WHERE ( people.first_name = ? AND people.last_name = ? )',
'operation' => 'UPDATE'
}, 'Database::Accessor::Result' );
useful info but it would also be nice to see what params are being used and if they are in the correct order; So a quick attribute add into the Database::Accessor::Result class;
++ has params => (
++ is => 'rw',
++ isa => 'ArrayRef|Undef',
++ );
and all I have to do in the Driver::DBI is;
...
$result->query($sql);
++ $result->params([map({$_->value} @{$self->params} )]);
$self->da_warn('execute',"SQL=$sql")
if $self->da_warning()>=1;
…
and now the result cl;ass has all the params I passed in. Suitable for debugging or testing but not for framing, wraping fish or lining bird cages;
$VAR1 = bless( {
'params' => [
'Bill',
'Bloggings',
'test1',
'test2'
],
'is_error' => 0,
'DAD' => 'Database::Accessor::Driver::DBI',
'query' => 'UPDATE people SET people.first_name = ?, people.last_name = ? WHERE ( people.first_name = ? AND people.last_name = ? )',
'operation' => 'UPDATE'
}, 'Database::Accessor::Result' );
Now add in four more tests, always a good thing;
ok($da->result()->query() eq "INSERT INTO people ( people.first_name, people.last_name ) VALUES( ?, ? )","create SQL correct");
cmp_deeply(
$da->result()->params,
[qw(Bill Bloggings)],
"create params in correct order"
);
…
cmp_deeply(
$da->result()->params,
[qw(test1 test2)],
"retrieve params in correct order"
);
…
cmp_deeply(
$da->result()->params,
[qw(Bill Bloggings test1 test2)],
"update params in correct order"
);
…
cmp_deeply(
$da->result()->params,
[qw(test1 test2)],
"delete params in correct order"
);
and now I have an even dozen tests all in a row that are all passing.
Leave a comment