package # hide this package from CPAN indexer
# once we've been loaded we don't want perl to load the real Win32::ODBC
$INC{'Win32/ODBC.pm'} = $INC{'Win32/DBIODBC.pm'} || 1;
#my $db = new Win32::ODBC("DSN=$self->{'DSN'};UID=$self->{'UID'};PWD=$self->{'PWD'};");
#EMU --- my $db = new Win32::ODBC("DSN=$DSN;UID=$login;PWD=$password;");
# [R] self-hack to allow empty UID and PWD
$connect_line=~/DSN=\w+/;
$temp_connect_line="$&;";
if ($connect_line=~/UID=\w?/)
{$temp_connect_line.="$&;";}
else {$temp_connect_line.="UID=;";};
if ($connect_line=~/PWD=\w?/)
{$temp_connect_line.="$&;";}
else {$temp_connect_line.="PWD=;";};
$connect_line=$temp_connect_line;
/^(DSN=)(.*)(;UID=)(.*)(;PWD=)(.*)(;)$/;
#---- DBI CONNECTION VARIABLES
#---- DBI CONNECTION VARIABLES
$self->{DBI_DBNAME
}=$self->{ODBC_DSN
};
$self->{DBI_USER
}=$self->{ODBC_UID
};
$self->{DBI_PASSWORD
}=$self->{ODBC_PWD
};
$self->{'DBI_DBH'}=DBI
->connect($self->{'DBI_DBNAME'},
$self->{'DBI_USER'},$self->{'DBI_PASSWORD'},$self->{'DBI_DBD'});
warn "Error($DBI::err) : $DBI::errstr\n" if ! $self->{'DBI_DBH'};
#EMU --- $db->Sql('SELECT * FROM DUAL');
# print " SQL : $SQL_statment \n";
$self->{'DBI_SQL_STATMENT'}=$SQL_statment;
my $dbh=$self->{'DBI_DBH'};
# print " DBH : $dbh \n";
my $sth=$dbh->prepare("$SQL_statment");
# print " STH : $sth \n";
$self->{DBI_ERR
}=$DBI::err
;
$self->{DBI_ERRSTR
}=$DBI::errstr
;
$self->{'DBI_NAME'} = $sth->{NAME
};
# [R] provide compatibility with Win32::ODBC's way of identifying erraneous SQL statements
return ($self->{'DBI_ERR'})?
1:undef;
#EMU --- $db->FetchRow())
my $sth=$self->{'DBI_STH'};
my @row=$sth->fetchrow_array;
$self->{'DBI_ROW'}=\
@row;
#-- the row of result is not nul
#-- return somthing nothing will be return else
# [R] provide compatibility with Win32::ODBC's Data() method.
my @array=@
{$self->{'DBI_ROW'}};
foreach my $element (@array)
# remove padding of spaces by DBI
return (wantarray())?
@array:join('', @array);
#EMU --- %record = $db->DataHash;
my $p_name=$self->{'DBI_NAME'};
my $p_row=$self->{'DBI_ROW'};
#print @name; print "\n"; print @row;
# [R] new code that seems to work consistent with Win32::ODBC
# remove padding of spaces by DBI
# [R] old code that didn't appear to work
# foreach my $name (@name)
# $name=~s/(^\s*)|(\s*$)//;
# print "lot $name name col $_ or ROW= 0 $row[0] 1 $row[1] 2 $row[2] \n ";
# $DataHash{$name}=shift(@row);
if ($self->{'DBI_ERR'} ne '')
#--- Return error message
#-- else good no error message
# [R] provide compatibility with Win32::ODBC's Close() method.
my $dbh=$self->{'DBI_DBH'};
# [R] to -[R]- indicate sections edited by me, Roy Lee
Win32::DBIODBC - Win32::ODBC emulation layer for the DBI
use Win32::DBIODBC; # instead of use Win32::ODBC
This is a I<very> basic I<very> alpha quality Win32::ODBC emulation
for the DBI. To use it just replace
or, while experimenting, you can pre-load this module without changing your
perl -MWin32::DBIODBC your_script_name
Error handling is virtually non-existant.
Tom Horen <tho@melexis.com>