Author |
Message
|
Meow |
Posted: Fri Dec 12, 2003 11:20 am Post subject: SQL |
|
|
 Voyager
Joined: 25 Jun 2003 Posts: 95
|
Hi
i get something like this.. and i have to generate a where statement out of this dynamically
<query>
<search-string>( [Employee Number] = "" AND [CNumber] = "" AND [DateOfService] = "" AND [CStatus] = "" AND [CType] = "" AND PNumber = “” AND PName = “”)</search-string>
<search-spec> <node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">Employee Number</node>
<node value-type="TEXT" node-type="Constant"></node> </node>
<node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">CNumber</node>
<node value-type="TEXT" node-type="Constant"></node>
</node>
<node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">DateOfService</node>
<node value-type="DATE" node-type="Constant"></node>
</node>
<node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">PNumber</node>
<node value-type="TEXT" node-type="Constant"></node>
</node>
<node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">PName</node>
<node value-type="TEXT" node-type="Constant"></node>
</node>
<node node-type="Binary Operator">
AND
<node node-type="Binary Operator">
=
<node node-type="Identifier">CStatus</node>
<node value-type="TEXT" node-type="Constant"></node></node>
<node node-type="Binary Operator"> =
<node node-type="Identifier">CType</node> <node value-type="TEXT" node-type="Constant"></node> </node>
</node>
</node>
</node>
</node>
</node>
</node>
</search-spec>
</query>
i have to generate a where statement out of this. how do i achieve this.
Thanks in advance
Paruvan |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Dec 12, 2003 12:27 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You could certainly use EVAL or PASSTHROUGH to execute a complete SQL statement that had been assembled as a string.
You might be able to use the {} with a where clause to also do something similar. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Meow |
Posted: Fri Dec 12, 2003 5:14 pm Post subject: |
|
|
 Voyager
Joined: 25 Jun 2003 Posts: 95
|
Hi Guys,
i am using the following ESQL code to achieve the above. But due to some logical error its going to infinite loop.
can you guys help me with this....
IF ( (myInputRef."search-string" IS NOT NULL) OR (myInputRef."search-spec" IS NOT NULL) ) THEN
DECLARE myStartRef REFERENCE TO myInputRef."search-spec";
IF ((myStartRef.node = 'AND') OR (myStartRef.node = 'OR')) THEN
WHILE (myStartRef IS NOT NULL) DO
SET Operator1 = myStartRef.node;
DECLARE myTempRef REFERENCE TO myStartRef.node;
IF (myTempRef.node[1] = '=') THEN
DECLARE mySearchRef REFERENCE TO myTempRef.node[1];
SET Operand1 = mySearchRef.node[1];
SET Operand2 = mySearchRef.node[2];
SET whereStmt = whereStmt||Operand1 ||' = '||Operand2||' ';
END IF;
IF (myTempRef.node[2] = '=') THEN
SET whereStmt = whereStmt||Operator2||' ';
DECLARE mySearchRef REFERENCE TO myTempRef.node[2];
SET Operand1 = mySearchRef.node[1];
SET Operand2 = mySearchRef.node[2];
SET whereStmt = whereStmt||Operand1 ||' = '||Operand2||' ';
SET myStartRef = NULL;
ELSEIF ((myTempRef.node[2] = 'AND') OR (myTempRef.node[2] = 'OR')) THEN
MOVE myStartRef TO myTempRef.node[2];
SET Operator2 = myTempRef.node[2];
SET whereStmt = whereStmt||Operator1||' ';
END IF;
END WHILE;
END IF;
END IF;
SET OutputRoot.XML.WhereStatement = '('||whereStmt||')';
i knew its something to do with the Reference and the Move functions.
Please help me out.
Thanks in advance,
Paruvan |
|
Back to top |
|
 |
Meow |
Posted: Sat Dec 13, 2003 7:37 am Post subject: |
|
|
 Voyager
Joined: 25 Jun 2003 Posts: 95
|
I found a small bug in the above code but still cant figure that out....
DECLARE myInputRef REFERENCE TO InputRoot.XML.query;
IF ( (myInputRef."search-string" IS NOT NULL) OR (myInputRef."search-spec" IS NOT NULL) ) THEN
DECLARE myStartRef REFERENCE TO myInputRef."search-spec";
IF ((myStartRef.node = 'AND') OR (myStartRef.node = 'OR')) THEN
WHILE (myStartRef IS NOT NULL) DO
SET Operator1 = myStartRef.node;
DECLARE myTempRef REFERENCE TO myStartRef.node;
-- CHANGED myTempRef.node[1] to myTempRef.node
IF (myTempRef.node = '=') THEN
DECLARE mySearchRef REFERENCE TO myTempRef.node;
SET Operand1 = mySearchRef.node[1];
SET Operand2 = mySearchRef.node[2];
SET whereStmt = whereStmt||Operand1 ||' = '||Operand2||' ';
END IF;
-- ADDED THE BELOW LINE AND WAS ABLE TO PROCESS TILL HERE
MOVE myTempRef NEXTSIBLING;
IF (myTempRef.node[2] = '=') THEN
SET whereStmt = whereStmt||Operator2||' ';
DECLARE mySearchRef REFERENCE TO myTempRef.node;
SET Operand1 = mySearchRef.node[1];
SET Operand2 = mySearchRef.node[2];
SET whereStmt = whereStmt||Operand1 ||' = '||Operand2||' ';
SET myStartRef = NULL;
ELSEIF ((myTempRef.node[2] = 'AND') OR (myTempRef.node[2] = 'OR')) THEN
MOVE myStartRef TO myTempRef.node[2];
SET Operator2 = myTempRef.node[2];
SET whereStmt = whereStmt||Operator1||' ';
END IF;
END WHILE;
END IF;
END IF;
SET OutputRoot.XML.WhereStatement = '('||whereStmt||')';
help me out..
thanks in advance
paruvan |
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Dec 13, 2003 8:05 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Use LASTMOVE to test if your loop is complete, not "IS NULL".
Code: |
while lastmove(myStartRef) do |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Meow |
Posted: Sat Dec 13, 2003 12:01 pm Post subject: |
|
|
 Voyager
Joined: 25 Jun 2003 Posts: 95
|
this is the modified code ... please help me.. i tired lastmove but it did not work.so i tried with the counter.
DECLARE myInputRef REFERENCE TO InputRoot.XML.query";
SET whereStmt = '';
SET Operator1 = '';
SET Operator2 = '';
SET Counter = 1;
-- CHECKING FOR SOME VALIDATIONS
IF ( (myInputRef."search-string" IS NOT NULL) AND (myInputRef."search-spec" IS NOT NULL) ) THEN
DECLARE myStartRef REFERENCE TO myInputRef."search-spec";
IF (myStartRef.node = '=') THEN
DECLARE myTempRef REFERENCE TO myStartRef.node;
SET Operand1 = myTempRef.node[1];
SET Operand2 = myTempRef.node[2];
SET whereStmt = whereStmt||Operand1 ||'='|| Operand2||' ';
ELSEIF ((myStartRef.node = 'AND') OR (myStartRef.node = 'OR') ) THEN
WHILE (Counter < 99) DO
SET Operator1 = myStartRef.node;
DECLARE myTempRef REFERENCE TO myStartRef.node;
IF (myTempRef.node[1] = '=') THEN
DECLARE myChildTempRef REFERENCE TO myTempRef.node[1];
SET Operand1 = myChildTempRef.node[1];
SET Operand2 = myChildTempRef.node[2];
SET whereStmt = whereStmt||Operand1 ||'='|| Operand2||' ';
END IF;
SET whereStmt = whereStmt||Operator1||' ';
IF ((myTempRef.node[2] = 'AND') OR (myTempRef.node[2] = 'OR') ) THEN
SET whereStmt = whereStmt||'SO far success';
-- the loop should come here
MOVE myStartRef.node TO myTempRef.node[2];
SET whereStmt =whereStmt ||Operator1||' ';
SET Counter = Counter + 1;
ELSEIF(myTempRef.node[2] = '=') THEN
DECLARE myChildTempRef REFERENCE TO myTempRef.node[2];
SET Operand1 = myChildTempRef.node[1];
SET Operand2 = myChildTempRef.node[2];
SET whereStmt = whereStmt||Operand1||' = '||Operand2||' ';
SET Counter = 99;
END IF;
END WHILE;
END IF;
END IF;
SET OutputRoot.XML.WhereStatement = '('||whereStmt||')';
Thanks in advance,
Paruvan |
|
Back to top |
|
 |
|