Jenda has asked for the wisdom of the Perl Monks concerning the following question:

In a script I have something like this:

$db = DBI->connect('dbi:ODBC:'.$DSN, $UID, $PWD, {PrintError => 0,Rais +eError => 1,LongReadLen => 65536}); ... $FetchPagesWithUpdatedTranslations = $db->prepare('exec FetchPagesWith +UpdatedTranslations ?, ?'); # product_id, time ... my $res = $FetchPagesWithUpdatedTranslations->execute( $prodId, SQLtim +e($FILES{':'.$section})); ... sub SQLtime { my $time = shift() || 0; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $year+=1900; $mon++; return "$year-$mon-$mday $hour:$min:$sec"; }
The stored procedure is like this:
CREATE PROCEDURE FetchPagesWithUpdatedTranslations ( @ProductId Int, @Date datetime = NULL ) AS ...
This code works fine with Perl 5.6.1. (ActiveState build 631), but reports
DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Inval +id character value for cast specification (SQL-22018)(DBD: st_execute +/SQLExecute err=-1) at ...
with Perl 5.8 (ActiveState build 804). Both running under Win2k server with MS SQL 2000.

I tried it with DBI 1.30 (from PPM) and DBI 1.32 (compiled by myself) and with DBD::ODBC 0.43 (from PPM), 1.02 and 1.04 (compiled by myself) and it crashed every time.

I also tried to change the stored procedure to

CREATE PROCEDURE FetchPagesWithUpdatedTranslations ( @ProductId Int, @DateS varchar(20) = NULL ) AS ...
and that worked with both 5.6.1 and 5.8. Does anyone have any idea what could be wrong? In this case I can change the stored procedure, but in the future this could be a problem.

Thanks, Jenda

Replies are listed 'Best First'.
Re: Passing dates to MS SQL via DBD::ODBC doesn't work under 5.8
by Jenda (Abbot) on Feb 18, 2003 at 23:12 UTC

    FYI, I contacted Jeff Urlwin via CPAN Request Tracker and he suggested to add

    $exec->bind_param(1, undef, &SQL_VARCHAR);
    which worked fine.

    And then I found out that the "problem" was not related to Perl 5.8 at all. All the time I had DBD::ODBC 0.28 in my 5.6.1. I think I DID try the other versions in 5.6.1, but it seems I did not :-( So now I can confirm that the module behaves the same under 5.6.1 and 5.8 and the difference WAS caused by different version of DBD::ODBC. Sorry to waste everyones' time.

    Jenda