Fixed a bug in WebGUI::User::profileField, where the check for whether or not

a profile field existed in the db always passed because it used quickArray in
scalar context.  Since quickArray always returns 1 element, this was always true
and it never returned undef like it was supposed to.

To fix this, I added a new method called quickScalar that returns the first column
from the row as a scalar.  It has a basic test in SQL.t.

Then there's the new test in User.t for coverage that exposed this problem, and
I also removed a whole slew of duplicate tests.
This commit is contained in:
Colin Kuskie 2007-03-04 04:18:59 +00:00
parent 1a278fed6c
commit 1412f023f1
4 changed files with 63 additions and 68 deletions

View file

@ -383,6 +383,7 @@ sub new {
my $cache = WebGUI::Cache->new($session,["user",$userId]);
my $userData = $cache->get;
unless ($userData->{_userId} && $userData->{_user}{username}) {
$session->errorHandler->warn('Cache invalid');
my %user;
tie %user, 'Tie::CPHash';
%user = $session->db->quickHash("select * from users where userId=?",[$userId]);
@ -462,7 +463,7 @@ sub profileField {
$self = shift;
$fieldName = shift;
$value = shift;
if (!exists $self->{_profile}{$fieldName} && !$self->session->db->quickArray("SELECT COUNT(*) FROM userProfileField WHERE fieldName = ?", [$fieldName])) {
if (!exists $self->{_profile}{$fieldName} && !$self->session->db->quickScalar("SELECT COUNT(*) FROM userProfileField WHERE fieldName = ?", [$fieldName]) ) {
$self->session->errorHandler->warn("No such profile field: $fieldName");
return undef;
}