Bug 5133

Problem with FileReadEx and Blobs 16 September, 2020

René Ullrich
24 August, 2020
Product: PowerBuilder Category: PowerScript
Version: 2019 R2 Build: 2353
Classification: Sybase (legacy) bug Publishing: Public
Priority: P3
Status: Scheduling Reason:
Ken Guo @Appeon 16 September, 2020
Hi René,

I agree with your opinion and strictly speaking, it is absolutely a bug!

I have submitted this ticket to the development team at present. Generally speaking, our development team will set the priority class of the bug according to its severity, its reach, impact, and whether there is a workaround for it.
Thus its priority won’t be too high. I hope you can understand that and suggest you use the current workaround.

Thanks again for finding out and reporting this issue!

René Ullrich 16 September, 2020
Hi Armando,
I currently use the workaround to read the blob in a local variable first and then assign it to the argument.

But I still think it is a bug! The assigment of an local empty blob variable to the NULL blob argument should change it to NOT NULL so the FileReadEx function should work correct. Strange: The assignment DOES change the argument to NOT NULL but FileReadEx fails but it shouldn't.
So I think you should fix that.

armando herrera @Appeon 15 September, 2020
Hi Rene,

Are you still facing this matter? 
Is there anything else we can do to keep helping?.

Ken Guo @Appeon 02 September, 2020
Hi All,

I verified multiple system functions in the of_readfile() function, following are the results:

blob lblob_empty
ablob_data = Blob(String('aaa')) //Set a value to blob

// If the system functions can’t change the value of the ablob_data variable, it works well. For instance:

Messagebox('String',String(ablob_data))  //String function works
Messagebox('Len',len(ablob_data))   //Len function works
ablob_data = BlobMid(ablob_data, 3)  //BlobMid function works
FileWriteEx(li_FileNum, ablob_data)  //FileWriteEx works

// If the system functions can change the value of the ablob_data variable, it fails. For example:

BlobEdit ( ablob_data, 1, '123456789', EncodingANSI!)  //BlobEdit function failure. Return NULL
FileReadEx(li_FileNum, ablob_data)  //FileReadEx function failure. Return NULL
dw_1.GetFullState(ablob_data)   //GetFullState failure. Return Null

This rule exists in PB all the time and currently, we don’t have a plan to modify it.

Chris Pollach @Appeon 01 September, 2020
FWIW:  I ran Rene’s test case and it behaves 100% as I would have expected PB execution wise and follows the method rules for nulls. The function is passed in a NULL and the IsNull() MessageBox displays the correct behaviour (as I would always have expected way back to PB 1.x) So to me, this is normal NULL behaviour not a bug.

 The problem is in the statement “ablob_data = lblob_empty" In the “of_readfile”. If you change the method argument ablob_data variable to passed by VALUE it *can* be changed to other than a null. If you leave the ablob_data variable as passed by REF, then the variable always stays a NULL even after the “ablob_data = lblob_empty" statement is executed.

  So the problem (misunderstanding) is the “by REF” setting blocking the argument variable from being updated (if NULLS are passed in). However, that goes back to PB’s standard of not passing in NULLS to methods. Maybe this is a C++ thing as no memory is really allocated if the NULL state is set. Hence the "no updating allowed" behaviour.

Food for thought
Chris Pollach @Appeon 31 August, 2020
Hi Everyone;

  From the PB Help .... "If any argument's value is null, FileReadEx returns null."

  Its the same for almost every PB System Function (command) and has been that way since PB 1.0. The owes is on the PB developer to ** ensure that they do not pass in NULL argument(s)**.

  This is not a bug.

Regards ... Chris
Ken Guo @Appeon 26 August, 2020
Hi René,

Thanks for reporting this problem! We reproduced it on our end and will do further research to figure it out. We will keep you posted about the progress.

BTW, PB 12.6 has the same issue as well.
And we’d suggest you to try the following workarounds:

In the of_readfile() function, Change:
li_rc = FileReadEx(li_FileNum, ablob_data)
li_rc = FileReadEx(li_FileNum, lblob_empty) 
ablob_data = lblob_empty

Govinda Lopez @Appeon 25 August, 2020
Hi René,

Thanks for the detailed info. I was able of reproducing your case. I will now pass it to our engineering team for further analysis. We will keep you posted on the results here.

René Ullrich 25 August, 2020
Bug5133.zip (15KB)

Hi Govinda,

Yes, I know this.
Please read my bug report again. Your test shows what I described as "works".
But if you move some of the code to a function it doesn't work anymore.

See the enhanced test case:
Blob argument to my own function is NULL. In function it is changed to NOT NULL. FileReadEx failes although. (It will not fail if blob argument to my own function is not NULL).

Govinda Lopez @Appeon 24 August, 2020
Reproducible Test Case
Govinda Lopez @Appeon 24 August, 2020
Hi René,

This does not seem to be a bug. Based on the documentation of the FileReadEx() function (https://docs.appeon.com/pb2019r2/powerscript_reference/ch10s174.html) it states that if you pass any NULL argument to the function it will return a NULL value:

Returns the number of bytes read. If an end-of-file mark (EOF) is encountered before any characters are read, FileReadEx returns -100. If the file is opened in LineMode and a CR or LF is encountered before any characters are read, FileReadEx returns 0. If an error occurs, FileReadEx returns -1. FileReadEx returns -1 if you attempt to read from a string in stream mode or read from a blob in line mode. If any argument's value is null, FileReadEx returns null.

Attached I have added a reproducible test case so you can see the differences. 

Please do let us know if this helped.

armando herrera @Appeon 24 August, 2020
Hi Rene,

Thank you very much for your report. We are working on it and we will get back to you after analyzing it.

We'll keep you posted here!

René Ullrich 24 August, 2020
There is a strange behaviour with FileReadEx function with blobs. (Maybe it is also with other functions?)

I know that FileReadEx returns NULL if any argument is NULL.

So this would return NULL:
blob lblob_data
SetNull (lblob_data)
FileReadEx (li_f, lblob_data)

But this works:
blob lblob_data, lblob_empty
SetNull (lblob_data)
lblob_data = lblob_empty   // lblob_data is not NULL anymore
FileReadEx (li_f, lblob_data)

I have a function
long of_fileread (string as_filename, ref blob ablob_data)

In the function I do:
blob lblob_empty
ablob_data = lblob_empty   // ablob_data is not NULL anymore
FileReadEx (li_f, ablob_data)

The function works if the argument ablob_data is not NULL.
If argument ablob_data is NULL the FileReadEx function fails (returns NULL)!
But there is no reason to return NULL because the argument is not NULL at this moment!

Same functionality like above but different behaviour!?

Read file into a local blob variable and then assign to argument.
Windows 10
Database Type:
Database Version: