In PocketBuilder 2.0.2, system functions FileReadEx and FileWriteEx supercede the FileRead and FileWrite functions, although support for FileRead and FileWrite is retained for backward compatibility.
FileRead and FileWrite have a 32,765 character limit on the amount of data that can be read or written in a single function call. The FileReadEx and FileWriteEx functions do not have this limitation.
The new functions retain the same arguments as the functions they supercede, but return a long datatype instead of an integer. The first argument for the FileReadEx and FileWriteEx functions is the integer assigned to the file that you open for reading or writing. The second argument is the name of the string or blob variable into which you want to read or write the data.
Whether you use the old or new functions, the mode in which you open a file determines the behavior of the functions used to read and write to a file.
When a file has been opened in line mode, each call to the FileRead or FileReadEx function reads until it encounters a carriage return (CR), line feed (LF), or end-of-file mark (EOF). Each call to FileWrite or FileWriteEx adds a CR and LF at the end of each string it writes. Line mode is not supported when reading from or writing to blobs.
When a file has been opened in stream mode, a call to FileRead reads the whole file (until it encounters an EOF) or 32,765 bytes, whichever is less. FileWrite writes a maximum of 32,765 bytes in a single call and does not add CR and LF characters. A byte size of 32,765 does not cause termination of the FileReadEx or FileWriteEx calls.
This example reads the file EMP_DATA.TXT into a string in line mode:
integer li_FileNum
long ll_bytes
li_FileNum = FileOpen("C:\HR\EMP_DATA.TXT", &
LineMode!)
FileReadEx(li_FileNum, ls_Emp_Input)
END IF
This example reads the file EMP_PIC1.BMP and stores the data in the blob Emp_Id_Pic. The number of bytes read is stored in ll_bytes:
integer li_fnum
long ll_bytes
blob Emp_Id_Pic
li_fnum = FileOpen("C:\HR\EMP_PIC1.BMP", StreamMode!)
ll_bytes = FileReadEx(li_fnum, Emp_Id_Pic)
This script excerpt opens EMP_DATA.TXT and writes the string New Employees on a new line at the end of the file. The variable li_FileNum stores the number of the opened file:
integer li_FileNum
li_FileNum = FileOpen("C:\HR\EMP_DATA.TXT", &
LineMode!, Write!, LockWrite!, Append!)
FileWriteEx(li_FileNum, "New Employees")
The following example reads a blob from the database and writes it to a file. The SQL SELECT statement assigns the picture data to the blob Emp_Id_Pic. Then FileOpen opens a file for writing in stream mode and FileWriteEx writes the blob to the file:
integer li_FileNum blob emp_id_pic SELECTBLOB salary_hist INTO : emp_id_pic FROM Employee WHERE Employee.Emp_Num = 100 USING Emp_tran; li_FileNum = FileOpen("C:\EMPLOYEE\EMP_PICS.BMP", & StreamMode!, Write!, Shared!, Replace!) FileWriteEx(li_FileNum, emp_id_pic)
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |