cvsuser 05/11/25 08:35:03
Modified: App-Repository/lib/App Repository.pm
App-Repository/lib/App/Repository DBI.pm
App-Repository/t DBI-compress.t DBI-getset.t
Log:
protect against undef params
Revision Changes Path
1.26 +18 -8 p5ee/App-Repository/lib/App/Repository.pm
Index: Repository.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Repository.pm 21 Oct 2005 15:32:13 -0000 1.25
+++ Repository.pm 25 Nov 2005 16:35:02 -0000 1.26
@@ -496,6 +496,7 @@
sub get {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $options) = @_;
+ die "get(): params undefined" if (!defined $params);
my ($row, $wantarray);
if (ref($cols) eq "ARRAY") {
$wantarray = 1;
@@ -549,6 +550,7 @@
sub set {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $col, $value, $options) = @_;
+ die "set(): params undefined" if (!defined $params);
$self->_load_table_metadata($table) if (! defined
$self->{table}{$table}{loaded});
my ($nrows);
if ($col && ref($col) eq "") {
@@ -590,6 +592,7 @@
sub get_row {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $options) = @_;
+ die "get_row(): params undefined" if (!defined $params);
my ($row);
my $repname = $self->{table}{$table}{repository};
@@ -679,6 +682,7 @@
sub set_row {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $row, $options) = @_;
+ die "set_row(): params undefined" if (!defined $params);
$self->_load_table_metadata($table) if (! defined
$self->{table}{$table}{loaded});
my ($nrows, $key_defined);
@@ -945,6 +949,7 @@
sub set_rows {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $rows, $options) = @_;
+ die "set_rows(): params undefined" if (!defined $params);
my ($nrows);
my $repname = $self->{table}{$table}{repository};
my $realtable = $self->{table}{$table}{table} || $table;
@@ -994,6 +999,7 @@
sub get_hash {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $options) = @_;
+ die "get_hash(): params undefined" if (!defined $params);
$cols = [] if (!$cols);
my $row = $self->get_row($table, $params, $cols, $options);
my ($hash, $col, $value);
@@ -1090,6 +1096,7 @@
sub get_object {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $options) = @_;
+ die "get_object(): params undefined" if (!defined $params);
my $tabledef = $self->{table}{$table};
my $class = $tabledef->{class} || "App::RepositoryObject";
App->use($class);
@@ -1309,6 +1316,7 @@
sub set_hash {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $values, $options) = @_;
+ die "set_hash(): params undefined" if (!defined $params);
$self->_load_table_metadata($table) if (! defined
$self->{table}{$table}{loaded});
&App::sub_exit() if ($App::trace);
}
@@ -1784,11 +1792,11 @@
return(undef); # sorry. maybe some subclass will know how to do this.
}
-# $ok = $rep->insert_rows ($table, [EMAIL PROTECTED], [EMAIL PROTECTED]);
+# $nrows = $rep->insert_rows ($table, [EMAIL PROTECTED], [EMAIL PROTECTED]);
sub insert_rows {
&App::sub_entry if ($App::trace);
my ($self, $table, $cols, $rows, $options) = @_;
- my ($retval, $hashes, $hash, $columns);
+ my ($nrows, $hashes, $hash, $columns);
if (ref($cols) eq "ARRAY" && ref($cols->[0]) eq "HASH") {
$hashes = $cols; # an array of hashrefs was passed in instead of
cols/rows
$hash = $hashes->[0];
@@ -1822,18 +1830,19 @@
}
push(@rows, $row);
}
- $retval = $self->_insert_rows($table, [EMAIL PROTECTED], [EMAIL
PROTECTED], $options);
+ $nrows = $self->_insert_rows($table, [EMAIL PROTECTED], [EMAIL
PROTECTED], $options);
}
else {
- $retval = $self->_insert_rows($table, $cols, $rows, $options);
+ $nrows = $self->_insert_rows($table, $cols, $rows, $options);
}
- &App::sub_exit($retval) if ($App::trace);
- $retval;
+ &App::sub_exit($nrows) if ($App::trace);
+ $nrows;
}
sub delete {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $row, $options) = @_;
+ die "set_row(): params undefined" if (!defined $params);
my $retval = $self->_delete($table,$params,$cols,$row,$options);
&App::sub_exit($retval) if ($App::trace);
return($retval);
@@ -1842,6 +1851,7 @@
sub update {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $row, $options) = @_;
+ die "update(): params undefined" if (!defined $params);
my $retval = $self->_update($table,$params,$cols,$row,$options);
&App::sub_exit($retval) if ($App::trace);
return($retval);
@@ -1859,7 +1869,7 @@
sub _insert_rows {
&App::sub_entry if ($App::trace);
- my ($self, $table, $params, $cols, $row, $options) = @_;
+ my ($self, $table, $cols, $rows, $options) = @_;
$self->{error} = "";
my $retval = 0;
die "_insert_rows(): not yet implemented";
1.33 +13 -11 p5ee/App-Repository/lib/App/Repository/DBI.pm
Index: DBI.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/DBI.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- DBI.pm 21 Nov 2005 20:24:57 -0000 1.32
+++ DBI.pm 25 Nov 2005 16:35:03 -0000 1.33
@@ -1957,22 +1957,21 @@
$retval;
}
-# $ok = $rep->_insert_rows ($table, [EMAIL PROTECTED], [EMAIL PROTECTED]);
+# $nrows = $rep->_insert_rows ($table, [EMAIL PROTECTED], [EMAIL PROTECTED]);
sub _insert_rows {
&App::sub_entry if ($App::trace);
my ($self, $table, $cols, $rows) = @_;
$self->{error} = "";
- my ($row, $sql, $nrows, $ok, $retval);
+ my ($sql, $retval);
my $dbh = $self->{dbh};
return 0 if (!defined $dbh);
- $ok = 1;
+ my $nrows = 0;
+ my $ok = 1;
$sql = $self->_mk_insert_row_sql($table, $cols);
my $debug_sql = $self->{context}{options}{debug_sql};
- foreach $row (@$rows) {
- $nrows += $self->{numrows};
-
+ foreach my $row (@$rows) {
if ($debug_sql) {
print "DEBUG_SQL: _insert_rows()\n";
print "DEBUG_SQL: bind vars [", join("|",map { defined $_ ? $_ :
"undef" } @$row), "]\n";
@@ -1984,7 +1983,10 @@
print "\n";
}
- if (!$retval) {
+ if ($retval) {
+ $nrows ++;
+ }
+ else {
$self->{numrows} = $nrows;
$ok = 0;
last;
@@ -1992,8 +1994,8 @@
}
$self->{sql} = $sql;
$self->{numrows} = $nrows;
- &App::sub_exit($ok) if ($App::trace);
- return($ok);
+ &App::sub_exit($nrows) if ($App::trace);
+ return($nrows);
}
sub _delete {
1.3 +3 -3 p5ee/App-Repository/t/DBI-compress.t
Index: DBI-compress.t
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/t/DBI-compress.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DBI-compress.t 20 Oct 2005 20:08:37 -0000 1.2
+++ DBI-compress.t 25 Nov 2005 16:35:03 -0000 1.3
@@ -95,10 +95,10 @@
my ($nrows);
eval {
- $nrows = $rep->set_rows("test_person", undef, $columns, $rows,
{create=>1});
+ $nrows = $rep->insert_rows("test_person", $columns, $rows);
};
-ok(!$@, "set_rows() [test_person]");
-is($nrows, 7, "set_rows() [test_person]: wrote 7 rows");
+ok(!$@, "insert_rows() [test_person]");
+is($nrows, 7, "insert_rows() [test_person]: wrote 7 rows");
my $hash = $rep->get_hash("test_person",{first_name=>"stephen"});
is($hash->{data}, "Temperament: Goofy\nTalent: Minimal", "get(data) ok");
1.9 +6 -8 p5ee/App-Repository/t/DBI-getset.t
Index: DBI-getset.t
===================================================================
RCS file: /cvs/public/p5ee/App-Repository/t/DBI-getset.t,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DBI-getset.t 20 Oct 2005 20:08:38 -0000 1.8
+++ DBI-getset.t 25 Nov 2005 16:35:03 -0000 1.9
@@ -142,14 +142,6 @@
is($person_id, 4, "get_row() 3 values w/ %crit (checking 3 of 3)");
my ($hashes, $hash);
-ok($rep->set("test_person", {person_id => 1, age => 40}),
"set(table,%hash)");
-$hash = $rep->get_hash("test_person");
-is($hash->{person_id}, 1, "get_hash() person_id");
-is($hash->{age}, 40, "get_hash() age");
-is($hash->{first_name}, "steve", "get_hash() first_name");
-is($hash->{gender}, "M", "get_hash() gender");
-is($hash->{state}, "GA", "get_hash() state");
-
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");
@@ -184,6 +176,12 @@
is($hash->{gender}, "M", "get_hashes()->[n] gender");
is($hash->{state}, "NY", "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");
+
exit(0);
#####################################################################
# $rep->set_rows($table, undef, [EMAIL PROTECTED], $rows, \%options);