Bug 896

FileOpen/FileWrite Replace! to a on existing file creates a corrupted (or wrong encoding) file 17 November, 2021

Adrian Gonzalez
17 March, 2018
Product: PowerBuilder Category: PowerScript
Version: 2017 R2 Build:
Classification: Sybase (legacy) bug Publishing: Public
Priority: P1
Status: Scheduling Reason:
Communication Status: Waiting for Customer
Ken Guo @Appeon 17 November, 2021
#7
Hi Adrian,

There is currently no plan to fix this bug.
Can you work around this issue? For example, work around it by not specifying the encoding argument.

Thanks & Regards,

Tom Jiang
Adrian Gonzalez 12 November, 2021
#6
Any news on this ticket? it's been stuck since 2018
Adrian Gonzalez 12 November, 2021
#5
This tickets has been stuck for years now... please provide an update.
Ken Guo @Appeon 20 March, 2018
#4
Hi Adrian,

We apologize the inconvenience this has caused. 
I just checked with our development team and was confirmed that currently there’s not any plan to modify it so to make it behave (or
misbehave, that is) in the same manner as PB12.5

Regards,
Ken
Adrian Gonzalez 20 March, 2018
#3
Thanks for the update Ken.
Your explanation makes sense, still, we'd rather have PB2017.R2 behave (or misbehave, that is) in the same manner as PB12.5.

At the moment we are assessing migrating a huge code base and a simple change like the one you propose implies an extensive an impact analysis from our side.

Will you updated this issue as soon as you get the development team's answer?
Ken Guo @Appeon 18 March, 2018
#2
Hi Adrian,

Thanks for reporting the problem. I’ve transferred this to our development team for further analysis and possible fix. 

Currently please work it around with the below scripts, i.e. do not specify the encoding argument:
ll_FileHandle = FileOpen( ls_BaseFolder + 'target.pb17.txt', &
        StreamMode!, &
        Write!, &
        LockReadWrite!, &
        Replace!
)


You may refer to the PB Help for the Encoding argument: “Specify this argument when you create a new text file using text or line mode. If you do not specify an encoding, the file is created with ANSI encoding.”. Therefore when you are using Steam Mode, please do not specify the encoding. 

Regards,
Ken
Adrian Gonzalez 17 March, 2018
#1
test.2017.zip (5KB)

*Phenomenon:
When trying to save a blob into a non-existing file using Replace! resulting file is "corrupted" (or wrong encoding) file.
The second time (once the file exists) the file is saved correctly.

*Reproduce Steps:
// Open the file in StreamMode! (so that we can read into a blob)
ll_FileHandle = FileOpen( ls_BaseFolder + 'source.pbr', &
	StreamMode!, &
	Read!, &
	Shared! )

// Read the content into a blob
FileRead(ll_FileHandle, lblb_Data)

// Close the file
FileClose(ll_FileHandle)

////
//// Write the content to a new file, replacing it if it exists
////
ll_FileHandle = FileOpen( ls_BaseFolder + 'target.pb17.txt', &
	StreamMode!, &
	Write!, &
	LockReadWrite!, &
	Replace!, &
	EncodingUTF16LE! )
	
FileWrite(ll_FileHandle, lblb_Data)
FileClose(ll_FileHandle)


Remark:
Attached 2 targets, in PB12.5 works fine, in PB2017R7 it generates a corrupt file
OS:
Windows 7
Platform:
32-bit
Database Type:
N/A
Database Version:
N/A