Commit 62eecf24 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 280494: Replace "SELECT LAST_INSERT_ID()" with Bugzilla::DB function call

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