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

Bugzilla/Auth/Login/WWW/CGI.pm
Bugzilla/Auth/Login/WWW/Env.pm
attachment.cgi
checksetup.pl
contrib/bug_email.pl
editgroups.cgi
editproducts.cgi
editusers.cgi
importxml.pl
post_bug.cgi

index 10eb85f60ec901c8962fb6d63ceba4a926756deb..98999a3680212c2fbd6848a7d6c6f1132b2664e9 100644 (file)
@@ -72,7 +72,7 @@ sub login {
                  VALUES (?, ?, NOW())",
                  undef,
                  $userid, $ipaddr);
-        my $logincookie = $dbh->selectrow_array("SELECT LAST_INSERT_ID()");
+        my $logincookie = $dbh->bz_last_key('logincookies', 'cookie');
 
         # Remember cookie only if admin has told so
         # or admin didn't forbid it and user told to remember.
index abd17631586bfedd02468dd587fef7f06eb1bb2f..54e202bbf2a7c8482263b4963167892bf65b9015 100644 (file)
@@ -116,9 +116,7 @@ sub login {
                                      "realname, disabledtext " .
                                      ") VALUES ( ?, ?, ?, '' )");
                 $sth->execute($env_email, '*', $env_realname);
-                $sth = $dbh->prepare("SELECT last_insert_id()");
-                $sth->execute();
-                $matched_userid = $sth->fetch->[0];
+                $matched_userid = $dbh->bz_last_key('profiles', 'userid');
             }
         }
     }
index 5e10d8feefcc6c7293aea2fc68c9dc26266b1a69..3522f9e26f01e2816852fcd910f7305a68516370 100755 (executable)
@@ -869,7 +869,8 @@ sub insert
   my ($data) = @_;
 
   # Insert a new attachment into the database.
-
+  my $dbh = Bugzilla->dbh;
+  
   # Escape characters in strings that will be used in SQL statements.
   $filename = SqlQuote($filename);
   my $description = SqlQuote($::FORM{'description'});
@@ -886,8 +887,7 @@ sub insert
            VALUES ($::FORM{'bugid'}, $sql_timestamp, $filename, $description, $contenttype, $::FORM{'ispatch'}, $isprivate, $::userid, $thedata)");
 
   # Retrieve the ID of the newly created attachment record.
-  SendSQL("SELECT LAST_INSERT_ID()");
-  my $attachid = FetchOneColumn();
+  my $attachid = $dbh->bz_last_key('attachments', 'attach_id');
 
   # Insert a comment about the new attachment into the database.
   my $comment = "Created an attachment (id=$attachid)\n$::FORM{'description'}\n";
index 79095ee3adcda1a4247018c286cde0cf6dbe80d4..388703ab1d361116a218d9d586d0d96d1323f656 100755 (executable)
@@ -2232,9 +2232,7 @@ sub AddGroup {
                           VALUES (?, ?, ?, ?)');
     $sth->execute($name, $desc, $userregexp, 0);
 
-    $sth = $dbh->prepare("select last_insert_id()");
-    $sth->execute();
-    my ($last) = $sth->fetchrow_array();
+    my $last = $dbh->bz_last_key('groups', 'id');
     return $last;
 }
 
@@ -2459,9 +2457,8 @@ unless ($sth->rows) {
              'bugzilla.", "", 0, 0, 0)');
     # We could probably just assume that this is "1", but better
     # safe than sorry...
-    $sth = $dbh->prepare("SELECT LAST_INSERT_ID()");
-    $sth->execute;
-    my ($product_id) = $sth->fetchrow_array;
+    my $product_id = $dbh->bz_last_key('products', 'id');
+    
     $dbh->do(qq{INSERT INTO versions (value, product_id) VALUES ("other", $product_id)});
     # note: since admin user is not yet known, components gets a 0 for 
     # initialowner and this is fixed during final checks.
@@ -2801,9 +2798,7 @@ if (GetFieldDef('bugs', 'long_desc')) {
                                  $dbh->quote($name) .
                                  ", " . $dbh->quote(bz_crypt('okthen')) . ", " . 
                                  "'Account created only to maintain database integrity')");
