Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: PowerBuilder
Expertise: Beginner
May 29, 1997



Application Security Testing: An Integral Part of DevOps

Max file size PB can open

I need to develop a program interfaced with a Sybase database. First I have to open a huge ASCII file (size ranges from 20 to 100 MB) to read and convert it to a preformatted ASCII file for the database.

Can PB open such a large ASCII file if my PC has 32 MB of memory? If so, how?

The size of the file makes no difference to PowerBuilder, because it reads only 32K chunks at a time. Obviously if you read the whole file in 32K chunks and tried to store them in memory as one continuous block, you'd have problems.

Assuming your data has some kind of structure to it, you can read the data in 32K chunks and process as much of the first chunk as possible, then append the next chunk to the end of what's left of the chunk, and continue until you process the whole file.

The following code will read a large file into a blob variable. I suggest that instead of concatenating the chunks into the blob, you perform only the processing you need to do.

integer fnum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b

// Set a wait cursor

// Get the file length, and open the file
flen = FileLength(sle_filename.Text)
fnum = FileOpen(sle_filename.Text,  &
	StreamMode!, Read!, LockRead!)

// Determine how many times to call FileRead 
IF flen > 32765 THEN
   IF Mod(flen, 32765) = 0 THEN
      loops = flen/32765
      loops = (flen/32765) + 1
   loops = 1

// Read the file
new_pos = 1
FOR i = 1 to loops
   bytes_read = FileRead(fnum, b)

   // Here you perform your processing on the current chunk
   tot_b = tot_b + b

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date