Author |
Message
|
angka |
Posted: Mon Sep 25, 2006 1:01 am Post subject: Casting of BLOB to INTEGER |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi all,
I am trying to cast Blob to integer but some how it cannot be CAST below are my codes. Thanks
SET LEAD_ZEROS = X'00000000';
SET TEST_BLOB = SUBSTRING(InputRoot.MQMD.CorrelId FROM 1 FOR 4);
SET TEMP_BLOB = TEST_BLOB || LEAD_ZEROS;
SET TEST_INT = CAST(TEMP_BLOB AS INTEGER);
I am working on Windows platform so it is little Endian. When i step through the debug, the TEST_INT is not assign any value. Are there any mistakes from my codes? I did get this working in Broker V2.1 before. i am currently using V6. Thanks. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Sep 25, 2006 1:45 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I don't think you can make any guarantees that an MQMD Correlation ID is going to start with four integer bytes. And you shouldn't be misusing this field to hold business data.
You could consider adding an ENCODING parameter to the CAST, though. It might help. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
angka |
Posted: Mon Sep 25, 2006 2:00 am Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
The existing system is using this field so I can't change anything. I taking the first 4 bytes because it is in the business logic. I did set ENCODING InputRoot.Properties.Encoding before but it gave me the same result =(
Thanks =) |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Sep 25, 2006 2:47 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Try passing the resulting BLOB to a java function that uses Integer.decode....
this way you can use "0x" + BLOB for the decode part.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mgk |
Posted: Mon Sep 25, 2006 3:43 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
I agree with Jeff that this is a bad idea in general. However, it should work. Can you post as example Input CorrelID and the rest of the ESQL showing the DECLAREs of the variables you are using. Also, if you could post a Usertrace showing this operation that would help too.
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 |
|
 |
angka |
Posted: Mon Sep 25, 2006 6:45 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi all,
I am working on Wintel platform. I have this subjectID of numeric value 111111111 which is coming in from an external system in hexa format. On my end, I need to cast this incoming hexa value into an integer to do processing. 111111111 is basically represented by hexa 069F6BC7. I did the following in my ESQL codes:
DECLARE SUBJ_ID INTEGER;
SET SUBJ_ID = CAST(X'00000000069F6BC7' AS INTEGER);
This works. However, I am puzzled by why it works. Specifically, I am working on a Wintel machine. Thus, I am expecting all representations to be in Little Endian format. However, the above representation is clearly in Big Endian. Have I missed out something?
Also, when I experimented with the following:
SET SUBJ_ID = CAST(X'00000000FFFFFFFF');
There is no results returned. It seems like although the INTEGER type is of 8 Bytes (64 bits), I can go beyond the least significant 4-Bytes. |
|
Back to top |
|
 |
angka |
Posted: Mon Sep 25, 2006 7:37 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
Sorry, I understand that CAST function will cast all in Big Endian format.
But still can't figure out why INTEGER type is of 8 Bytes (64 bits), I cant go beyond 31 bits when casting. Thanks |
|
Back to top |
|
 |
angka |
Posted: Sun Oct 29, 2006 7:37 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi,
I still cant figure out wat wrong with the CAST function.. Below are my codes.
DECLARE LEAD_ZEROS BLOB;
DECLARE FIRST_BYTE BLOB;
DECLARE SECOND_BYTE BLOB;
DECLARE THIRD_BYTE BLOB;
DECLARE FOURTH_BYTE BLOB;
DECLARE REQ_NO_BLOB BLOB;
DECLARE REQ_NO INTEGER;
SET LEAD_ZEROS = X'00000000';
SET REQ_NO_BLOB = X'FFFFFF7F';
SET FIRST_BYTE = SUBSTRING(REQ_NO_BLOB FROM 1 FOR 1);
SET SECOND_BYTE = SUBSTRING(REQ_NO_BLOB FROM 2 FOR 1);
SET THIRD_BYTE = SUBSTRING(REQ_NO_BLOB FROM 3 FOR 1);
SET FOURTH_BYTE = SUBSTRING(REQ_NO_BLOB FROM 4 FOR 1);
SET REQ_NO = CAST(LEAD_ZEROS || FOURTH_BYTE || THIRD_BYTE || SECOND_BYTE || FIRST_BYTE AS INTEGER);
X'FFFFFF7F' is the biggest value it can be casted. X'00000080' will give a blank value from the debug mode? Why is this so? or should i add ENCODING clause? i tried with MQENC_INTEGER_NORMAL AND MQENC_INTEGER_REVERSED it still the same. Thanks.. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Oct 30, 2006 3:11 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
I think you need to understand far more than you'd like to solve this.
Depending on the platform and the size of the integer on the platform you will use X many bytes per integer. (64 bit processors typically allow for bigger values...).
Depending on the platform again the values may be reversed (little endian / big endian).
Depending on whether the system considers a signed integer or not the value will be different in decimal (max = 7FFF, 8000 would be the min negative value in case of a 2 byte signed integer).
And of course your parsing has to take all this into account...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Oct 30, 2006 3:39 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Also, you may only get 64 bit numbers inside a 64bit execution group.
At least in terms of extracting 64 bits worth of BLOB data. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
angka |
Posted: Mon Oct 30, 2006 6:02 pm Post subject: |
|
|
Chevalier
Joined: 20 Sep 2005 Posts: 406
|
Hi all,
Thanks for the clarification. So now I understand why. I am on a 32 bit processor and most likely a 2 complement platform.
Cheers |
|
Back to top |
|
 |
|