Bug 280497: Replace "LIMIT" with Bugzilla::DB function call

Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat,a=justdave
This commit is contained in:
mkanat%kerio.com 2005-02-18 16:14:27 +00:00
parent d062676ab0
commit a570c5ec1b
11 changed files with 42 additions and 26 deletions

View File

@ -1393,6 +1393,8 @@ sub ListIDsForEmail {
my $old = $self->{"emailcache"}{"$type,$email"};
return undef if ($old && $old eq "---");
return $old if $old;
my $dbh = Bugzilla->dbh;
my @list = ();
my $list = "---";
if ($type eq 'anyexact') {
@ -1406,7 +1408,7 @@ sub ListIDsForEmail {
$list = join(',', @list);
} elsif ($type eq 'substring') {
&::SendSQL("SELECT userid FROM profiles WHERE INSTR(login_name, " .
&::SqlQuote($email) . ") LIMIT 51");
&::SqlQuote($email) . ") " . $dbh->sql_limit(51));
while (&::MoreSQLData()) {
my ($id) = &::FetchSQLData();
push(@list, $id);

View File

@ -260,10 +260,11 @@ sub HasEmailChangeToken {
# Returns an email change token if the user has one.
my ($userid) = @_;
my $dbh = Bugzilla->dbh;
&::SendSQL("SELECT token FROM tokens WHERE userid = $userid " .
"AND (tokentype = 'emailnew' OR tokentype = 'emailold') " .
"LIMIT 1");
$dbh->sql_limit(1));
my ($token) = &::FetchSQLData();
return $token;

View File

@ -539,6 +539,7 @@ sub match {
my $wildstr = $str;
my $user = Bugzilla->user;
my $dbh = Bugzilla->dbh;
if ($wildstr =~ s/\*/\%/g && # don't do wildcards if no '*' in the string
Param('usermatchmode') ne 'off') { # or if we only want exact matches
@ -561,7 +562,7 @@ sub match {
}
$query .= " AND disabledtext = '' " if $exclude_disabled;
$query .= "ORDER BY length(login_name) ";
$query .= "LIMIT $limit " if $limit;
$query .= $dbh->sql_limit($limit) if $limit;
# Execute the query, retrieve the results, and make them into
# User objects.
@ -611,7 +612,7 @@ sub match {
}
$query .= " AND disabledtext = '' " if $exclude_disabled;
$query .= "ORDER BY length(login_name) ";
$query .= "LIMIT $limit " if $limit;
$query .= $dbh->sql_limit($limit) if $limit;
&::PushGlobalSQLState();
&::SendSQL($query);
push(@users, new Bugzilla::User(&::FetchSQLData())) while &::MoreSQLData();

View File

@ -294,8 +294,8 @@ sub GetQuip {
. " FROM quips WHERE approved = 1");
my $random = int(rand($count));
my $quip =
$dbh->selectrow_array("SELECT quip FROM quips"
. " WHERE approved = 1 LIMIT $random,1");
$dbh->selectrow_array("SELECT quip FROM quips WHERE approved = 1 " .
$dbh->sql_limit(1, $random));
return $quip;
}
@ -746,10 +746,10 @@ my $search = new Bugzilla::Search('fields' => \@selectnames,
my $query = $search->getSQL();
if ($::FORM{'limit'} && detaint_natural($::FORM{'limit'})) {
$query .= " LIMIT $::FORM{'limit'}";
$query .= " " . $dbh->sql_limit($::FORM{'limit'});
}
elsif ($fulltext) {
$query .= " LIMIT 200";
$query .= " " . $dbh->sql_limit(200);
}

View File

@ -3552,7 +3552,9 @@ if (($fielddef = GetFieldDef("attachments", "creation_ts")) &&
# Restrict this as much as possible in order to avoid false positives, and
# keep the db search time down
my $sth2 = $dbh->prepare("SELECT bug_when FROM longdescs WHERE bug_id=? AND who=? AND thetext LIKE ? ORDER BY bug_when LIMIT 1");
my $sth2 = $dbh->prepare("SELECT bug_when FROM longdescs
WHERE bug_id=? AND who=? AND thetext LIKE ?
ORDER BY bug_when " . $dbh->sql_limit(1));
while (my ($bug_id, $attach_id, $submitter_id) = $sth->fetchrow_array()) {
$sth2->execute($bug_id, $submitter_id, "Created an attachment (id=$attach_id)%");
my ($when) = $sth2->fetchrow_array();
@ -4037,8 +4039,8 @@ if (TableExists("user_series_map")) {
# 2003-06-26 Copy the old charting data into the database, and create the
# queries that will keep it all running. When the old charting system goes
# away, if this code ever runs, it'll just find no files and do nothing.
my $series_exists = $dbh->selectrow_array("SELECT 1 FROM series LIMIT 1");
my $series_exists = $dbh->selectrow_array("SELECT 1 FROM series " .
$dbh->sql_limit(1));
if (!$series_exists) {
print "Migrating old chart data into database ...\n" unless $silent;

View File

@ -258,8 +258,9 @@ sub calculate_dupes {
sub regenerate_stats {
my $dir = shift;
my $product = shift;
my $when = localtime(time());
my $dbh = Bugzilla->dbh;
my $when = localtime(time());
my $tstart = time();
# NB: Need to mangle the product for the filename, but use the real
@ -287,7 +288,7 @@ sub regenerate_stats {
"to_days('1970-01-01') " .
"FROM bugs $from_product WHERE to_days(creation_ts) != 'NULL' " .
$and_product .
"ORDER BY start LIMIT 1");
"ORDER BY start " . $dbh->sql_limit(1));
my ($start, $end, $base) = FetchSQLData();
if (!defined $start) {
@ -353,7 +354,8 @@ FIN
"AND fielddefs.name = 'bug_status' " .
"AND bugs_activity.bug_id = $bug " .
"AND bugs_activity.bug_when >= from_days($day) " .
"ORDER BY bugs_activity.bug_when LIMIT 1");
"ORDER BY bugs_activity.bug_when " .
$dbh->sql_limit(1));
my $status;
if (@row = FetchSQLData()) {
@ -374,7 +376,8 @@ FIN
"AND fielddefs.name = 'resolution' " .
"AND bugs_activity.bug_id = $bug " .
"AND bugs_activity.bug_when >= from_days($day) " .
"ORDER BY bugs_activity.bug_when LIMIT 1");
"ORDER BY bugs_activity.bug_when " .
$dbh->sql_limit(1));
if (@row = FetchSQLData()) {
$status = $row[0];

View File

@ -386,10 +386,11 @@ sub AnyEntryGroups {
$product_id = 0 unless ($product_id);
return $::CachedAnyEntryGroups{$product_id}
if defined($::CachedAnyEntryGroups{$product_id});
my $dbh = Bugzilla->dbh;
PushGlobalSQLState();
my $query = "SELECT 1 FROM group_control_map WHERE entry != 0";
$query .= " AND product_id = $product_id" if ($product_id);
$query .= " LIMIT 1";
$query .= " " . $dbh->sql_limit(1);
SendSQL($query);
if (MoreSQLData()) {
$::CachedAnyEntryGroups{$product_id} = MoreSQLData();
@ -406,13 +407,14 @@ sub AnyEntryGroups {
# one bug to another.
sub AnyDefaultGroups {
return $::CachedAnyDefaultGroups if defined($::CachedAnyDefaultGroups);
my $dbh = Bugzilla->dbh;
PushGlobalSQLState();
SendSQL("SELECT 1 FROM group_control_map, groups WHERE " .
"groups.id = group_control_map.group_id " .
"AND isactive != 0 AND " .
"(membercontrol = " . CONTROLMAPDEFAULT .
" OR othercontrol = " . CONTROLMAPDEFAULT .
") LIMIT 1");
") " . $dbh->sql_limit(1));
$::CachedAnyDefaultGroups = MoreSQLData();
FetchSQLData();
PopGlobalSQLState();
@ -424,6 +426,7 @@ sub AnyDefaultGroups {
# bugs in this product at all.
sub CanEditProductId {
my ($productid) = @_;
my $dbh = Bugzilla->dbh;
my $query = "SELECT group_id FROM group_control_map " .
"WHERE product_id = $productid " .
"AND canedit != 0 ";
@ -431,7 +434,7 @@ sub CanEditProductId {
$query .= "AND group_id NOT IN(" .
join(',', values(%{Bugzilla->user->groups})) . ") ";
}
$query .= "LIMIT 1";
$query .= $dbh->sql_limit(1);
PushGlobalSQLState();
SendSQL($query);
my ($result) = FetchSQLData();
@ -462,6 +465,7 @@ sub IsInClassification {
# product.
sub CanEnterProduct {
my ($productname) = @_;
my $dbh = Bugzilla->dbh;
my $query = "SELECT group_id IS NULL " .
"FROM products " .
"LEFT JOIN group_control_map " .
@ -471,7 +475,8 @@ sub CanEnterProduct {
$query .= "AND group_id NOT IN(" .
join(',', values(%{Bugzilla->user->groups})) . ") ";
}
$query .= "WHERE products.name = " . SqlQuote($productname) . " LIMIT 1";
$query .= "WHERE products.name = " . SqlQuote($productname) . " " .
$dbh->sql_limit(1);
PushGlobalSQLState();
SendSQL($query);
my ($ret) = FetchSQLData();

View File

@ -696,7 +696,7 @@ if ($::FORM{'product'} ne $::FORM{'dontchange'}) {
$::query .= "product_id = $prod_id";
} else {
SendSQL("SELECT DISTINCT product_id FROM bugs WHERE bug_id IN (" .
join(',', @idlist) . ") LIMIT 2");
join(',', @idlist) . ") " . $dbh->sql_limit(2));
$prod_id = FetchOneColumn();
$prod_id = undef if (FetchOneColumn());
}

View File

@ -118,7 +118,7 @@ if (defined $cgi->param('rebuildvotecache')) {
if (defined $cgi->param('rederivegroups')) {
Status("OK, All users' inherited permissions will be rechecked when " .
"they next access Bugzilla.");
SendSQL("UPDATE groups SET last_changed = NOW() LIMIT 1");
SendSQL("UPDATE groups SET last_changed = NOW() " . $dbh->sql_limit(1));
}
# rederivegroupsnow is REALLY only for testing.
@ -152,8 +152,8 @@ if (defined $cgi->param('cleangroupsnow')) {
$dbh->bz_lock_tables('user_group_map WRITE', 'profiles WRITE');
SendSQL("SELECT userid FROM profiles " .
"WHERE refreshed_when > 0 " .
"AND refreshed_when < " . SqlQuote($cutoff) .
" LIMIT 1000");
"AND refreshed_when < " . SqlQuote($cutoff) . " " .
$dbh->sql_limit(1000));
my $count = 0;
while ((my $id) = FetchSQLData()) {
$count++;

View File

@ -49,6 +49,7 @@ my @reasons = ("Removeme", "Comments", "Attachments", "Status", "Resolved",
# SaveFoo may be called before DoFoo.
###############################################################################
sub DoAccount {
my $dbh = Bugzilla->dbh;
SendSQL("SELECT realname FROM profiles WHERE userid = $userid");
$vars->{'realname'} = FetchSQLData();
@ -57,7 +58,7 @@ sub DoAccount {
FROM tokens
WHERE userid = $userid
AND tokentype LIKE 'email%'
ORDER BY tokentype ASC LIMIT 1");
ORDER BY tokentype ASC " . $dbh->sql_limit(1));
if(MoreSQLData()) {
my ($tokentype, $change_date, $eventdata) = &::FetchSQLData();
$vars->{'login_change_date'} = $change_date;

View File

@ -69,7 +69,8 @@ my $sth_next_scheduled_event = $dbh->prepare(
"LEFT JOIN whine_events " .
" ON whine_events.id = whine_schedules.eventid " .
"WHERE run_next <= NOW() " .
"ORDER BY run_next LIMIT 1"
"ORDER BY run_next " .
$dbh->sql_limit(1)
);
# get all pending schedules matching an eventid