From e5a96ae00d9c44c94cff828e73cadc5352e531ef Mon Sep 17 00:00:00 2001 From: minima Date: Wed, 21 Dec 2005 16:44:03 +0000 Subject: [PATCH] add SQLite special --- perl/DXSql.pm | 37 +++++++++++++++++++++++++++++++++---- perl/DXSql/SQLite.pm | 21 +++++++++++++++++++++ perl/DXVars.pm.issue | 2 +- perl/cluster.pl | 4 ++-- 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 perl/DXSql/SQLite.pm diff --git a/perl/DXSql.pm b/perl/DXSql.pm index 932b9b0e..a327e07e 100644 --- a/perl/DXSql.pm +++ b/perl/DXSql.pm @@ -10,6 +10,12 @@ package DXSql; use strict; +use vars qw($VERSION $BRANCH); +$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); +$main::build += $VERSION; +$main::branch += $BRANCH; + our $active = 0; sub init @@ -30,14 +36,37 @@ 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; + my ($style) = $dsn =~ /^dbi:(\w+):/; + my $newclass = "DXSql::$style"; + eval "require $newclass"; + if ($@) { + $active = 0; + return undef; + } + return bless {}, $newclass; +} + +sub connect +{ + my $self = shift; + my $dsn = shift; + my $user = shift; + my $passwd = shift; + + my $dbh; + eval { + no strict 'refs'; + $dbh = DBI->connect($dsn, $user, $passwd); + }; + unless ($dbh) { + $active = 0; + return undef; + } + $self->{dbh} = $dbh; return $self; } diff --git a/perl/DXSql/SQLite.pm b/perl/DXSql/SQLite.pm new file mode 100644 index 00000000..2f62461c --- /dev/null +++ b/perl/DXSql/SQLite.pm @@ -0,0 +1,21 @@ +# +# Module for SQLite DXSql variants +# +# Stuff like table creates and (later) alters +# +# $Id$ +# +# Copyright (c) 2005 Dirk Koopman G1TLH +# + +package DXSql::SQLite; + +use vars qw($VERSION $BRANCH @ISA); +$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); +$main::build += $VERSION; +$main::branch += $BRANCH; + +@ISA = qw{DXSql}; + +1; diff --git a/perl/DXVars.pm.issue b/perl/DXVars.pm.issue index c8e0cc8d..6370a563 100644 --- a/perl/DXVars.pm.issue +++ b/perl/DXVars.pm.issue @@ -87,7 +87,7 @@ $motd = "$data/motd"; @debug = qw(chan state msg cron connect); # the SQL database DBI dsn -#$dsn = "dbi:sqlite:$root/data/dxspider.db"; +#$dsn = "dbi:SQLite:dbname=$root/data/dxspider.db"; #$dbuser = ""; #$dbpass = ""; diff --git a/perl/cluster.pl b/perl/cluster.pl index 2510c940..9eba29c1 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -133,7 +133,6 @@ $allowdxby = 0; # 1 = allow "dx by ", 0 - don't allow it use vars qw($VERSION $BRANCH $build $branch); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += 1; # add an offset to make it bigger than last system $main::build += $VERSION; $main::branch += $BRANCH; @@ -360,7 +359,8 @@ if ($dsn && -e "$root/perl/DXSql.pm") { import DXSql; if (DXSql::init()) { - $dbh = DXSql->new($dsn, $dbuser, $dbpass); + $dbh = DXSql->new($dsn); + $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh; } } -- 2.43.0