Commit f4915ace authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303693: Eliminate deprecated Bugzilla::DB routines from describe*.cgi,…

Bug 303693: Eliminate deprecated Bugzilla::DB routines from describe*.cgi, duplicates.cgi, quips.cgi, report.cgi, request.cgi and showdependency*.cgi - Patch by Teemu Mannermaa <wicked@etlicon.fi> r=LpSolit a=myk
parent ba7c33a6
...@@ -35,6 +35,7 @@ my $user = Bugzilla->login(); ...@@ -35,6 +35,7 @@ my $user = Bugzilla->login();
GetVersionTable(); GetVersionTable();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
my $product = trim($cgi->param('product') || ''); my $product = trim($cgi->param('product') || '');
...@@ -87,12 +88,13 @@ if (!$product_id || !$user->can_enter_product($product)) { ...@@ -87,12 +88,13 @@ if (!$product_id || !$user->can_enter_product($product)) {
###################################################################### ######################################################################
my @components; my @components;
SendSQL("SELECT name, initialowner, initialqacontact, description FROM " . my $comps = $dbh->selectall_arrayref(
"components WHERE product_id = $product_id ORDER BY name"); q{SELECT name, initialowner, initialqacontact, description
while (MoreSQLData()) { FROM components
my ($name, $initialowner, $initialqacontact, $description) = WHERE product_id = ?
FetchSQLData(); ORDER BY name}, undef, $product_id);
foreach my $comp (@$comps) {
my ($name, $initialowner, $initialqacontact, $description) = @$comp;
my %component; my %component;
$component{'name'} = $name; $component{'name'} = $name;
......
...@@ -36,25 +36,17 @@ my $dbh = Bugzilla->dbh; ...@@ -36,25 +36,17 @@ my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
SendSQL("SELECT keyworddefs.name, keyworddefs.description, my $keywords = $dbh->selectall_arrayref(
COUNT(keywords.bug_id) q{SELECT keyworddefs.name, keyworddefs.description,
FROM keyworddefs LEFT JOIN keywords COUNT(keywords.bug_id) AS bugcount
ON keyworddefs.id = keywords.keywordid " . FROM keyworddefs
LEFT JOIN keywords
ON keyworddefs.id = keywords.keywordid } .
$dbh->sql_group_by('keyworddefs.id', $dbh->sql_group_by('keyworddefs.id',
'keyworddefs.name, keyworddefs.description') . " 'keyworddefs.name, keyworddefs.description') .
ORDER BY keyworddefs.name"); " ORDER BY keyworddefs.name", {'Slice' => {}});
my @keywords; $vars->{'keywords'} = $keywords;
while (MoreSQLData()) {
my ($name, $description, $bugs) = FetchSQLData();
push (@keywords, { name => $name,
description => $description,
bugcount => $bugs });
}
$vars->{'keywords'} = \@keywords;
$vars->{'caneditkeywords'} = UserInGroup("editkeywords"); $vars->{'caneditkeywords'} = UserInGroup("editkeywords");
print Bugzilla->cgi->header(); print Bugzilla->cgi->header();
......
...@@ -37,6 +37,7 @@ use Bugzilla::Config qw(:DEFAULT $datadir); ...@@ -37,6 +37,7 @@ use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Constants; use Bugzilla::Constants;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
# Go directly to the XUL version of the duplicates report (duplicates.xul) # Go directly to the XUL version of the duplicates report (duplicates.xul)
# if the user specified ctype=xul. Adds params if they exist, and directs # if the user specified ctype=xul. Adds params if they exist, and directs
...@@ -231,13 +232,13 @@ if (scalar(%count)) { ...@@ -231,13 +232,13 @@ if (scalar(%count)) {
'params' => $params, 'params' => $params,
); );
SendSQL($query->getSQL()); my $results = $dbh->selectall_arrayref($query->getSQL());
while (MoreSQLData()) { foreach my $result (@$results) {
# Note: maximum row count is dealt with in the template. # Note: maximum row count is dealt with in the template.
my ($id, $component, $bug_severity, $op_sys, $target_milestone, my ($id, $component, $bug_severity, $op_sys, $target_milestone,
$short_desc, $bug_status, $resolution) = FetchSQLData(); $short_desc, $bug_status, $resolution) = @$result;
push (@bugs, { id => $id, push (@bugs, { id => $id,
count => $count{$id}, count => $count{$id},
......
...@@ -36,6 +36,7 @@ use Bugzilla::Constants; ...@@ -36,6 +36,7 @@ use Bugzilla::Constants;
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
...@@ -43,23 +44,24 @@ my $action = $cgi->param('action') || ""; ...@@ -43,23 +44,24 @@ my $action = $cgi->param('action') || "";
if ($action eq "show") { if ($action eq "show") {
# Read in the entire quip list # Read in the entire quip list
SendSQL("SELECT quipid, userid, quip, approved FROM quips"); my $quipsref = $dbh->selectall_arrayref(
"SELECT quipid, userid, quip, approved FROM quips");
my $quips; my $quips;
my @quipids; my @quipids;
while (MoreSQLData()) { foreach my $quipref (@$quipsref) {
my ($quipid, $userid, $quip, $approved) = FetchSQLData(); my ($quipid, $userid, $quip, $approved) = @$quipref;
$quips->{$quipid} = {'userid' => $userid, 'quip' => $quip, $quips->{$quipid} = {'userid' => $userid, 'quip' => $quip,
'approved' => $approved}; 'approved' => $approved};
push(@quipids, $quipid); push(@quipids, $quipid);
} }
my $users; my $users;
my $sth = $dbh->prepare("SELECT login_name FROM profiles WHERE userid = ?");
foreach my $quipid (@quipids) { foreach my $quipid (@quipids) {
my $userid = $quips->{$quipid}{'userid'}; my $userid = $quips->{$quipid}{'userid'};
if ($userid && not defined $users->{$userid}) { if ($userid && not defined $users->{$userid}) {
SendSQL("SELECT login_name FROM profiles WHERE userid = $userid"); ($users->{$userid}) = $dbh->selectrow_array($sth, undef, $userid);
$users->{$userid} = FetchOneColumn();
} }
} }
$vars->{'quipids'} = \@quipids; $vars->{'quipids'} = \@quipids;
...@@ -77,20 +79,21 @@ if ($action eq "add") { ...@@ -77,20 +79,21 @@ if ($action eq "add") {
(Param('quip_list_entry_control') eq "open") || (UserInGroup('admin')) || 0; (Param('quip_list_entry_control') eq "open") || (UserInGroup('admin')) || 0;
my $comment = $cgi->param("quip"); my $comment = $cgi->param("quip");
$comment || ThrowUserError("need_quip"); $comment || ThrowUserError("need_quip");
trick_taint($comment); # Used in a placeholder below
SendSQL("INSERT INTO quips (userid, quip, approved) VALUES " . $dbh->do("INSERT INTO quips (userid, quip, approved) VALUES (?, ?, ?)",
'(' . $userid . ', ' . SqlQuote($comment) . ', ' . $approved . ')'); undef, ($userid, $comment, $approved));
$vars->{'added_quip'} = $comment; $vars->{'added_quip'} = $comment;
} }
if ($action eq 'approve') { if ($action eq 'approve') {
# Read in the entire quip list # Read in the entire quip list
SendSQL("SELECT quipid, approved FROM quips"); my $quipsref = $dbh->selectall_arrayref("SELECT quipid, approved FROM quips");
my %quips; my %quips;
while (MoreSQLData()) { foreach my $quipref (@$quipsref) {
my ($quipid, $approved) = FetchSQLData(); my ($quipid, $approved) = @$quipref;
$quips{$quipid} = $approved; $quips{$quipid} = $approved;
} }
...@@ -103,9 +106,9 @@ if ($action eq 'approve') { ...@@ -103,9 +106,9 @@ if ($action eq 'approve') {
else { push(@unapproved, $quipid); } else { push(@unapproved, $quipid); }
} }
} }
SendSQL("UPDATE quips SET approved = 1 WHERE quipid IN (" . $dbh->do("UPDATE quips SET approved = 1 WHERE quipid IN (" .
join(",", @approved) . ")") if($#approved > -1); join(",", @approved) . ")") if($#approved > -1);
SendSQL("UPDATE quips SET approved = 0 WHERE quipid IN (" . $dbh->do("UPDATE quips SET approved = 0 WHERE quipid IN (" .
join(",", @unapproved) . ")") if($#unapproved > -1); join(",", @unapproved) . ")") if($#unapproved > -1);
$vars->{ 'approved' } = \@approved; $vars->{ 'approved' } = \@approved;
$vars->{ 'unapproved' } = \@unapproved; $vars->{ 'unapproved' } = \@unapproved;
...@@ -120,9 +123,10 @@ if ($action eq "delete") { ...@@ -120,9 +123,10 @@ if ($action eq "delete") {
ThrowCodeError("need_quipid") unless $quipid =~ /(\d+)/; ThrowCodeError("need_quipid") unless $quipid =~ /(\d+)/;
$quipid = $1; $quipid = $1;
SendSQL("SELECT quip FROM quips WHERE quipid = $quipid"); ($vars->{'deleted_quip'}) = $dbh->selectrow_array(
$vars->{'deleted_quip'} = FetchSQLData(); "SELECT quip FROM quips WHERE quipid = ?",
SendSQL("DELETE FROM quips WHERE quipid = $quipid"); undef, $quipid);
$dbh->do("DELETE FROM quips WHERE quipid = ?", undef, $quipid);
} }
print $cgi->header(); print $cgi->header();
......
...@@ -35,6 +35,7 @@ my $cgi = Bugzilla->cgi; ...@@ -35,6 +35,7 @@ my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
my $buffer = $cgi->query_string(); my $buffer = $cgi->query_string();
my $dbh = Bugzilla->dbh;
# Go straight back to query.cgi if we are adding a boolean chart. # Go straight back to query.cgi if we are adding a boolean chart.
if (grep(/^cmd-/, $cgi->param())) { if (grep(/^cmd-/, $cgi->param())) {
...@@ -149,7 +150,7 @@ my $query = $search->getSQL(); ...@@ -149,7 +150,7 @@ my $query = $search->getSQL();
$::SIG{TERM} = 'DEFAULT'; $::SIG{TERM} = 'DEFAULT';
$::SIG{PIPE} = 'DEFAULT'; $::SIG{PIPE} = 'DEFAULT';
SendSQL($query); my $results = $dbh->selectall_arrayref($query);
# We have a hash of hashes for the data itself, and a hash to hold the # We have a hash of hashes for the data itself, and a hash to hold the
# row/col/table names. # row/col/table names.
...@@ -165,8 +166,8 @@ my $col_isnumeric = 1; ...@@ -165,8 +166,8 @@ my $col_isnumeric = 1;
my $row_isnumeric = 1; my $row_isnumeric = 1;
my $tbl_isnumeric = 1; my $tbl_isnumeric = 1;
while (MoreSQLData()) { foreach my $result (@$results) {
my ($row, $col, $tbl) = FetchSQLData(); my ($row, $col, $tbl) = @$result;
# handle empty dimension member names # handle empty dimension member names
$row = ' ' if ($row eq ''); $row = ' ' if ($row eq '');
......
...@@ -157,14 +157,17 @@ sub queue { ...@@ -157,14 +157,17 @@ sub queue {
# Filter results by exact email address of requester or requestee. # Filter results by exact email address of requester or requestee.
if (defined $cgi->param('requester') && $cgi->param('requester') ne "") { if (defined $cgi->param('requester') && $cgi->param('requester') ne "") {
push(@criteria, $dbh->sql_istrcmp('requesters.login_name', my $requester = $dbh->quote($cgi->param('requester'));
SqlQuote($cgi->param('requester')))); trick_taint($requester); # Quoted above
push(@criteria, $dbh->sql_istrcmp('requesters.login_name', $requester));
push(@excluded_columns, 'requester') unless $cgi->param('do_union'); push(@excluded_columns, 'requester') unless $cgi->param('do_union');
} }
if (defined $cgi->param('requestee') && $cgi->param('requestee') ne "") { if (defined $cgi->param('requestee') && $cgi->param('requestee') ne "") {
if ($cgi->param('requestee') ne "-") { if ($cgi->param('requestee') ne "-") {
my $requestee = $dbh->quote($cgi->param('requestee'));
trick_taint($requestee); # Quoted above
push(@criteria, $dbh->sql_istrcmp('requestees.login_name', push(@criteria, $dbh->sql_istrcmp('requestees.login_name',
SqlQuote($cgi->param('requestee')))); $requestee));
} }
else { push(@criteria, "flags.requestee_id IS NULL") } else { push(@criteria, "flags.requestee_id IS NULL") }
push(@excluded_columns, 'requestee') unless $cgi->param('do_union'); push(@excluded_columns, 'requestee') unless $cgi->param('do_union');
...@@ -203,8 +206,10 @@ sub queue { ...@@ -203,8 +206,10 @@ sub queue {
} }
} }
if (!$has_attachment_type) { push(@excluded_columns, 'attachment') } if (!$has_attachment_type) { push(@excluded_columns, 'attachment') }
push(@criteria, "flagtypes.name = " . SqlQuote($form_type)); my $quoted_form_type = $dbh->quote($form_type);
trick_taint($quoted_form_type); # Already SQL quoted
push(@criteria, "flagtypes.name = " . $quoted_form_type);
push(@excluded_columns, 'type') unless $cgi->param('do_union'); push(@excluded_columns, 'type') unless $cgi->param('do_union');
} }
...@@ -252,10 +257,10 @@ sub queue { ...@@ -252,10 +257,10 @@ sub queue {
$vars->{'query'} = $query; $vars->{'query'} = $query;
$vars->{'debug'} = $cgi->param('debug') ? 1 : 0; $vars->{'debug'} = $cgi->param('debug') ? 1 : 0;
SendSQL($query); my $results = $dbh->selectall_arrayref($query);
my @requests = (); my @requests = ();
while (MoreSQLData()) { foreach my $result (@$results) {
my @data = FetchSQLData(); my @data = @$result;
my $request = { my $request = {
'id' => $data[0] , 'id' => $data[0] ,
'type' => $data[1] , 'type' => $data[1] ,
...@@ -274,8 +279,9 @@ sub queue { ...@@ -274,8 +279,9 @@ sub queue {
# Get a list of request type names to use in the filter form. # Get a list of request type names to use in the filter form.
my @types = ("all"); my @types = ("all");
SendSQL("SELECT DISTINCT(name) FROM flagtypes ORDER BY name"); my $flagtypes = $dbh->selectcol_arrayref(
push(@types, FetchOneColumn()) while MoreSQLData(); "SELECT DISTINCT(name) FROM flagtypes ORDER BY name");
push(@types, @$flagtypes);
$vars->{'products'} = $user->get_selectable_products; $vars->{'products'} = $user->get_selectable_products;
$vars->{'excluded_columns'} = \@excluded_columns; $vars->{'excluded_columns'} = \@excluded_columns;
......
...@@ -36,6 +36,7 @@ require "globals.pl"; ...@@ -36,6 +36,7 @@ require "globals.pl";
Bugzilla->login(); Bugzilla->login();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
...@@ -122,10 +123,11 @@ node [URL="${urlbase}show_bug.cgi?id=\\N", style=filled, color=lightgrey] ...@@ -122,10 +123,11 @@ node [URL="${urlbase}show_bug.cgi?id=\\N", style=filled, color=lightgrey]
my %baselist; my %baselist;
if ($cgi->param('doall')) { if ($cgi->param('doall')) {
SendSQL("SELECT blocked, dependson FROM dependencies"); my $dependencies = $dbh->selectall_arrayref(
"SELECT blocked, dependson FROM dependencies");
while (MoreSQLData()) { foreach my $dependency (@$dependencies) {
my ($blocked, $dependson) = FetchSQLData(); my ($blocked, $dependson) = @$dependency;
AddLink($blocked, $dependson, $fh); AddLink($blocked, $dependson, $fh);
} }
} else { } else {
...@@ -136,12 +138,14 @@ if ($cgi->param('doall')) { ...@@ -136,12 +138,14 @@ if ($cgi->param('doall')) {
} }
my @stack = keys(%baselist); my @stack = keys(%baselist);
my $sth = $dbh->prepare(
q{SELECT blocked, dependson
FROM dependencies
WHERE blocked = ? or dependson = ?});
foreach my $id (@stack) { foreach my $id (@stack) {
SendSQL("SELECT blocked, dependson my $dependencies = $dbh->selectall_arrayref($sth, undef, ($id, $id));
FROM dependencies foreach my $dependency (@$dependencies) {
WHERE blocked = $id or dependson = $id"); my ($blocked, $dependson) = @$dependency;
while (MoreSQLData()) {
my ($blocked, $dependson) = FetchSQLData();
if ($blocked != $id && !exists $seen{$blocked}) { if ($blocked != $id && !exists $seen{$blocked}) {
push @stack, $blocked; push @stack, $blocked;
} }
...@@ -159,16 +163,13 @@ if ($cgi->param('doall')) { ...@@ -159,16 +163,13 @@ if ($cgi->param('doall')) {
} }
} }
my $sth = $dbh->prepare(
q{SELECT bug_status, resolution, short_desc
FROM bugs
WHERE bugs.bug_id = ?});
foreach my $k (keys(%seen)) { foreach my $k (keys(%seen)) {
my $summary = "";
my $stat;
my $resolution;
# Retrieve bug information from the database # Retrieve bug information from the database
my ($stat, $resolution, $summary) = $dbh->selectrow_array($sth, undef, $k);
SendSQL("SELECT bug_status, resolution, short_desc FROM bugs " .
"WHERE bugs.bug_id = $k");
($stat, $resolution, $summary) = FetchSQLData();
$stat ||= 'NEW'; $stat ||= 'NEW';
$resolution ||= ''; $resolution ||= '';
$summary ||= ''; $summary ||= '';
......
...@@ -33,6 +33,7 @@ use Bugzilla::Bug; ...@@ -33,6 +33,7 @@ use Bugzilla::Bug;
Bugzilla->login(); Bugzilla->login();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
...@@ -145,27 +146,26 @@ sub GetBug { ...@@ -145,27 +146,26 @@ sub GetBug {
# Retrieves the necessary information about a bug, stores it in the bug cache, # Retrieves the necessary information about a bug, stores it in the bug cache,
# and returns it to the calling code. # and returns it to the calling code.
my ($id) = @_; my ($id) = @_;
my $dbh = Bugzilla->dbh;
my $bug = {}; my $bug = {};
if (Bugzilla->user->can_see_bug($id)) { if (Bugzilla->user->can_see_bug($id)) {
SendSQL("SELECT 1, ($bug->{'exists'},
$bug->{'status'},
$bug->{'summary'},
$bug->{'milestone'},
$bug->{'assignee_id'},
$bug->{'assignee_email'}) = $dbh->selectrow_array(
"SELECT 1,
bug_status, bug_status,
short_desc, short_desc,
$milestone_column, $milestone_column,
assignee.userid, assignee.userid,
assignee.login_name assignee.login_name
FROM bugs FROM bugs
INNER JOIN profiles AS assignee INNER JOIN profiles AS assignee
ON bugs.assigned_to = assignee.userid ON bugs.assigned_to = assignee.userid
WHERE bugs.bug_id = $id"); WHERE bugs.bug_id = ?", undef, $id);
($bug->{'exists'},
$bug->{'status'},
$bug->{'summary'},
$bug->{'milestone'},
$bug->{'assignee_id'},
$bug->{'assignee_email'}) = FetchSQLData();
} }
$bug->{'open'} = $bug->{'exists'} && IsOpenedState($bug->{'status'}); $bug->{'open'} = $bug->{'exists'} && IsOpenedState($bug->{'status'});
...@@ -176,19 +176,17 @@ sub GetBug { ...@@ -176,19 +176,17 @@ sub GetBug {
sub GetDependencies { sub GetDependencies {
# Returns a list of dependencies for a given bug. # Returns a list of dependencies for a given bug.
my ($id, $relationship) = @_; my ($id, $relationship) = @_;
my $dbh = Bugzilla->dbh;
my $bug_type = ($relationship eq "blocked") ? "dependson" : "blocked"; my $bug_type = ($relationship eq "blocked") ? "dependson" : "blocked";
SendSQL(" SELECT $relationship my $dependencies = $dbh->selectcol_arrayref(
"SELECT $relationship
FROM dependencies FROM dependencies
WHERE $bug_type = $id WHERE $bug_type = ?
ORDER BY $relationship"); ORDER BY $relationship", undef, $id);
my @dependencies = ();
push(@dependencies, FetchOneColumn()) while MoreSQLData();
return @dependencies; return @$dependencies;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment