add SQLite special
[spider.git] / perl / DXSql.pm
index 932b9b0e2c35dcf871c9e737ab1cc95283bf3851..a327e07e220dc9a52daf5fed9124964eb2159e7a 100644 (file)
@@ -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;
 }