diff options
author | mkanat%kerio.com <> | 2005-02-19 01:14:26 +0100 |
---|---|---|
committer | mkanat%kerio.com <> | 2005-02-19 01:14:26 +0100 |
commit | b9402d3e113b408143c7ad18f1cb798023c7d178 (patch) | |
tree | ead35cce72a5f7be7fa8660561159eca2174185d | |
parent | 62eecf24480520e204ab0057f8f7845c13f37c13 (diff) | |
download | bugzilla-b9402d3e113b408143c7ad18f1cb798023c7d178.tar.gz bugzilla-b9402d3e113b408143c7ad18f1cb798023c7d178.tar.xz |
Bug 280497: Replace "LIMIT" with Bugzilla::DB function call
Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat,a=justdave
-rw-r--r-- | Bugzilla/Search.pm | 4 | ||||
-rw-r--r-- | Bugzilla/Token.pm | 5 | ||||
-rw-r--r-- | Bugzilla/User.pm | 5 | ||||
-rwxr-xr-x | buglist.cgi | 8 | ||||
-rwxr-xr-x | checksetup.pl | 8 | ||||
-rwxr-xr-x | collectstats.pl | 11 | ||||
-rw-r--r-- | globals.pl | 13 | ||||
-rwxr-xr-x | process_bug.cgi | 2 | ||||
-rwxr-xr-x | sanitycheck.cgi | 6 | ||||
-rwxr-xr-x | userprefs.cgi | 3 | ||||
-rwxr-xr-x | whine.pl | 3 |
11 files changed, 42 insertions, 26 deletions
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 7740e7402..816b4b0a1 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -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); diff --git a/Bugzilla/Token.pm b/Bugzilla/Token.pm index 9caf91ab2..548430847 100644 --- a/Bugzilla/Token.pm +++ b/Bugzilla/Token.pm @@ -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; diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index 67b79f168..0a67400b3 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -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(); diff --git a/buglist.cgi b/buglist.cgi index 65391f779..4b9bc960f 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -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); } diff --git a/checksetup.pl b/checksetup.pl index 388703ab1..350c71243 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -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; diff --git a/collectstats.pl b/collectstats.pl index 23d01bbc4..cf863f405 100755 --- a/collectstats.pl +++ b/collectstats.pl @@ -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]; diff --git a/globals.pl b/globals.pl index 1bd53261f..9ea60c48b 100644 --- a/globals.pl +++ b/globals.pl @@ -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(); diff --git a/process_bug.cgi b/process_bug.cgi index abbad43f9..b742062dd 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -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()); } diff --git a/sanitycheck.cgi b/sanitycheck.cgi index 81afe79c5..1696a3e7a 100755 --- a/sanitycheck.cgi +++ b/sanitycheck.cgi @@ -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++; diff --git a/userprefs.cgi b/userprefs.cgi index 193a4d73f..a1239ca8f 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -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; @@ -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 |