Hi!

I am trying to convert a BLOB (unlimited size, theoretically) to a long 
VARCHAR (say, VARCHAR(8192)). This should be easy enough to do:

DECLARE VARIABLE b BLOB; /* input */
DECLARE VARIABLE v VARCHAR(8192); /* output */
...
v = SUBSTRING(b, 1, 8192);

Except that as soon as I convert between BLOB and VARCHAR, I lose all 
high-ASCII characters (they get replaced by a dot). E.g., to expand the 
example above:

DECLARE VARIABLE b BLOB; /* input */
DECLARE VARIABLE b2 BLOB; /* output */
DECLARE VARIABLE v VARCHAR(8192); /* output */
...
v = SUBSTRING(b, 1, 8192);
b2 = SUBSTRING(b, 1, 8192);

When this code is run, both b2 and v contain the first 8192 characters 
from the input - but in v's case, the high-ascii characters get 
converted to a dot.

Supposedly this should be done using a UDF, but I just can't figure out 
how to write one (in Delphi):

function BLOBSTR(Value: PBlob; Size: Longint; Dest: PAnsiChar): 
PAnsiChar; cdecl;
begin
   Result := Dest;
   FillChar(Result^, Size, 'a');
end;

(I decided to remove the BLOB-reading code to make sure I have no errors 
in my parameter-passing code.)

But with a declaration:

DECLARE EXTERNAL FUNCTION BLOBSTR
BLOB, INTEGER, CSTRING(8192)
RETURNS PARAMETER 3
ENTRY_POINT 'BLOBSTR' MODULE_NAME 'pwIBUDF';

and a select:

SELECT BLOBSTR(blobfield, 10) FROM sometable WHERE id=1

I get an empty (zero-byte, NOT NULL) result. I would expect to get 
either a 10-byte result (if the buffer for parameter 3 gets filled with 
zeroes before the UDF is called) or something between 10 and 8192 byte 
result (if the buffer does not get initialized), but zero has me stumped.

I would appreciate any pointers.

Thanks,

Pepak


------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Resources item
on the main (top) menu.  Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/firebird-support/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/firebird-support/join
    (Yahoo! ID required)

<*> To change settings via email:
    firebird-support-dig...@yahoogroups.com 
    firebird-support-fullfeatu...@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    firebird-support-unsubscr...@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to