App-Repository
view release on metacpan or search on metacpan
t/DBI-getset.t view on Meta::CPAN
is($age, 38, "get() 2 values (checking 2 of 2)");
ok($rep->set_row("test_person", 3, ["age", "state"], [7, "CA"]),"set_row() 2 values");
$row = $rep->get_row("test_person", 4, ["age", "gender"]);
($age, $gender) = @$row;
is($age, 3, "get_row() 2 values (checking 1 of 2)");
is($gender, "M", "get_row() 2 values (checking 2 of 2)");
ok($rep->set_row("test_person", {first_name=>'paul'}, ["age", "state"], [5, "CA"]),"set_row() 2 values w/ %crit");
$row = $rep->get_row("test_person", {first_name=>'paul'}, ["age", "state","person_id"]);
($age, $state, $person_id) = @$row;
is($age, 5, "get_row() 3 values w/ %crit (checking 1 of 3)");
is($state, "CA", "get_row() 3 values w/ %crit (checking 2 of 3)");
is($person_id, 4, "get_row() 3 values w/ %crit (checking 3 of 3)");
ok($rep->set_row("test_person", {first_name=>'paul'}, ["age", "state"], {age=>6, state=>"GA", person_id=>99}),
"set_row() 2 values w/ %crit and values in hash");
$row = $rep->get_row("test_person", {first_name=>'paul'}, ["age", "state","person_id"]);
($age, $state, $person_id) = @$row;
is($age, 6, "get_row() 3 values w/ %crit (checking 1 of 3)");
is($state, "GA", "get_row() 3 values w/ %crit (checking 2 of 3)");
is($person_id, 4, "get_row() 3 values w/ %crit (checking 3 of 3)");
my ($hashes, $hash);
ok($rep->set("test_person", 1, {person_id => 1, age => 41}), "set(table,\$key,\%hash)");
$hash = $rep->get_hash("test_person", 1);
is($hash->{person_id}, 1, "get_hash(1) person_id");
is($hash->{age}, 41, "get_hash(1) age");
is($hash->{first_name}, "steve", "get_hash(1) first_name");
is($hash->{gender}, "M", "get_hash(1) gender");
is($hash->{state}, "GA", "get_hash(1) state");
ok($rep->set("test_person", {first_name => "steve"}, {person_id => 1, age => 41}), "set(table,\$params,\%hash)");
ok($rep->set("test_person", {person_id => 8, age => 37, first_name => "nick", gender => "M", state => undef},
undef, undef, {create=>1}),
"set(table,\$params,\%hash) : insert");
is($rep->set("test_person", {gender => "F", age => 41}), 0,
"set(table,\$params,\%hash) : fails if key not supplied");
$hashes = $rep->get_hashes("test_person");
is($#$hashes, 7, "get_hashes(test_person) returned 8 rows");
$hashes = $rep->get_hashes("test_person",{},undef,{order_by=>["person_id"]});
is($#$hashes, 7, "get_hashes(test_person,{},undef,{order_by}) returned 8 rows");
#foreach $hash (@$hashes) {
# print "HASH: {", join("|", %$hash), "}\n";
#}
$hash = $hashes->[0];
is($hash->{person_id}, 1, "get_hashes()->[0] person_id");
is($hash->{age}, 41, "get_hashes()->[0] age");
is($hash->{first_name}, "steve", "get_hashes()->[0] first_name");
is($hash->{gender}, "M", "get_hashes()->[0] gender");
is($hash->{state}, "GA", "get_hashes()->[0] state");
$hash = $hashes->[$#$hashes];
is($hash->{person_id}, 8, "get_hashes()->[n] person_id");
is($hash->{age}, 37, "get_hashes()->[n] age");
is($hash->{first_name}, "nick", "get_hashes()->[n] first_name");
is($hash->{gender}, "M", "get_hashes()->[n] gender");
is($hash->{state}, undef, "get_hashes()->[n] state");
eval {
$nrows = $rep->set("test_person", undef, "gender", "M");
print "updated $nrows rows. ?!? shouldn't ever get here!\n";
};
ok($@, "set() with undef params");
####################################################################
# Exercise the special implied where conditions
####################################################################
#my $rows2 = $rep->get_rows("test_person", {}, ["person_id","age","first_name","gender","state"]);
#foreach my $row (@$rows2) {
# print "ROW: [", join("|", map { defined $_ ? $_ : "undef" } @$row), "]\n";
#}
$hashes = $rep->get_hashes("test_person", {first_name => "!steve,joe,nick"});
is($#$hashes+1, 6, "get_hashes(!steve,joe,nick)");
$hashes = $rep->get_hashes("test_person", {first_name => "steve,joe,nick"});
is($#$hashes+1, 2, "get_hashes(steve,joe,nick)");
$hashes = $rep->get_hashes("test_person", {first_name => "=steve,joe,nick"});
is($#$hashes+1, 2, "get_hashes(=steve,joe,nick)");
$hashes = $rep->get_hashes("test_person", {first_name => "==steve,joe,nick"});
is($#$hashes+1, 0, "get_hashes(==steve,joe,nick)");
$hashes = $rep->get_hashes("test_person", {state => "GA"});
is($#$hashes+1, 5, "get_hashes(GA)");
$hashes = $rep->get_hashes("test_person", {state => "GA,NULL"});
is($#$hashes+1, 6, "get_hashes(GA,NULL)");
$hashes = $rep->get_hashes("test_person", {state => "!GA,NULL"});
is($#$hashes+1, 2, "get_hashes(!GA,NULL)");
$hashes = $rep->get_hashes("test_person", {state => "GA,CA"});
is($#$hashes+1, 6, "get_hashes(GA,CA)");
$hashes = $rep->get_hashes("test_person", {state => "!GA,CA"});
is($#$hashes+1, 1, "get_hashes(!GA,CA)");
$hashes = $rep->get_hashes("test_person", {"state.not_in" => ["GA","CA"]});
is($#$hashes+1, 1, "get_hashes not_in [GA,CA]");
$hashes = $rep->get_hashes("test_person", {"state.not_in" => "GA,CA"});
is($#$hashes+1, 1, "get_hashes not_in (GA,CA)");
$hashes = $rep->get_hashes("test_person", {"state.in" => "!GA,CA"});
is($#$hashes+1, 1, "get_hashes in (!GA,CA)");
$hashes = $rep->get_hashes("test_person", {"state.eq" => "!GA,CA"});
is($#$hashes+1, 0, "get_hashes eq (!GA,CA)");
$hashes = $rep->get_hashes("test_person", {"state.contains" => "A"});
is($#$hashes+1, 6, "get_hashes contains (A)");
$hashes = $rep->get_hashes("test_person", {"state.not_contains" => "A"});
is($#$hashes+1, 1, "get_hashes not_contains (A)");
$hashes = $rep->get_hashes("test_person", {"state.matches" => "?A"});
is($#$hashes+1, 6, "get_hashes matches (?A)");
$hashes = $rep->get_hashes("test_person", {"state" => "?A"});
is($#$hashes+1, 6, "get_hashes (?A)");
$hashes = $rep->get_hashes("test_person", {"state.not_matches" => "?A"});
is($#$hashes+1, 1, "get_hashes not_matches (?A)");
#print $rep->{sql};
#####################################################################
# dbexpr with substitutions
#####################################################################
my ($years_older);
$years_older = $rep->get("test_person", {person_id => 1}, "years_older");
is($years_older, 41, "get() years_older [$years_older] base_age is undef");
$years_older = $rep->get("test_person", {person_id => 1, base_age => 20}, "years_older");
is($years_older, 21, "get() years_older [$years_older] base_age = 20");
( run in 1.222 second using v1.01-cache-2.11-cpan-39bf76dae61 )