Subject Re: [firebird-support] octets handling
Author Hans
This snippet returns your desired result, I think

CREATE PROCEDURE STR_TEST
RETURNS ( PAYLOAD CHAR( 29 ) )
AS
DECLARE VARIABLE I1 Integer;
DECLARE VARIABLE I2 Integer;
DECLARE VARIABLE I3 Integer;
DECLARE VARIABLE I4 Integer;

DECLARE VARIABLE D11 Integer;
DECLARE VARIABLE D12 Integer;
DECLARE VARIABLE D21 Integer;
DECLARE VARIABLE D22 Integer;
DECLARE VARIABLE D31 Integer;
DECLARE VARIABLE D32 Integer;
DECLARE VARIABLE D41 Integer;
DECLARE VARIABLE D42 Integer;

DECLARE HEX Varchar(20);

BEGIN
I1 = 6;
I2 = 0;
I3 = 60;
I4 = 1;

/*=======================*/

HEX = '0123456789ABCDEF';

D11 = DIV(I1,16) + 1;
D12 = MOD(I1,16) + 1;

D21 = DIV(I2,16) + 1;
D22 = MOD(I2,16) + 1;

D31 = DIV(I3,16) + 1;
D32 = MOD(I3,16) + 1;

D41 = DIV(I4,16) + 1;
D42 = MOD(I4,16) + 1;

Payload = SUBSTR(HEX,D11,D11) || SUBSTR(HEX,D12,D12)
|| SUBSTR(HEX,D21,D21) || SUBSTR(HEX,D22,D22)
|| SUBSTR(HEX,D31,D31) || SUBSTR(HEX,D32,D32)
|| SUBSTR(HEX,D41,D41) || SUBSTR(HEX,D42,D42)
|| '000000000000000000000';

SUSPEND;
END

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

Then
Select * from Str_Test;

----- Original Message -----
From: "Nick Upson" <nick.upson@...>
To: "firebird-support" <firebird-support@yahoogroups.com>
Sent: Friday, October 06, 2006 10:25 AM
Subject: [firebird-support] octets handling


>I need to construct a string, within an SP and preserve all values,
> including nulls.
>
> declare variable payload Char(29) character set OCTETS;
> declare variable i1 Integer;
> declare variable i2 Integer;
> declare variable i3 Integer;
> declare variable i4 Integer;
>
> i1 = 6;
> i2 = 0;
> i3 = 60;
> i4 = 1;
>
> payload = ascii_char(i1) || ascii_char(i2) || ascii_char(i3) ||
> ascii_char(i4);
>
> results in payload = '063C00000...'
>
> whereas I would expect & need '06003C01000...'
>
> I thought that putting everything into an octets field would avoid the
> db chopping at null but it's still not correct either.
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> 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
>
>
>
>
>
>
>
>
>
>