|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Dynamically updating a reference data type |
« View previous topic :: View next topic » |
Author |
Message
|
darioo |
Posted: Thu Oct 09, 2014 10:02 am Post subject: Dynamically updating a reference data type |
|
|
Novice
Joined: 19 Mar 2009 Posts: 15
|
Greetings everyone, I'm using WMB7.
I'm wondering if it's possible to change where a declared reference variable points to?
Something like this (non working code follows):
Code: |
DECLARE myref REFERENCE TO Environment.Variable.Something;
... some code ...
SET myref REFERENCE = Environment.Variable.SomethingElse; -- won't work
SET myref = 50; -- effectively "SET Environment.Variable.SomethingElse = 50;"
|
since using
Code: |
SET myref = Environment.Variable.SomethingElse
|
is effectively
Code: |
SET Environment.Variable.Something = Environment.Variable.SomethingElse;
|
and it's not what I wanted. Image I want something like pointers in C.
Rationale (read if you have some time): data gets pulled from a database using ESQL ODBC. Two rows are returned, let's say one of them represents "BUY", other one "SELL", these are values from one of database columns.
ESQL doesn't have an ORDER BY clause when SELECTing from a database, so I can never be quite sure which row is "BUY" and which one is "SELL".
Code: |
myData.rows[1] -- might be "BUY" or "SELL"
myData.rows[2] -- the opposite value
|
So, I thought it would be nice to do something like creating two empty references "buyRef" and "sellRef", then assigning to them appropriate rows after checking their values in an IF...ELSE. Alas, not possible.
Another thing I hoped that would work is doing something like:
Code: |
IF myData.rows[1].orderType = 'BUY' THEN
DECLARE buyRef REFERENCE TO myData.rows[1];
DECLARE sellRef REFERENCE TO myData.rows[2];
ELSE
DECLARE buyRef REFERENCE TO myData.rows[2];
DECLARE sellRef REFERENCE TO myData.rows[1];
END IF;
|
but this won't work because of scoping issues when I want to access references later in code.
I have found few workarounds how to solve this problem:
1. PASSTHRU statement
2. two ESQL queries with a WHERE statement (doubling amount of DB calls)
3. using Java
4. some ESQL trickery
but was left wondering what would be the most elegant solution to this problem using pure ESQL. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Oct 09, 2014 10:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you want to change where a reference points, you can MOVE it.
If you want to test the value of an element you can use FIELDVALUE. Likewise if you want to test the Name of an element, you can test FIELDNAME.
If you want to access a child of an element (a single level only) by name, you can use {}, like MOVE myRef to Environment.Variables.{'buy'} |
|
Back to top |
|
 |
kimbert |
Posted: Thu Oct 09, 2014 12:46 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
ESQL does not allow uninitialised pointers. Some would say that's a feature, not a shortcoming. But it does have a SELECT statement, which does exactly what you need. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Oct 09, 2014 1:02 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Right, so you can't create two references that point to nowhere.
You can create two references that point to InputRoot. And then move them. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|