From a472851a7e290dac262131fd7f73b567332df6e4 Mon Sep 17 00:00:00 2001 From: minima Date: Wed, 21 Dec 2005 16:21:46 +0000 Subject: [PATCH] add DXSql module and condiational processing --- perl/DXSql.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++ perl/DXVars.pm.issue | 20 +++++++----------- perl/cluster.pl | 15 ++++++++++++- 3 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 perl/DXSql.pm diff --git a/perl/DXSql.pm b/perl/DXSql.pm new file mode 100644 index 00000000..932b9b0e --- /dev/null +++ b/perl/DXSql.pm @@ -0,0 +1,50 @@ +# +# The master SQL module +# +# $Id$ +# +# Copyright (c) 2006 Dirk Koopman G1TLH +# + +package DXSql; + +use strict; + +our $active = 0; + +sub init +{ + return $active if $active; + + eval { + require DBI; + }; + unless ($@) { + import DBI; + $active++; + } + return $active; +} + +sub new +{ + my $class = shift; + my $dsn = shift; + my $user = shift; + my $passwd = shift; + my $self; + + return undef unless $active; + my $dbh; + eval {$dbh = DBI->connect($dsn, $user, $passwd); }; + $self = bless {dbh => $dbh}, $class if $dbh; + return $self; +} + +sub finish +{ + my $self = shift; + $self->{dbh}->disconnect; +} +1; + diff --git a/perl/DXVars.pm.issue b/perl/DXVars.pm.issue index 1433d080..c8e0cc8d 100644 --- a/perl/DXVars.pm.issue +++ b/perl/DXVars.pm.issue @@ -9,19 +9,6 @@ package main; -require Exporter; -@ISA = qw(Exporter); - -@EXPORT_OK = qw($mycall $myname $myalias $mylatitude $mylongtitude $mylocator - $myqth $myemail $myprot_version - $clusterport $clusteraddr $debugfn - $def_hopcount $data $system $cmd - $userfn $motd $local_cmd $mybbsaddr - $lang @my_cc - $pc50_interval $user_interval - ); - - # this really does need to change for your system!!!! # use CAPITAL LETTERS $mycall = "GB7DJK"; @@ -98,3 +85,10 @@ $motd = "$data/motd"; # are we debugging ? @debug = qw(chan state msg cron connect); + +# the SQL database DBI dsn +#$dsn = "dbi:sqlite:$root/data/dxspider.db"; +#$dbuser = ""; +#$dbpass = ""; + +1; diff --git a/perl/cluster.pl b/perl/cluster.pl index d2392ceb..2510c940 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -116,7 +116,7 @@ use strict; use vars qw(@inqueue $systime $version $starttime $lockfn @outstanding_connects $zombies $root @listeners $lang $myalias @debug $userfn $clusteraddr $clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting - $allowdxby + $allowdxby $dbh $dsn $dbuser $dbpass ); @inqueue = (); # the main input queue, an array of hashes @@ -287,6 +287,9 @@ sub cease Log('cluster', "DXSpider V$version, build $build ended"); dbgclose(); Logclose(); + + $dbh->finish if $dbh; + unlink $lockfn; # $SIG{__WARN__} = $SIG{__DIE__} = sub {my $a = shift; cluck($a); }; exit(0); @@ -351,6 +354,16 @@ $year += 1900; dbg("Copyright (c) 1998-$year Dirk Koopman G1TLH"); dbg("DXSpider Version $version, build $build started"); +# try to load the database +if ($dsn && -e "$root/perl/DXSql.pm") { + require DXSql; + import DXSql; + + if (DXSql::init()) { + $dbh = DXSql->new($dsn, $dbuser, $dbpass); + } +} + # load Prefixes dbg("loading prefixes ..."); dbg(USDB::init()); -- 2.43.0