Closed Bug 306036 Opened 19 years ago Closed 16 years ago

Fix misuse of fetchrow_array() and selectrow_array()

Categories

(Bugzilla :: Bugzilla-General, defect)

2.21
defect
Not set
trivial

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: LpSolit, Assigned: karl)

Details

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.
Status: NEW → ASSIGNED
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
Status: ASSIGNED → NEW
Running `grep -nr "row_array(" *` in the Bugzilla tip, plus some filtering, gives me: Bugzilla/Attachment.pm:325: Bugzilla->dbh->selectrow_array("SELECT LENGTH(thedata) Bugzilla/Auth/Verify/LDAP.pm:143: $dbh->selectrow_array($sth, Bugzilla/Bug.pm:315: $dbh->selectrow_array(q{SELECT dupe_of Bugzilla/Bug.pm:338: $self->{'actual_time'} = $sth->fetchrow_array(); Bugzilla/Bug.pm:566: $membercontrol, $othercontrol) = $sth->fetchrow_array()) { Bugzilla/Bug.pm:1084: my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " . Bugzilla/Bug.pm:1099: $dbh->selectrow_array("SELECT votes, bug_status, everconfirmed, " . Bugzilla/Bug.pm:1168: $dbh->selectrow_array("SELECT bug_id FROM bugs WHERE bug_id = ?", undef, $id) Bugzilla/Bug.pm:1211: my $id = $dbh->selectrow_array($query, undef, $alias); Bugzilla/BugMail.pm:762: $count = $dbh->selectrow_array('SELECT COUNT(*) FROM longdescs Bugzilla/Chart.pm:218: my $datefrom = $dbh->selectrow_array("SELECT MIN(series_date) " . Bugzilla/Chart.pm:227: my $dateto = $dbh->selectrow_array("SELECT MAX(series_date) " . Bugzilla/Classification.pm:88: $self->{'product_count'} = $dbh->selectrow_array(q{ Bugzilla/Component.pm:96: $self->{'bug_count'} = $dbh->selectrow_array(q{ Bugzilla/DB/Mysql.pm:81: my ($last_insert_id) = $self->selectrow_array('SELECT LAST_INSERT_ID()'); Bugzilla/DB/Mysql.pm:285: my $bug_count = $self->selectrow_array("SELECT COUNT(*) FROM bugs"); Bugzilla/DB/Mysql.pm:291: $self->selectrow_array("SELECT COUNT(*) FROM attachments"); Bugzilla/DB/Mysql.pm:455: = $sth->fetchrow_array()) Bugzilla/DB.pm:383: my $any_nulls = $self->selectrow_array( Bugzilla/DB.pm:801: $self->selectrow_array("SELECT COUNT(*) FROM bz_schema"); Bugzilla/DB.pm:893: my $table_size = $self->selectrow_array("SELECT COUNT(*) FROM bz_schema"); Bugzilla/Field.pm:61: my $id = $dbh->selectrow_array('SELECT fieldid FROM fielddefs Bugzilla/Flag.pm:268: $dbh->selectrow_array("SELECT 1 FROM flags Bugzilla/FlagType.pm:346: $dbh->selectrow_array("SELECT 1 FROM flagtypes Bugzilla/Milestone.pm:81: $self->{'bug_count'} = $dbh->selectrow_array(q{ Bugzilla/Product.pm:195: $self->{'bug_count'} = $dbh->selectrow_array(qq{ Bugzilla/Search/Quicksearch.pm:134: if (Bugzilla->dbh->selectrow_array(q{SELECT COUNT(*) Bugzilla/Series.pm:183: $dbh->selectrow_array("SELECT series_id FROM series Bugzilla/Series.pm:209: $self->{'series_id'} = $dbh->selectrow_array("SELECT MAX(series_id) " . Bugzilla/Series.pm:228: my $series_id = $dbh->selectrow_array("SELECT series_id " . Bugzilla/Series.pm:247: $category_id = $dbh->selectrow_array("SELECT id " . Bugzilla/User/Setting.pm:64: $dbh->selectrow_array( Bugzilla/User/Setting.pm:77: $dbh->selectrow_array( Bugzilla/User/Setting.pm:154: = $sth->fetchrow_array()) { >fetchrow_array()) { Bugzilla/User.pm:381: return Bugzilla->dbh->selectrow_array($query, undef, $otherUser->id); Bugzilla/User.pm:531: my $time = $dbh->selectrow_array("SELECT NOW()"); Bugzilla/User.pm:1068: my $bug_status = $dbh->selectrow_array("SELECT bug_status Bugzilla/User.pm:1102: $dbh->selectrow_array("SELECT 1 Bugzilla/User.pm:1255: my $user_id = $dbh->selectrow_array("SELECT userid FROM profiles WHERE " . Bugzilla/Version.pm:80: $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 " . checksetup.pl:1854: $dbh->selectrow_array("SELECT COUNT(*) FROM classifications"); checksetup.pl:2035: my ($id, $createtime, $reporterid, $desc) = ($sth->fetchrow_array()); checksetup.pl:2075: ($who) = ($s2->fetchrow_array()); checksetup.pl:2091: ($who) = ($s2->fetchrow_array()); checksetup.pl:2250: my $initialownerid = $s2->fetchrow_array(); checksetup.pl:2289: my $initialqacontactid = $s2->fetchrow_array(); checksetup.pl:2326:my $milestones_exist = $dbh->selectrow_array("SELECT 1 FROM milestones"); checksetup.pl:3245: $sth->fetchrow_array()) checksetup.pl:3339: = $sth->fetchrow_array()) { checksetup.pl:3399:my $series_exists = $dbh->selectrow_array("SELECT 1 FROM series " . checksetup.pl:3525: $dbh->selectrow_array("SELECT id " . checksetup.pl:3529: $dbh->selectrow_array("SELECT id " . checksetup.pl:4089: my $group_exists = $dbh->selectrow_array( checksetup.pl:4403: 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 classifications.name 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 globals.pl:443: my $has_access = $dbh->selectrow_array($query, undef, $productname); globals.pl:455: $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.
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.