Navigation Menu

Skip to content

Commit

Permalink
Attempt fix the parent/child DB access with two DB handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac G committed Sep 15, 2011
1 parent bf18ef6 commit ebcc66a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2011-09-15 .74
* Merged in the testing branch to get two DB handles to avoid the parent
and child process from conflicting by using the same handle.
- IsaacG

2011-08-12 .73
* Sort nicknames show in case-insensitive alphabetical order by VinzNL.
- IsaacG
Expand Down
18 changes: 14 additions & 4 deletions stalker.pl
Expand Up @@ -8,15 +8,15 @@
# DBI
# DBD::SQLite

$VERSION = '0.73';
$VERSION = '0.74';
%IRSSI = (
authors => 'SymKat',
contact => 'symkat@symkat.com',
name => "stalker",
decsription => 'Records and correlates nick!user@host information',
license => "BSD",
url => "http://github.com/symkat/stalker",
changed => "2011-08-12",
changed => "2011-09-15",
changes => "See Change Log",
);

Expand Down Expand Up @@ -74,6 +74,16 @@
}
) or die "Failed to connect to database $db: " . $DBI::errstr;

# DBI::SQLite and fork() don't mix. Do it anyhow but keep the parent and child DBH separate?
# Ideally the child should open its own connection.
my $DBH_child = DBI->connect(
'dbi:SQLite:dbname='.$db, "", "",
{
RaiseError => 1,
AutoCommit => 1,
}
) or die "Failed to connect to database $db: " . $DBI::errstr;

# async data
my @records_to_add; # Queue of records to add
my $child_running = 0; # child pid that is running
Expand Down Expand Up @@ -280,7 +290,7 @@ sub db_add_record

# Check if we already have this record.
my $q = "SELECT nick FROM records WHERE nick = ? AND user = ? AND host = ? AND serv = ?";
my $sth = $DBH->prepare( $q );
my $sth = $DBH_child->prepare( $q );
$sth->execute( $nick, $user, $host, $serv );
my $result = $sth->fetchrow_hashref;

Expand All @@ -292,7 +302,7 @@ sub db_add_record
debugPrint( "info", "Adding to DB: nick = $nick, user = $user, host = $host, serv = $serv" );

# We don't have the record, add it.
$sth = $DBH->prepare
$sth = $DBH_child->prepare
("INSERT INTO records (nick,user,host,serv) VALUES( ?, ?, ?, ? )" );
eval { $sth->execute( $nick, $user, $host, $serv ) };
if ($@) {
Expand Down

0 comments on commit ebcc66a

Please sign in to comment.