[VXCMD] Offset not being applied in Binary_ReadData?

Rodney Tamblyn rodneytamblyn at paradise.net.nz
Mon Feb 10 15:20:30 CST 2003


I've been testing reading and writing large binary objects to blob 
fields using VXMCD 1.9.6 MachO

The call:

     get Valentina("Binary_ReadData", fRef,"tData",tRead,(tOffset-1))

... is not working as expected.  The offset is not being applied and is 
always returning the data from the start of the file. MC script below.  
If you want to review the MC stack, I've uploaded it to:

http://radio.weblogs.com/0118367/downloads/ValentinaTester.sit

Rodney
--
constant kRead = 200000
global dbRef
local cRef

on mouseUp
   local tWriteFi,tStartTime,fRef,tData,tBlobSize
   -- test for abort during debugging
   #  if cRef <> empty then
   #  valCleanup
   # end if
   -- timer
   put the seconds into tStartTime
   --setup val
   put Valentina("DataBase_SQLSelect",dbRef,"SELECT * from MEDIA") into 
cRef
   valAssert "SQLSelect",cRef
   put Valentina("Cursor_GetFieldRef",cRef,"MOVIES") into fRef
   valAssert "GetFieldRef",fRef
   -- how big is it?
   put Valentina("BLOB_GetDataSize", fRef ) into tBlobSize
   --temp file to write to
   put writeSetup() into tWriteFi
   put 1 into tOffset
   put false into tData
   repeat until tOffset = tBlobSize
     #how much should we read?
     if tOffset+ kRead > tBlobSize then
       #read the remaining bit
       put tBlobSize - tOffset into tRead
     else
       #read a another chunk from the blob
       put kRead into tRead
     end if

     #read from db
     get Valentina("Binary_ReadData", fRef,"tData",tRead,(tOffset-1))
     valAssert "ReadData",it
     #write the chunk out to the file
     write tData to file tWriteFi at tOffset
     put empty into tData
     add tRead to tOffset
     if tOffset > tBlobSize then
       answer "Error in code... read for more than length of blob..."
       valCleanup cRef
       exit to Metacard
     end if
   end repeat
   -- cleanup
   valCleanup cRef
   close file tWriteFi
   if there is a player "test" then
     set the filename of player "test" to tWriteFi
   end if
   put the seconds into tEndTime
   put "Took:"&& tEndTime-tStartTime&&"secs"
end mouseUp

on valAssert pWhere,pRet
   if word 1 of pRet = "ERROR" then
     answer "Valentina returned an error:"&&pRet&&"("&pWhere&")"
     valCleanup
     exit to Metacard
   end if
end valAssert

on valCleanup
   get Valentina("Cursor_Remove", cRef)
   if word 1 of it = "Error" then breakpoint
end valCleanup


function writeSetup
   # put the tempName() into tFi
   put fld "writeFile" into tFi
   open file tFi for binary write
   if the result <> empty then
     put "writesetup:"&& the result
     exit to Metacard
   else
     return tFi
   end if
end writeSetup



More information about the Valentina mailing list