Subject Re: [firebird-support] ???HELP -->Converting blob to VARCHAR or VARCHAR to blob.
Author Jason Dodson
A blob to a varchar shouldn't be hard. You can select it as a string. I could be full of it though.

Here is the StringToBlob (with other things needed) function I wrote (Originally C++, but converted to Delphi for fellow
programmers):

/*********************************************************************************************/

type
PIBVarChar = ^TIBVarChar;
TIBVarChar = packed record
Len: SmallInt;
Str: array[0..4095] of Char;
end;

function IBVarCharToStr(const V: TIBVarChar): string;
begin
//An Interbase VarChar is preceeded with 2 bytes, indicating the length
//Set the length of our return string, to the length of our Interbase VarChar
setLength(Result, V.Len);

//Now we copy the string portion of the Interbase VarChar into the Return String
//We use position 1, not 0, because a Pascal string also has the length preceeding the string
Move(V.Str[0], Result[1], V.Len);
end;

function StringToBlob(var Str: TIBVarChar; Blob: PBlob): PBlob;
var TempStr : string;
begin
//Convert the IBVarChar to a pascal string so we can manipualte it
TempStr := IBVarCharToStr(Str);

//Set the return Pointer to an to the address of othe BLOB we pass in
Result := Blob;

//Make sure a BLOB was actually passed in
if (not Assigned(Blob)) or (not Assigned(Blob^.BlobHandle)) then exit;

//Put our string into the blob
Blob^.PutSegment(Blob^.BlobHandle, TempStr, StrLen(TempStr));
end;

/*********************************************************************************************/

kapilpatil84firebird wrote:
> Any One Have,
> UDF TO converting blob to VARCHAR or VARCHAR to blob.
>
> Thanks In Advance!!!
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net 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
>
>
>
>
>
>
>
>


--
The information transmitted herewith is sensitive information intended only for use to the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon, this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.