in reply to Re^2: Win32::ODBC and MoreResults()
in thread Win32::ODBC and MoreResults()

Did you try it as two separate statements? It should still be in the same transaction -- do you have the transaction BEGIN'd properly? Win32::ODBC supports transactions if the underlying db driver does.

Replies are listed 'Best First'.
Re^4: Win32::ODBC and MoreResults()
by Lyndley (Novice) on Aug 11, 2005 at 13:03 UTC
    Interesting I tried this which is what I think you were suggesting...

    #!perl use Win32::ODBC; my $db=new Win32::ODBC('DB_SERVER'); my $sql="INSERT INTO T_Test (C_Data) VALUES ('data');"; #2 $db->Sql($sql); sleep(20); $sql="SELECT \@\@IDENTITY AS C_ID;"; $db->Sql($sql); $db->FetchRow(); print $db->Data("C_ID")."\n";

    It runs the insert, pauses for 20 seconds, gets the last identity value and outputs to the screen.

    During the 20 second pause you can rerun the same script but without the pause in that version and both versions pull the correct identity value. This can be verified by watching the database through query analyzer. I guess it mean the the @@IDENTITY value must be unique to each session which I didn't realise.... and which of course sorts my main issue so ta for that. =D

    Would still be nice to know why the INSERT-SELECT fails when the SELECT-SELECT works while using MoreResults() if anyone knows though.