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
{
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;
}
--- /dev/null
+#
+# 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;
@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 = "";
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;
import DXSql;
if (DXSql::init()) {
- $dbh = DXSql->new($dsn, $dbuser, $dbpass);
+ $dbh = DXSql->new($dsn);
+ $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh;
}
}