Moose Stumbles a Little

Is why tinker with a good thing day here in the Moose-pen

Just carrying on with my extended or as I like to call it my practical test cases. I figure I can skip the rest of the simple where conditions as I have already used most of them in the previous test cases. To start I added a new test case '32_where_operators.t' with this test;


$da->add_condition( {
left => {
name => 'id',
view => 'people'
},
right => [ { value => 6 }, { value => 9 } ],
operator => 'BETWeeN',
},);
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $updated_people,
"All 4 users retrieved correctly with between");

and it passed;

ok 1 - All 4 users retrieved correctly with between

nice to know as that can be a tricky one. The next is Is Null with this test

$da->reset_conditions();
$da->add_condition(
{
left => {
name => 'id',
view => 'address'
},
operator => 'Is Null',
},
);
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $updated_people,
"All 4 users retrieved correctly with is null");
$da->reset_conditions();

The one point I will have to make a note on it that address.id has a field alias 'address_id' but it cannot be used in a where condition as that is just for selection.

The next is a check of the 'in' operator


$da->reset_conditions();
$da->add_condition(
{
left => {
name => 'id',
view => 'people'
},
operator => 'In',
right => [{value=>'6'},
{value=>'7'},
{value=>'8'},
{value=>'9'},]
},
);
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $updated_people,
"All 4 users retrieved with in ");

so far I am batting 100% with all three passing

ok 1 - All 4 users retrieved correctly with between
ok 2 - All 4 users retrieved correctly with is null
ok 3 - All 4 users retrieved with in

Now for the tricky one using another $da in a condition and my test looks like this

$da->reset_conditions();
use Xtest::DA::Address;
my $address = Xtest::DA::Address->new();
my $address_da = $address->da();
my $people = $user_db->people_data();
shift($people);
splice($people,4,9);
$da->add_condition(
{
left => {
name => 'id',
view => 'address'
},
operator => 'In',
right =>{value=>$address_da}
},
);

$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $people,
"All 4 users retrieved with in ");


In this one I get a new Database::Accessor '$address_da' for my address table and then I set up the $people array. The $address_da should return all the record in the Address table which should be 4 rows and I use that in my condition so lets see what I get;

Attempt to use retrieve with no_retrieve flag on! at GitHub\database-
accessor\lib/Database/Accessor.pm line 581.

ok forgot about that one lets turn that off but I cannot do that directly as that is a flag and as such is ro;

has retrieve_only => (
is => 'ro',
isa => 'Bool',
default => 0,
traits => ['MooseX::MetaDescription::Meta::Trait'],
description => { not_in_DAD => 1 }

);


so I have to fix that for now in the ' Xtest::DA::Address' file


{name=>'street'},
{name=>'postal_code'},],
-- no_retrieve=>1,
});
}

and now when I run it I get;

DBD::Oracle::db prepare failed: ORA-00913: too many values (

WHERE address.id in ( <*>SELECT address.id, address.city, address.time_zone_id

so what is going on here is I am selecting too many vars out of that $address_da, I should only be selecting the 'address.id'. I am missing something to tell my sub query to only select a sub set of rows.

Looking at Accessor.pm I do see I have an 'only_elements' option but I can only pass that down though one of the CRUD methods as an 'option' and I have no way to do that here. Will have to figure out some way to fix this.

Looks like I have a post for tomorrow.

Moose-Encounter-1.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations