add CTY-3304
[spider.git] / perl / DXSql.pm
index fcf4e4ce5608dd5fc4068f4adb2c19924278483f..9c440fbd48acab19ec7d32d80a83e92f6d18ff3a 100644 (file)
@@ -1,7 +1,7 @@
 #
 # The master SQL module
 #
-# $Id$
+#
 #
 # Copyright (c) 2006 Dirk Koopman G1TLH
 #
@@ -12,16 +12,13 @@ use strict;
 
 use DXDebug;
 
-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;
+use vars qw($active);
+$active = 0;
 
 sub init
 {
+       my $dsn = shift;
+       return unless $dsn;
        return $active if $active;
        
        eval { 
@@ -31,6 +28,7 @@ sub init
                import DBI;
                $active++;
        }
+       undef $@;
        return $active;
 } 
 
@@ -62,7 +60,7 @@ sub connect
        my $dbh;
        eval {
                no strict 'refs';
-               $dbh = DBI->connect($dsn, $user, $passwd, {AutoCommit => 0}); 
+               $dbh = DBI->connect($dsn, $user, $passwd); 
        };
        unless ($dbh) {
                $active = 0;
@@ -86,16 +84,19 @@ sub do
        eval { $self->{dbh}->do($s); }; 
 }
 
+sub begin_work
+{
+       $_[0]->{dbh}->begin_work;
+}
+
 sub commit
 {
        $_[0]->{dbh}->commit;
-       $_[0]->{dbh}->{AutoCommit} = 0;
 }
 
 sub rollback
 {
        $_[0]->{dbh}->rollback;
-       $_[0]->{dbh}->{AutoCommit} = 0;
 }
 
 sub quote
@@ -111,7 +112,7 @@ sub prepare
 sub spot_insert_prepare
 {
        my $self = shift;
-       return $self->prepare('insert into spot values(?' . ',?' x 14 . ')');
+       return $self->prepare('insert into spot values(?' . ',?' x 15 . ')');
 }
 
 sub spot_insert
@@ -121,6 +122,8 @@ sub spot_insert
        my $sth = shift;
        
        if ($sth) {
+               push @$spot, undef while  @$spot < 15;
+               pop @$spot while @$spot > 15;
                eval {$sth->execute(undef, @$spot)};
        } else {
                my $s = "insert into spot values(NULL,";
@@ -137,7 +140,8 @@ sub spot_insert
                $s .= $spot->[10] . ',';
                $s .= $spot->[11] . ',';
                $s .= (length $spot->[12] ? $self->quote($spot->[12]) : 'NULL') . ',';
-               $s .= (length $spot->[13] ? $self->quote($spot->[13]) : 'NULL') . ')';
+               $s .= (length $spot->[13] ? $self->quote($spot->[13]) : 'NULL') . ',';
+               $s .= (length $spot->[14] ? $self->quote($spot->[14]) : 'NULL') . ')';
                eval {$self->do($s)};
        }
 }
@@ -170,7 +174,7 @@ sub spot_search
                $expr =~ s/\$f9/spotcq/g;
                $expr =~ s/\|\|/ or /g;
                $expr =~ s/\&\&/ and /g;
-               $expr =~ s/=~\s+m\{\^([\w]+)[^\}]*\}/ like '$1%'/g;
+               $expr =~ s/=~\s+m\{\^([%\w]+)[^\}]*\}/ like '$1'/g;
        } else {
                $expr = '';
        }