Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Bugzilla connection class, for appending comments to a bug report.
9
 
10
package Codestriker::BugDB::BugzillaConnection;
11
 
12
use strict;
13
use DBI;
14
 
15
# Static method for building a database connection.
16
sub get_connection($) {
17
    my ($type) = @_;
18
 
19
    # Return a connection with the bugzilla database.
20
    my $self = {};
21
    my $dbname = $Codestriker::bug_db_dbname;
22
    $dbname = "bugs" if ($dbname eq "");
23
    $self->{dbh} =
24
	DBI->connect("DBI:mysql:dbname=$dbname;host=$Codestriker::bug_db_host",
25
		     $Codestriker::bug_db_name, $Codestriker::bug_db_password,
26
		     { RaiseError => 1, AutoCommit => 1 });
27
    bless $self, $type;
28
}
29
 
30
# Method for releasing a bugzilla database connection.
31
sub release_connection($) {
32
    my ($self) = @_;
33
 
34
    $self->{dbh}->disconnect;
35
}
36
 
37
# Return true if the specified bugid exists in the bug database,
38
# false otherwise.
39
sub bugid_exists($$) {
40
    my ($self, $bugid) = @_;
41
 
42
    return $self->{dbh}->selectrow_array('SELECT COUNT(*) FROM bugs ' .
43
					 'WHERE bug_id = ?', {}, $bugid) != 0;
44
}
45
 
46
# Method for updating the bug with information that a code review has been
47
# created/closed/committed against this bug.
48
sub update_bug($$$$) {
49
    my ($self, $bugid, $comment) = @_;
50
 
51
    # Create the necessary prepared statements.
52
    my $insert_comment =
53
	$self->{dbh}->prepare_cached('INSERT INTO longdescs ' .
54
				     '(bug_id, who, bug_when, thetext) ' .
55
				     'VALUES (?, ?, now(), ?)');
56
    my $update_bug =
57
	$self->{dbh}->prepare_cached('UPDATE bugs SET delta_ts = now() ' .
58
				     'WHERE bug_id = ?');
59
 
60
    # Execute the statements.
61
    $insert_comment->execute($bugid, $Codestriker::bug_db_user_id, $comment);
62
    $update_bug->execute($bugid);
63
}
64
 
65
1;