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:
parent
1a278fed6c
commit
1412f023f1
4 changed files with 63 additions and 68 deletions
|
|
@ -45,17 +45,18 @@ Package for interfacing with SQL databases. This package implements Perl DBI fun
|
|||
$db->commit;
|
||||
$db->rollback;
|
||||
|
||||
@arr = $db->buildArray($sql);
|
||||
@arr = $db->buildArray($sql);
|
||||
$arrayRef = $db->buildArrayRef($sql);
|
||||
%hash = $db->buildHash($sql);
|
||||
$hashRef = $db->buildHashRef($sql);
|
||||
@arr = $db->quickArray($sql);
|
||||
$text = $db->quickCSV($sql);
|
||||
%hash = $db->quickHash($sql);
|
||||
$hashRef = $db->quickHashRef($sql);
|
||||
$text = $db->quickTab($sql);
|
||||
%hash = $db->buildHash($sql);
|
||||
$hashRef = $db->buildHashRef($sql);
|
||||
@arr = $db->quickArray($sql);
|
||||
$scalar = $db->quickScalar($sql);
|
||||
$text = $db->quickCSV($sql);
|
||||
%hash = $db->quickHash($sql);
|
||||
$hashRef = $db->quickHashRef($sql);
|
||||
$text = $db->quickTab($sql);
|
||||
|
||||
$id = $db->getNextId("someId");
|
||||
$id = $db->getNextId("someId");
|
||||
$string = $db->quote($string);
|
||||
$string = $db->quoteAndJoin(\@array);
|
||||
|
||||
|
|
@ -620,6 +621,35 @@ sub quickHashRef {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 quickScalar ( sql, params )
|
||||
|
||||
Executes a query and returns the first column from a single row of data as a scalar.
|
||||
|
||||
=head3 sql
|
||||
|
||||
An SQL query.
|
||||
|
||||
=head3 params
|
||||
|
||||
An array reference containing values for any placeholder params used in the SQL query.
|
||||
|
||||
=cut
|
||||
|
||||
sub quickScalar {
|
||||
my $self = shift;
|
||||
my $sql = shift;
|
||||
my $params = shift;
|
||||
my ($sth, @data);
|
||||
$sth = $self->prepare($sql);
|
||||
$sth->execute($params);
|
||||
@data = $sth->array;
|
||||
$sth->finish;
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 quickTab ( sql, params )
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue