Closed Bug 306036 Opened 14 years ago Closed 11 years ago

Fix misuse of fetchrow_array() and selectrow_array()


(Bugzilla :: Bugzilla-General, defect, trivial)

Not set





(Reporter: LpSolit, Assigned: karl)


We should write:

my ($result) = $dbh->selectrow_array("SELECT only_one_col FROM ...");
my ($result) = $dbh->fetchrow_array("SELECT only_one_col FROM ...");

instead of:

my $result = $dbh->selectrow_array("SELECT only_one_col FROM ...");
my $result = $dbh->fetchrow_array("SELECT only_one_col FROM ...");

because an array is returned, even with only one element in it.
Target Milestone: --- → Bugzilla 2.20
Note that it's only a problem in a loop. Else I don't see what the problem could be.
Unless we find an actual *bug* in 2.20, I think we should just do it for 2.22.
Target Milestone: Bugzilla 2.20 → Bugzilla 2.22
Assignee: LpSolit → general
Running `grep -nr "row_array(" *` in the Bugzilla tip, plus some filtering, gives me:

Bugzilla/        Bugzilla->dbh->selectrow_array("SELECT LENGTH(thedata)
Bugzilla/Auth/Verify/      $dbh->selectrow_array($sth,
Bugzilla/          $dbh->selectrow_array(q{SELECT dupe_of 
Bugzilla/    $self->{'actual_time'} = $sth->fetchrow_array();
Bugzilla/            $membercontrol, $othercontrol) = $sth->fetchrow_array()) {
Bugzilla/        my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " .
Bugzilla/        $dbh->selectrow_array("SELECT votes, bug_status, everconfirmed, " .
Bugzilla/    $dbh->selectrow_array("SELECT bug_id FROM bugs WHERE bug_id = ?", 
undef, $id)
Bugzilla/    my $id = $dbh->selectrow_array($query, undef, $alias); 
Bugzilla/        $count = $dbh->selectrow_array('SELECT COUNT(*) FROM longdescs
Bugzilla/    my $datefrom = $dbh->selectrow_array("SELECT MIN(series_date) " . 
Bugzilla/    my $dateto = $dbh->selectrow_array("SELECT MAX(series_date) " . 
Bugzilla/        $self->{'product_count'} = $dbh->selectrow_array(q{
Bugzilla/        $self->{'bug_count'} = $dbh->selectrow_array(q{
Bugzilla/DB/    my ($last_insert_id) = $self->selectrow_array('SELECT LAST_INSERT_ID()');
Bugzilla/DB/        my $bug_count = $self->selectrow_array("SELECT COUNT(*) FROM 
Bugzilla/DB/            $self->selectrow_array("SELECT COUNT(*) FROM attachments");
Bugzilla/DB/                  = $sth->fetchrow_array()) 
Bugzilla/            my $any_nulls = $self->selectrow_array(
Bugzilla/            $self->selectrow_array("SELECT COUNT(*) FROM bz_schema");
Bugzilla/    my $table_size = $self->selectrow_array("SELECT COUNT(*) FROM bz_schema");
Bugzilla/    my $id = $dbh->selectrow_array('SELECT fieldid FROM fielddefs
Bugzilla/        $dbh->selectrow_array("SELECT 1 FROM flags
Bugzilla/        $dbh->selectrow_array("SELECT 1 FROM flagtypes
Bugzilla/        $self->{'bug_count'} = $dbh->selectrow_array(q{
Bugzilla/        $self->{'bug_count'} = $dbh->selectrow_array(qq{
Bugzilla/Search/            if (Bugzilla->dbh->selectrow_array(q{SELECT COUNT(*)
Bugzilla/            $dbh->selectrow_array("SELECT series_id FROM series
Bugzilla/        $self->{'series_id'} = $dbh->selectrow_array("SELECT MAX(series_id) " .
Bugzilla/    my $series_id = $dbh->selectrow_array("SELECT series_id " .
Bugzilla/        $category_id = $dbh->selectrow_array("SELECT id " .
Bugzilla/User/          $dbh->selectrow_array(
Bugzilla/User/              $dbh->selectrow_array(
Bugzilla/User/               = $sth->fetchrow_array()) {
>fetchrow_array()) {
Bugzilla/    return Bugzilla->dbh->selectrow_array($query, undef, $otherUser->id);
Bugzilla/    my $time = $dbh->selectrow_array("SELECT NOW()");
Bugzilla/        my $bug_status = $dbh->selectrow_array("SELECT bug_status 
Bugzilla/        $dbh->selectrow_array("SELECT 1 
Bugzilla/    my $user_id = $dbh->selectrow_array("SELECT userid FROM profiles WHERE " 
Bugzilla/        $self->{'bug_count'} = $dbh->selectrow_array(qq{
buglist.cgi:211:    my $result = $dbh->selectrow_array("SELECT query FROM namedqueries" 
buglist.cgi:265:    my $result = $dbh->selectrow_array("SELECT userid FROM namedqueries"
buglist.cgi:291:    my $result = $dbh->selectrow_array("SELECT query FROM series " .
buglist.cgi:303:    my $count = $dbh->selectrow_array("SELECT COUNT(quip)"
buglist.cgi:307:        $dbh->selectrow_array("SELECT quip FROM quips WHERE approved = 1 " . 
chart.cgi:210:    my $iscreator = $dbh->selectrow_array("SELECT creator = ? FROM series " .    $dbh->selectrow_array("SELECT COUNT(*) FROM classifications");        my ($id, $createtime, $reporterid, $desc) = ($sth->fetchrow_array());                    ($who) = ($s2->fetchrow_array());                            ($who) = ($s2->fetchrow_array());        my $initialownerid = $s2->fetchrow_array();        my $initialqacontactid = $s2->fetchrow_array(); $milestones_exist = $dbh->selectrow_array("SELECT 1 FROM milestones");      $sth->fetchrow_array())            = $sth->fetchrow_array()) { $series_exists = $dbh->selectrow_array("SELECT 1 FROM series " .            $dbh->selectrow_array("SELECT id " .            $dbh->selectrow_array("SELECT id " .    my $group_exists = $dbh->selectrow_array(    my $userid = $dbh->selectrow_array("SELECT userid FROM profiles WHERE " .
editflagtypes.cgi:145:                $dbh->selectrow_array('SELECT name FROM groups WHERE id = ?',
editflagtypes.cgi:263:    my $id = $dbh->selectrow_array('SELECT MAX(id) FROM flagtypes') + 1;
editflagtypes.cgi:468:        $dbh->selectrow_array('SELECT 1 FROM flagtypes WHERE id = ?',
editflagtypes.cgi:571:          my $gid = $dbh->selectrow_array('SELECT id FROM groups
editgroups.cgi:113:    my $name_exists = Bugzilla->dbh->selectrow_array("SELECT name FROM groups 
" .
editgroups.cgi:168:        $dbh->selectrow_array("SELECT name, description, userregexp, " .
editgroups.cgi:305:        $dbh->selectrow_array("SELECT name, description, isbuggroup " .
editgroups.cgi:313:    my $hasusers = $dbh->selectrow_array('SELECT 1 FROM user_group_map 
editgroups.cgi:326:    my $hasflags = $dbh->selectrow_array('SELECT 1 FROM flagtypes 
editgroups.cgi:356:        $dbh->selectrow_array("SELECT name, isbuggroup FROM groups " .
editgroups.cgi:366:    my $hasusers = $dbh->selectrow_array('SELECT 1 FROM user_group_map 
editgroups.cgi:374:    my $hasbugs = $dbh->selectrow_array('SELECT 1 FROM bug_group_map
editgroups.cgi:386:    my $hasflags = $dbh->selectrow_array('SELECT 1 FROM flagtypes 
editgroups.cgi:469:      $dbh->selectrow_array('SELECT name, userregexp FROM groups
editgroups.cgi:543:    my $isbuggroup = $dbh->selectrow_array('SELECT isbuggroup FROM groups
editkeywords.cgi:117:    my $id = $dbh->selectrow_array('SELECT id FROM keyworddefs
editkeywords.cgi:174:        $dbh->selectrow_array('SELECT name, description FROM keyworddefs
editkeywords.cgi:182:    my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
editkeywords.cgi:213:    my $tmp = $dbh->selectrow_array('SELECT id FROM keyworddefs
editkeywords.cgi:241:    my $name = $dbh->selectrow_array('SELECT name FROM keyworddefs
editkeywords.cgi:245:        my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
editmilestones.cgi:214:        my $timestamp = $dbh->selectrow_array("SELECT NOW()");
editproducts.cgi:598:                $dbh->selectrow_array("SELECT
editproducts.cgi:672:    $vars->{'bug_count'} = $dbh->selectrow_array(qq{
editusers.cgi:423:    $vars->{'assignee_or_qa'} = $dbh->selectrow_array(
editusers.cgi:428:    $vars->{'reporter'} = $dbh->selectrow_array(
editusers.cgi:431:    $vars->{'cc'} = $dbh->selectrow_array(
editusers.cgi:434:    $vars->{'bugs_activity'} = $dbh->selectrow_array(
editusers.cgi:437:    $vars->{'flags'}{'requestee'} = $dbh->selectrow_array(
editusers.cgi:440:    $vars->{'flags'}{'setter'} = $dbh->selectrow_array(
editusers.cgi:443:    $vars->{'longdescs'} = $dbh->selectrow_array(
editusers.cgi:446:    $vars->{'namedqueries'} = $dbh->selectrow_array(
editusers.cgi:449:    $vars->{'profiles_activity'} = $dbh->selectrow_array(
editusers.cgi:452:    $vars->{'series'} = $dbh->selectrow_array(
editusers.cgi:455:    $vars->{'votes'} = $dbh->selectrow_array(
editusers.cgi:458:    $vars->{'watch'}{'watched'} = $dbh->selectrow_array(
editusers.cgi:461:    $vars->{'watch'}{'watcher'} = $dbh->selectrow_array(
editusers.cgi:464:    $vars->{'whine_events'} = $dbh->selectrow_array(
editusers.cgi:467:    $vars->{'whine_schedules'} = $dbh->selectrow_array(
editusers.cgi:530:    my $timestamp = $dbh->selectrow_array('SELECT NOW()');
editusers.cgi:605:    while ($id = $sth_seriesid->fetchrow_array()) {
editusers.cgi:624:    while ($id = $sth_whineidFromSchedules->fetchrow_array()) {
editusers.cgi:631:    while ($id = $sth_whineidFromEvents->fetchrow_array()) {
editvalues.cgi:71:        $dbh->selectrow_array("SELECT COUNT(*) FROM $field "
editvalues.cgi:233:        $dbh->selectrow_array("SELECT COUNT(*) FROM bugs WHERE $field = ?",
editvalues.cgi:236:        $dbh->selectrow_array("SELECT COUNT(*) FROM $field");
editvalues.cgi:294:    $vars->{'sortkey'} = $dbh->selectrow_array(
enter_bug.cgi:166:        return $value if $dbh->selectrow_array(
enter_bug.cgi:346:       = $sth->fetchrow_array()) {
enter_bug.cgi:480:                $dbh->selectrow_array('SELECT defaultmilestone FROM products
enter_bug.cgi:496:my $votestoconfirm = $dbh->selectrow_array('SELECT votestoconfirm FROM 
products    my $has_access = $dbh->selectrow_array($query, undef, $productname);        $dbh->selectrow_array('SELECT CASE WHEN disallownew = 0 THEN 1 ELSE 0 END, ' 
process_bug.cgi:273:        $dbh->selectrow_array("SELECT 1 FROM bugs
process_bug.cgi:624:    my $timestamp = $dbh->selectrow_array("SELECT NOW()");
process_bug.cgi:1119:            $dbh->selectrow_array("SELECT dupe_of FROM duplicates
process_bug.cgi:1388:                $dbh->selectrow_array("SELECT defaultmilestone
query.cgi:94:                my $query = $dbh->selectrow_array(
query.cgi:121:    $userdefaultquery = $dbh->selectrow_array(
votes.cgi:136:        my $has_votes = $dbh->selectrow_array('SELECT vote_count FROM votes
Assignee: general → karl
Please note that using these routines in a scalar context *is* valid! Only fix
what needs to be fixed, not all occurences.
Target Milestone: Bugzilla 2.22 → Bugzilla 2.24
Most of these don't need to be fixed, also, as the DBDs correctly check wantarray and return the right thing. Theoretically they don't have to, but they do.
Severity: normal → trivial
This bug is retargetted to Bugzilla 3.2 for one of the following reasons:

- it has no assignee (except the default one)
- we don't expect someone to fix it in the next two weeks (i.e. before we freeze the trunk to prepare Bugzilla 3.0 RC1)
- it's not a blocker

If you are working on this bug and you think you will be able to submit a patch in the next two weeks, retarget this bug to 3.0.

If this bug is something you would like to see implemented in 3.0 but you are not a developer or you don't think you will be able to fix this bug yourself in the next two weeks, please *do not* retarget this bug.

If you think this bug should absolutely be fixed before we release 3.0, either ask on IRC or use the "blocking3.0 flag".
Target Milestone: Bugzilla 3.0 → Bugzilla 3.2
Bugzilla 3.2 is now frozen. Only enhancements blocking 3.2 or specifically approved for 3.2 may be checked in to the 3.2 branch. If you would like to nominate your enhancement for Bugzilla 3.2, set the "blocking3.2" flag to "?". Then, either the target milestone will be changed back, or the blocking3.2 flag will be granted, if we will accept this enhancement for Bugzilla 3.2.

This particular bug has not been touched in over eight months, and thus is being retargeted to "---" instead of "Bugzilla 4.0". If you believe this is a mistake, feel free to retarget it to Bugzilla 4.0.
Target Milestone: Bugzilla 3.2 → ---
We have no evidence of such issues, so closing as WFM.
Closed: 11 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.