You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by go...@osmosis.gr on 2003/11/23 18:46:04 UTC

xsp troubles with loops and an esql

hi people

last days i'm in trouble trying to run a "recursive" - like SQL query

in my table are rows with an id column and a column that specify the 
parent_id (row). so when i get a row (with id=10 for example) the i have 
to ask all the rows with the value 10 in column patent_id (but for each 
row and before get the next row-results i have to run a SQL query that
search for all rows that are have parent_id = this row id) and so on....


i have a succesfull output using an .xsp with hand coded nested esql 
queries (3 or 4 levels) 

the problem is tha i dont know how many levels i have to go.

trying to put this esql query into a function who will call it-self has 
began my odysey.


i need something like 

	<xsp:logic>	
	
		public void getChilds(String parent_id){

			<esql:execute-query>
				<esql:query>select * from tblElements WHERE element_Parent= <xsp:expr>parent_id</xsp:expr></esql:query>
				<esql:results>
				<xsp:logic>parent_id = <esql:get-string column="element_id"/>;</xsp:logic>
				<esql:get-columns/>
				call getChilds(parent_id);
				</esql:results>
			</esql:execute-query>
		}	
		
		getChilds("1");
		
	</xsp:logic>		

what i try to do is to display all elements from the table in a Tree-like view

<element>
<id>5</id>
<parent_id>1</parent_id>
 <element>
 <id>6</id>
 <parent_id>5</parent_id>
 </element>
 <element>
 <id>9</id>
 <parent_id>5</parent_id>
   <element>
   <id>12</id>
   <parent_id>9</parent_id>
   </element>
 </element>
</element>

any idea?

thnx for your replies

--stavros



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xsp troubles with loops and an esql [solved]

Posted by go...@osmosis.gr.
thanx chris 

in the case someone else looking for something similar i post the code 
that now work for me 

i have to add AttributesImpl xspAttr tou my function and put all esql: in 
a try-catch


<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:esql="http://apache.org/cocoon/SQL/v2">
<xsp:logic>	
      void getChilds(String parent_id, AttributesImpl xspAttr)
      {
	try
	{
	<esql:connection>
	<esql:pool>hotpoints</esql:pool>	
	<esql:execute-query>
	<esql:query>select * from tblElements WHERE element_Parent= 
<xsp:expr>parent_id</xsp:expr></esql:query>		
	<esql:results>
		<esql:row-results>
		<element>				
		<xsp:logic>
		parent_id = <esql:get-string column="id_Elements"/>;						
		</xsp:logic>
		<esql:get-columns/>
		<xsp:expr>parent_id</xsp:expr>		
			<xsp:logic>
				getChilds(parent_id, xspAttr);					
			</xsp:logic>		
		</element>
		</esql:row-results>			
	</esql:results>
	<esql:no-results>
	<the_end>done</the_end>
	</esql:no-results>
	</esql:execute-query>
	</esql:connection>					
	}
	catch (Exception e)
	{
	}
     }		
</xsp:logic>		
	
<page>	
	<elements>
	<xsp:logic>
		getChilds("4",xspAttr);		
	</xsp:logic>
	</elements>
</page>
</xsp:page>





On Mon, 24 Nov 2003, Christian Haul wrote:

> gounis@osmosis.gr wrote:
> 
> >hi people
> >
> >last days i'm in trouble trying to run a "recursive" - like SQL query
> >
> >in my table are rows with an id column and a column that specify the 
> >parent_id (row). so when i get a row (with id=10 for example) the i have 
> >to ask all the rows with the value 10 in column patent_id (but for each 
> >row and before get the next row-results i have to run a SQL query that
> >search for all rows that are have parent_id = this row id) and so on....
> >
> >
> >i have a succesfull output using an .xsp with hand coded nested esql 
> >queries (3 or 4 levels) 
> >
> >the problem is tha i dont know how many levels i have to go.
> >
> >trying to put this esql query into a function who will call it-self has 
> >began my odysey.
> >
> >
> >i need something like 
> >
> >	<xsp:logic>	
> >	
> >		public void getChilds(String parent_id){
> >
> >			<esql:execute-query>
> >				<esql:query>select * from tblElements WHERE element_Parent= <xsp:expr>parent_id</xsp:expr></esql:query>
> >				<esql:results>
> >				<xsp:logic>parent_id = <esql:get-string column="element_id"/>;</xsp:logic>
> >				<esql:get-columns/>
> >				call getChilds(parent_id);
> >				</esql:results>
> >			</esql:execute-query>
> >		}	
> >		
> >		getChilds("1");
> >		
> >	</xsp:logic>		
> >
> >what i try to do is to display all elements from the table in a Tree-like view
> >
> ><element>
> ><id>5</id>
> ><parent_id>1</parent_id>
> > <element>
> > <id>6</id>
> > <parent_id>5</parent_id>
> > </element>
> > <element>
> > <id>9</id>
> > <parent_id>5</parent_id>
> >   <element>
> >   <id>12</id>
> >   <parent_id>9</parent_id>
> >   </element>
> > </element>
> ></element>
> >
> >any idea?
> >  
> >
> 
> The key is to pass some more vars to the method like the object model 
> and the document handler. See
> generated source code for details. E.g. the esql logicsheet defines a 
> method that could serve as a blue
> print.
> 
>     Chris.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: xsp troubles with loops and an esql

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
gounis@osmosis.gr wrote:

>hi people
>
>last days i'm in trouble trying to run a "recursive" - like SQL query
>
>in my table are rows with an id column and a column that specify the 
>parent_id (row). so when i get a row (with id=10 for example) the i have 
>to ask all the rows with the value 10 in column patent_id (but for each 
>row and before get the next row-results i have to run a SQL query that
>search for all rows that are have parent_id = this row id) and so on....
>
>
>i have a succesfull output using an .xsp with hand coded nested esql 
>queries (3 or 4 levels) 
>
>the problem is tha i dont know how many levels i have to go.
>
>trying to put this esql query into a function who will call it-self has 
>began my odysey.
>
>
>i need something like 
>
>	<xsp:logic>	
>	
>		public void getChilds(String parent_id){
>
>			<esql:execute-query>
>				<esql:query>select * from tblElements WHERE element_Parent= <xsp:expr>parent_id</xsp:expr></esql:query>
>				<esql:results>
>				<xsp:logic>parent_id = <esql:get-string column="element_id"/>;</xsp:logic>
>				<esql:get-columns/>
>				call getChilds(parent_id);
>				</esql:results>
>			</esql:execute-query>
>		}	
>		
>		getChilds("1");
>		
>	</xsp:logic>		
>
>what i try to do is to display all elements from the table in a Tree-like view
>
><element>
><id>5</id>
><parent_id>1</parent_id>
> <element>
> <id>6</id>
> <parent_id>5</parent_id>
> </element>
> <element>
> <id>9</id>
> <parent_id>5</parent_id>
>   <element>
>   <id>12</id>
>   <parent_id>9</parent_id>
>   </element>
> </element>
></element>
>
>any idea?
>  
>

The key is to pass some more vars to the method like the object model 
and the document handler. See
generated source code for details. E.g. the esql logicsheet defines a 
method that could serve as a blue
print.

    Chris.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org