I've inherited the following perl code fragment....
1 %Returned = dbPrepare( %Input );
2 if ( $Returned{nStatus} == 0 ) {
3 %Input = ( nDbCursor => $Returned{nDbCursor} );
4 %Returned = dbExecute( %Input );
5 }
6 if ( $Returned{nStatus} == 0 ) {
7 # FINISH CURSOR
8 %Input = ( nDbCursor => $Returned{nDbCursor} );
9 %Returned = dbFinish( %Input );
10 }
11 # SET PROPER RETURN VALUES IF ALL WAS OK
12 if ( $Returned{nStatus} == 0 ) {
13 %Returned = (
14 nStatus => 0,
15 nReturnCode => 0,
16 sReturnDesc => "erLogDataError: Successful"
17 );
18 }
19 return( %Returned );
My environment: AIX 4.3.3, perl 5.004_04
The subroutine dbPrepare (line 1) returns a hash table with 4 keys (nStatus, nReturnCode, sReturnDesc, and nDbCursor).
The subroutine dbExecute (line 4) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).
The subroutine dbFinish (line 9) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).
I haven't been able to detect a pattern, yet, but sometimes the value of nDbCursor (on line 8) is null. If it happened every time, I would deduce that the key nDbCursor became undefined after the execution of dbExecute. Shouldn't the key nDbCursor still be available within the hash table Returned after the execution of dbExecute (and dbFinish)?
As a fix, I am planning to save the value of nDbCursor in a variable after executing dbPrepare and using the variable for the resetting of the hash Input. I'm trying to understand why this code sometimes works and sometimes fails. Any enlightenment would be greatly appreciated.
Thanks.
1 %Returned = dbPrepare( %Input );
2 if ( $Returned{nStatus} == 0 ) {
3 %Input = ( nDbCursor => $Returned{nDbCursor} );
4 %Returned = dbExecute( %Input );
5 }
6 if ( $Returned{nStatus} == 0 ) {
7 # FINISH CURSOR
8 %Input = ( nDbCursor => $Returned{nDbCursor} );
9 %Returned = dbFinish( %Input );
10 }
11 # SET PROPER RETURN VALUES IF ALL WAS OK
12 if ( $Returned{nStatus} == 0 ) {
13 %Returned = (
14 nStatus => 0,
15 nReturnCode => 0,
16 sReturnDesc => "erLogDataError: Successful"
17 );
18 }
19 return( %Returned );
My environment: AIX 4.3.3, perl 5.004_04
The subroutine dbPrepare (line 1) returns a hash table with 4 keys (nStatus, nReturnCode, sReturnDesc, and nDbCursor).
The subroutine dbExecute (line 4) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).
The subroutine dbFinish (line 9) returns a hash table with 3 keys (nStatus, nReturnCode, and sReturnDesc).
I haven't been able to detect a pattern, yet, but sometimes the value of nDbCursor (on line 8) is null. If it happened every time, I would deduce that the key nDbCursor became undefined after the execution of dbExecute. Shouldn't the key nDbCursor still be available within the hash table Returned after the execution of dbExecute (and dbFinish)?
As a fix, I am planning to save the value of nDbCursor in a variable after executing dbPrepare and using the variable for the resetting of the hash Input. I'm trying to understand why this code sometimes works and sometimes fails. Any enlightenment would be greatly appreciated.
Thanks.