More and More Moose Tests.

It carry on as if normal day here in the Moose-Pen.

The next little test I want to try out is this one;


$da->reset_conditions();
$da->add_condition(
{
left => {
expression => '*',
left => { name => 'id' },
right => { param => '3' }
},
right => { value => '12' },
operator => '<=',
}
);

$da->retrieve($dbh);
my $people = $user_db->people_data();
shift(@{$people});
splice(@{$people},3,9);
cmp_deeply( $da->result()->set, $people,
"Correct 3 users are selected with expression");


Simple enough give me all the rows in the people table where 'id * 3 <=12' so that should give me the first four users. I also have to remember that I deleted the user with id=1 way back on my first test hech the reason I shift that first row on the array before I do the slice;

I ran the test and I got


ok 2 - correct 3 users selected with expression
so not surprises there.

I wanted to get a little ambitious so I added this in next


shift(@{$people});

$da->add_condition(
{ condition => 'AND',
left => {
expression => '*',
left => { name => 'id' },
right => { param => '3' }
},
right => { value => '6' },
operator => '!=',
}
);
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $people,
"correct 2 users selected with two expressions");


which should just get met the last two rows that condition should exclude id=2 and I get;

ok 3 - correct 2 users selected with two expressions

Finally for today I want to see if the 'IF' or SQL 'case' statement is working, as I am not 100% sure it will work for ORACLE but here is the test I am going to try;

$da->reset_conditions();
$da->add_condition({
left => {ifs=>[{ left => { name => 'id', },
right => { value => '5' },
operator => '<=',
then=>{value=>'4 and under'}},
[{left => { name =>'id'},
right => { value => '5' },
operator => '>',
},
{ condition => 'and',
left => {name=>'id'},
right => { value => '8' },
operator => '<=',
then=>{value=>'5 to 8'}}
],
{ then=>{value=>'9 and Over'}},
],},
right => { value => '5 to 8' },
operator => '=',
condition => 'AND'
});
pop(@{$updated_people});
$da->retrieve($dbh);
cmp_deeply( $da->result()->set, $updated_people,
"correct 3 users selected with case statement");

I reset the conditions then add in a if/case where I split the data into three ''4 and under'', ' 5 to 8' and '9 and Over' and then I add in that I want only the ones that match '5 to 8'. I use the $updated_people taking the last one '9' off the list with the shift.

And the final result is


ok 1 - All 4 users retrieved correctly with function
ok 2 - correct 3 users selected with expression
ok 3 - correct 2 users selected with two expressions
ok 4 - correct 3 users selected with case statement
So no bugs today. Onto something else for tomorrow.

ontario1.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