]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 280497: Replace "LIMIT" with Bugzilla::DB function call
authormkanat%kerio.com <>
Sat, 19 Feb 2005 00:14:26 +0000 (00:14 +0000)
committermkanat%kerio.com <>
Sat, 19 Feb 2005 00:14:26 +0000 (00:14 +0000)
Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat,a=justdave

Bugzilla/Search.pm
Bugzilla/Token.pm
Bugzilla/User.pm
buglist.cgi
checksetup.pl
collectstats.pl
globals.pl
process_bug.cgi
sanitycheck.cgi
userprefs.cgi
whine.pl

index 7740e74022d2dd983b6169fbefe6ceec31de041f..816b4b0a19fac6d0103bc886befa9538ab32938d 100644 (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);
index 9caf91ab2a92de7c0166150dd678a09c0e14ea1a..5484308472f833b707eba5f6c0d1a0f54cf8e42d 100644 (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;
index 67b79f16873815ebf8ce479db71a7f0b87bee273..0a67400b3dc61255e098ba717dd96f56602d55a1 100644 (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();
index 65391f77909d13c7d13a9192c1489030ad4ad491..4b9bc960f163e27b819d609a551a7ecf6eb02ace 100755 (executable)
@@ -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);
 }
 
 
index 388703ab1d361116a218d9d586d0d96d1323f656..350c71243ea409ceb85336c51a248d147ada9995 100755 (executable)
@@ -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;
     
index 23d01bbc42677b8c1f386fc9ea762b0006f41638..cf863f4056cad533a7d0a89a69b725ff07e84660 100755 (executable)
@@ -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];
index 1bd53261f3220cfc63b225ab6217e72ada56035a..9ea60c48bcbd2ca2b0500d633312381b8830b1af 100644 (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();
index abbad43f9287adb5f40fa078e07643227729dd2b..b742062dd08de3894a452c0acf8745079c0be335 100755 (executable)
@@ -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());
 }
index 81afe79c5ff4afa92865dc9cdc4d14df3214ade5..1696a3e7ab84e14f13154a753f4a8b735f5074f5 100755 (executable)
@@ -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++;
index 193a4d73f0a4fb879496f79109c792fe362170ea..a1239ca8f2b94f710ed88b803a9a2f765fa8d2c8 100755 (executable)
@@ -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;
index 0e469e8addfa6aaed176bf138af5035efd0cf587..d3584db681ab19afed1302af2a32c514b4ac4f87 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -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