1111 *
1212 * History
1313 *
14+ * obakhir 24-jun-2024 - rwlreadlob : enablement of piecewise reading and error handling using RWL_ERROR_CLOB_TOO_LARGE
1415 * bengsig 22-may-2024 - lobwrite: trim before write
1516 * bengsig 4-apr-2024 - $oraerror:showoci directive
1617 * bengsig 21-mar-2024 - fix reconnect
@@ -4373,27 +4374,67 @@ void rwlreadlob(rwl_xeqenv *xev
43734374, rwl_location * loc
43744375, text * fname
43754376)
4376- {
4377- ub8 amtchr = pres -> slen ;
4377+ {
4378+ ub8 byte_amt = 0 ;
4379+ ub8 char_amt = 0 ;
4380+ ub8 offset = 1 ;
4381+ ub8 byte_inc = 0 ; // Incrementation of read bytes from the CLOB inside the loop
4382+ ub8 char_inc = 0 ; // Incrementation of read chars from the CLOB inside the loop
4383+ ub8 len = 0 ; // Variable that will store CLOB length in characters
4384+
4385+ RWL_OATIME_BEGIN (xev , loc , db -> seshp , 0 , fname , 1 )
4386+ OCILobGetLength2 ( db -> svchp
4387+ , xev -> errhp
4388+ , lobp
4389+ , & len ); // Get the CLOB length in characters
4390+ RWL_OATIME_END
43784391
4392+ char_amt = len ;
4393+
43794394 if (!db )
43804395 {
43814396 rwlexecsevere (xev , loc , "[rwlreadlob-nodb]" );
43824397 return ;
43834398 }
43844399 rwlinitstrvar (xev , pres );
4385- RWL_OATIME_BEGIN (xev , loc , db -> seshp , 0 , fname , 1 )
4400+
4401+ do
4402+ {
4403+ RWL_OATIME_BEGIN (xev , loc , db -> seshp , 0 , fname , 1 )
43864404 xev -> status = OCILobRead2 (db -> svchp
43874405 , xev -> errhp
43884406 , lobp
4389- , 0 /*byte_amtp*/
4390- , & amtchr
4391- , 1 /*offset*/
4392- , pres -> sval , amtchr
4393- , OCI_ONE_PIECE
4394- , 0 ,0
4395- , (ub2 ) 0 , (ub1 ) SQLCS_IMPLICIT );
4396- RWL_OATIME_END
4407+ , & byte_amt
4408+ , & char_amt
4409+ , offset
4410+ , pres -> sval + byte_inc
4411+ , pres -> slen - byte_inc
4412+ , OCI_FIRST_PIECE // This piece parameter value will change to OCI_NEXT_PIECE internally in OCILobRead2() after the first the first iteration
4413+ , (void * )0
4414+ , (OCICallbackLobRead2 )0
4415+ , (ub2 )0
4416+ , (ub1 )SQLCS_IMPLICIT );
4417+ RWL_OATIME_END
4418+
4419+ byte_inc += byte_amt ;
4420+ char_inc += char_amt ;
4421+
4422+ // If BUFFSIZE < CLOB_Byte_Length
4423+ if (pres -> slen - byte_inc <= 4 && xev -> status == OCI_NEED_DATA )
4424+ {
4425+ pres -> sval [byte_inc ] = '\0' ;
4426+ rwlexecerror (xev , loc , RWL_ERROR_CLOB_TOO_LARGE , char_inc , len , pres -> slen );
4427+ pres -> ival = rwlatosb8 (pres -> sval );
4428+ pres -> dval = rwlatof (pres -> sval );
4429+ pres -> isnull = 0 ;
4430+ OCIBreak (db -> svchp , xev -> errhp );
4431+ OCIReset (db -> svchp , xev -> errhp );
4432+ return ;
4433+ }
4434+
4435+ } while (xev -> status == OCI_NEED_DATA );
4436+
4437+
43974438 if (OCI_SUCCESS != xev -> status )
43984439 {
43994440 rwldberrorc1 (xev , loc , (text * )"OCILobRead2" , fname );
@@ -4402,17 +4443,12 @@ void rwlreadlob(rwl_xeqenv *xev
44024443 pres -> dval = 0.0 ;
44034444 }
44044445 else
4405- {
4406- if (bit (xev -> tflags , RWL_THR_DSQL ))
4407- {
4408- rwldebugcode (xev -> rwm ,loc ,"OCILobRead got amtchr=%d %.*s"
4409- , amtchr , amtchr , pres -> sval );
4410- }
4411- pres -> sval [amtchr ] = 0 ;
4446+ {
4447+ pres -> sval [byte_inc ] = '\0' ;
44124448 pres -> ival = rwlatosb8 (pres -> sval );
44134449 pres -> dval = rwlatof (pres -> sval );
4450+ pres -> isnull = 0 ;
44144451 }
4415- pres -> isnull = 0 ;
44164452}
44174453
44184454void rwlreadloblo (rwl_xeqenv * xev
0 commit comments