-                        $s2 = $dbh->prepare("SELECT LAST_INSERT_ID()");
-                        $s2->execute();
-                        ($who) = ($s2->fetchrow_array());
+                        $who = $dbh->bz_last_key('profiles', 'userid');
                     }
                     next;
                 } else {
@@ -2850,9 +2845,7 @@ if (GetFieldDef('bugs_activity', 'field')) {
         if (!$id) {
             $dbh->do("INSERT INTO fielddefs (name, description) VALUES " .
                      "($q, $q)");
-            $s2 = $dbh->prepare("SELECT LAST_INSERT_ID()");
-            $s2->execute();
-            ($id) = ($s2->fetchrow_array());
+            $id = $dbh->bz_last_key('fielddefs', 'fieldid');
         }
         $dbh->do("UPDATE bugs_activity SET fieldid = $id WHERE field = $q");
     }
index 1f2f28421152688f1fcac92481d6e9369b32b7a0..7fb6b533c1f6420eea0605964bfc55cbc1efe2ab 100755 (executable)
@@ -38,7 +38,7 @@
 #
 # You need to work with bug_email.pl the MIME::Parser installed.
 # 
-# $Id: bug_email.pl,v 1.23 2005/02/08 16:51:03 travis%sedsystems.ca Exp $
+# $Id: bug_email.pl,v 1.24 2005/02/18 16:01:48 mkanat%kerio.com Exp $
 ###############################################################
 
 # 02/12/2000 (SML)
@@ -1151,8 +1151,7 @@ END
     if( ! $test ) {
        SendSQL($query);
 
-       SendSQL("select LAST_INSERT_ID()");
-       $id = FetchOneColumn();
+       $id = Bugzilla->dbh->bz_last_key('bugs', 'bug_id');
 
        my $long_desc_query = "INSERT INTO longdescs SET bug_id=$id, who=$userid, bug_when=\'$bug_when\', thetext=" . SqlQuote($comment);
        SendSQL($long_desc_query);
index c3be719c7546ce7feaae840c3f6eabc278bb27a1..02f24b1e4ddfc313b2b0ce467bf6ca43871fb39a 100755 (executable)
@@ -274,8 +274,7 @@ if ($action eq 'new') {
             "1," .
             SqlQuote($regexp) . ", " . 
             $isactive . ", NOW())" );
-    SendSQL("SELECT last_insert_id()");
-    my $gid = FetchOneColumn();
+    my $gid = $dbh->bz_last_key('groups', 'id');
     my $admin = GroupNameToId('admin');
     # Since we created a new group, give the "admin" group all privileges
     # initially.
index f066f70293006bdb72b56ca1afdd3670b843b86c..11658c29ac789953e6d91c0a9019bff83eeb5155 100755 (executable)
@@ -506,8 +506,7 @@ if ($action eq 'new') {
             SqlQuote($votestoconfirm) . "," .
             SqlQuote($defaultmilestone) . "," .
             SqlQuote($classification_id) . ")");
-    SendSQL("SELECT LAST_INSERT_ID()");
-    my $product_id = FetchOneColumn();
+    my $product_id = $dbh->bz_last_key('products', 'id');
 
     SendSQL("INSERT INTO versions ( " .
           "value, product_id" .
@@ -531,8 +530,7 @@ if ($action eq 'new') {
                 "VALUES (" .
                 SqlQuote($productgroup) . ", " .
                 SqlQuote("Access to bugs in the $product product") . ", 1, NOW())");
-        SendSQL("SELECT last_insert_id()");
-        my $gid = FetchOneColumn();
+        my $gid = $dbh->bz_last_key('groups', 'id');
         my $admin = GroupNameToId('admin');
         # If we created a new group, give the "admin" group priviledges
         # initially.
index 9c8de616407b93655c72818b25d6ca96b8d6ca5b..9a6de0d1748d839238e99fce0fae242f269782df 100755 (executable)
@@ -461,8 +461,7 @@ if ($action eq 'new') {
     #+++ send e-mail away
 
     print "OK, done.<br>\n";
-    SendSQL("SELECT last_insert_id()");
-    my ($newuserid) = FetchSQLData();
+    my $newuserid = $dbh->bz_last_key('profiles', 'userid');
 
     my $changeduser = new Bugzilla::User($newuserid);
     $changeduser->derive_groups();
index 21d962d414c9a6b180c8040670d9190965cf425c..3b3b24a176c05b1d1614e04386513a1f95fd4907 100755 (executable)
@@ -162,6 +162,7 @@ $xml =~ s/^.+(<\?xml version.+)$/$1/s;
 
 my $parser = new XML::Parser(Style => 'Tree');
 my $tree = $parser->parse($xml);
+my $dbh = Bugzilla->dbh;
 
 my $maintainer;
 if (defined $tree->[1][0]->{'maintainer'}) {
@@ -609,8 +610,7 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
                . join (",\n", @values)
                . "\n)\n";
   SendSQL($query);
-  SendSQL("select LAST_INSERT_ID()");
-  my $id = FetchOneColumn();
+  my $id = $dbh->bz_last_key('bugs', 'bug_id');
 
   if (defined $bug_fields{'cc'}) {
     foreach my $person (split(/[ ,]/, $bug_fields{'cc'})) {
index 0f5abddb267312e0c1740a4a2ee692dc74393f18..3e5b289a8a5a85b3cf2c67bf5b468e4db64aecf1 100755 (executable)
@@ -56,6 +56,8 @@ my $user = Bugzilla->login(LOGIN_REQUIRED);
 
 my $cgi = Bugzilla->cgi;
 
+my $dbh = Bugzilla->dbh;
+
 # do a match on the fields if applicable
 
 &Bugzilla::User::match_field ({
@@ -420,8 +422,7 @@ while (MoreSQLData()) {
 SendSQL($sql);
 
 # Get the bug ID back.
-SendSQL("select LAST_INSERT_ID()");
-my $id = FetchOneColumn();
+my $id = $dbh->bz_last_key('bugs', 'bug_id');
 
 # Add the group restrictions
 foreach my $grouptoadd (@groupstoadd) {