Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help speed binary field conversion
Message
De
25/08/2005 07:22:50
 
 
À
24/08/2005 12:19:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Versions des environnements
Visual FoxPro:
VFP 7
Divers
Thread ID:
01043345
Message ID:
01043758
Vues:
14
>>I need to read binary fields from Postgres. I store them in Postgres in BYTEA type fields.
>>Postgres returns BYTEA fields in format where "bad" characters are replaced with octal codes in format \ooo
>>
>>I created the following routine to convert abytea type to binary format.
>>Unfortunately, my fields sizes can be up to 2 MB.
>>I this case the following conversion takes more than 10 secods.
>>
>>How to speed up binary data retrieval ?
>>
>>
>>cres=ByteA2Str( replicate( 'a\000', 10**7) )
>>
>>FUNCTION ByteA2Str( cStr )
>>LOCAL cTempFN
>>cTempFN = SYS(2015)+'.bin'
>>Bytea2File( m.cStr, m.cTempFN )
>>LOCAL cRes
>>cRes= FILETOSTR(m.cTempFN)
>>DELETE FILE (m.cTempFN)
>>RETURN m.cres
>>
>>PROCEDURE BYTEA2File( cBytea, cFN )
>>LOCAL cInpFn, inp, x, cchar, cchar1, cchar2, cchar3
>>cInpFn= SYS(2015)+'.txt'
>>STRTOFILE( m.cBytea, m.cInpFn)
>>inp = FOPEN(m.cInpFn,0)
>>nlen=LEN(m.cByteA)
>>x = FCREATE(m.cFN)
>>DO WHILE !FEOF(m.inp)
>>  cchar = FREAD(m.inp,1)
>>  IF m.cchar#'\'
>>	FWRITE(m.x, m.cchar )
>>	LOOP
>>	ENDIF
>>	
>>  cchar1 = FREAD(m.inp,1)
>>  IF m.cchar1='\'
>>	FWRITE(m.x, m.cchar1 )
>>	LOOP
>>	ENDIF
>>
>>  cchar2 = FREAD(m.inp,1)
>>  cchar3 = FREAD(m.inp,1)
>>
>>  IF !BETWEEN(m.cchar1, '0','7') OR ;
>>     !BETWEEN(m.cchar2, '0','7') OR !BETWEEN(m.cchar3, '0','7')
>>    ERROR 'Non-octal digit after \ '+ m.cFn
>>    ENDIF
>>
>>  FWRITE(m.x, CHR( VAL(m.cchar1)*64 + ;
>>                     VAL(m.cchar2)*8 + ;
>>                     VAL(m.cchar3) ) )
>>  ENDDO
>>
>>FCLOSE(m.x)
>>FCLOSE(m.inp)
>>DELETE FILE (m.cInpFn)
>>ENDPROC
>>
>
>which are the codes that it converts?
>ascii 0-31 ?

it converts codes 0 .. 31 and 127 .. 255 and also ' and \ characters
( 39 and 92 codes)
Andrus
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform