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 {
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.
......
......@@ -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');
}
}
}
......
......@@ -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";
......
......@@ -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");
}
......
......@@ -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);
......
......@@ -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.
......
......@@ -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.
......
......@@ -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();
......
......@@ -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'})) {
......
......@@ -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) {
......
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