aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LXRng/Index/Pg.pm
diff options
context:
space:
mode:
authorArne Georg Gleditsch <argggh@lxr.linpro.no>2007-11-27 01:13:37 +0100
committerArne Georg Gleditsch <argggh@lxr.linpro.no>2007-11-27 01:13:37 +0100
commit828f8807dcc27d236bc9f36b57987fd5cd505f95 (patch)
tree931af80f1c098843dd7f9e824b3542348b9030e2 /lib/LXRng/Index/Pg.pm
parent53aeb447f17030c94cd7c2048929c432a8761aff (diff)
Improve flushing logic,
Diffstat (limited to 'lib/LXRng/Index/Pg.pm')
-rw-r--r--lib/LXRng/Index/Pg.pm26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/LXRng/Index/Pg.pm b/lib/LXRng/Index/Pg.pm
index a385767..7afb2a8 100644
--- a/lib/LXRng/Index/Pg.pm
+++ b/lib/LXRng/Index/Pg.pm
@@ -8,12 +8,16 @@ use base qw(LXRng::Index::DBI);
sub dbh {
my ($self) = @_;
- $$self{'dbh'} ||= DBI->connect('dbi:Pg:'.$$self{'db_spec'},
- $$self{'db_user'}, $$self{'db_pass'},
- {AutoCommit => 1,
- RaiseError => 1})
+ return $$self{'dbh'} if $$self{'dbh'};
+
+ $$self{'dbh'} = DBI->connect('dbi:Pg:'.$$self{'db_spec'},
+ $$self{'db_user'}, $$self{'db_pass'},
+ {AutoCommit => 1,
+ RaiseError => 1,
+ pg_server_prepare => 1})
or die($DBI::errstr);
-
+ $$self{'dbh_pid'} = $$;
+
return $$self{'dbh'};
}
@@ -425,9 +429,15 @@ sub DESTROY {
my ($self) = @_;
if ($$self{'dbh'}) {
- $$self{'dbh'}->rollback();
- $$self{'dbh'}->disconnect();
- delete($$self{'dbh'});
+ if ($$self{'dbh_pid'} != $$) {
+ $$self{'dbh'}->{InactiveDestroy} = 1;
+ undef $$self{'dbh'};
+ }
+ else {
+ $$self{'dbh'}->rollback();
+ $$self{'dbh'}->disconnect();
+ delete($$self{'dbh'});
+ }
}
}