ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Supported casts - BLOB to Integer

Post new topic  Reply to topic
 Supported casts - BLOB to Integer « View previous topic :: View next topic » 
Author Message
jamesyu
PostPosted: Fri May 11, 2007 7:16 am    Post subject: Supported casts - BLOB to Integer Reply with quote

Acolyte

Joined: 31 Jan 2007
Posts: 70

Hi All,

In the v6 ESQL manual -> Supported Casts, it documents that BLOB can be casted to Integer, quote:

"The byte array has a maximum of 263 elements and is converted to an integer. An error is reported if the source is not of the correct length to match an integer."

What is the last statement of "An error is reported if the source is not of the correct length to match an integer" supposed to mean?

Now I am trying to convert, say a hex value of X'3412' to an integer with the following code but failed with an exception saying "Unsuitable source lenght" returned. Does anyboy know why?

DECLARE x BLOB;
DECLARE y INT;
SET x = X'3412';
SET y = CAST(x AS INT);

Thanks,
James
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri May 11, 2007 7:20 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Specify an Encoding on the CAST.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
jamesyu
PostPosted: Fri May 11, 2007 9:09 am    Post subject: Reply with quote

Acolyte

Joined: 31 Jan 2007
Posts: 70

jefflowrey wrote:
Specify an Encoding on the CAST.


Tried it with different encodings:

SET y = CAST(x AS INT ENCODING 1); -- MQENC_INTEGER_NORMAL
SET y = CAST(x AS INT ENCODING 16); -- MQENC_DECIMAL_NORMAL
SET y = CAST(x AS INT ENCODING InputRoot.MQMD.Encoding);

None of those works. Can you please advise again, or any sample lines?

Thanks,
James
Back to top
View user's profile Send private message
mgk
PostPosted: Fri May 11, 2007 9:59 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Hi.

The phrase
Quote:
"correct length to match an integer"
means that in order to be CAST to an INT the BLOB must be of the same length as an integer, which is 8 bytes (as in ESQL INTs are 64 bits). Unfortuantely, it does not automatically pad with 0 if the input value is < 8 so you will have to do that.

Regards,
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
jamesyu
PostPosted: Fri May 11, 2007 10:17 am    Post subject: Reply with quote

Acolyte

Joined: 31 Jan 2007
Posts: 70

mgk wrote:
Hi.

The phrase
Quote:
"correct length to match an integer"
means that in order to be CAST to an INT the BLOB must be of the same length as an integer, which is 8 bytes (as in ESQL INTs are 64 bits). Unfortuantely, it does not automatically pad with 0 if the input value is < 8 so you will have to do that.

Regards,


Ok, I tried this with the same error returned:

DECLARE x BLOB;
SET x = X'00003412';
DECLARE y INT;
SET y = CAST(x AS INT);

Any ideas?

Thanks,
James
Back to top
View user's profile Send private message
EddieA
PostPosted: Fri May 11, 2007 10:21 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

jefflowrey wrote:
Specify an Encoding on the CAST.


Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
mgk
PostPosted: Fri May 11, 2007 10:51 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Hi,

It is failing because you are only passing 4 bytes, not 8 to the CAST.

Your statement
Code:
SET x = X'00003412';
only creates a BLOB
that is 4 bytes long (as each pair of chars represents one byte). You can check this by using the LENGTH function on the BLOB and inspecting the result.

In this case, to make the CAST work, you need to pad to make 8 bytes with 8 more zeros as in:
Code:
SET x = X'0000000000003412';
.

The ENCODING is not relavent in this case.
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
jamesyu
PostPosted: Mon May 14, 2007 5:46 am    Post subject: Reply with quote

Acolyte

Joined: 31 Jan 2007
Posts: 70

Thx a lot. It works!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Supported casts - BLOB to Integer
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.