You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Malte Vahlenkamp <Ma...@bdal.de> on 2002/02/06 15:21:19 UTC

DatabaseAction

Hello,
is there a way, to insert the data of an HTML-Form into more than one database table? I have tried to do this via a database action (org.apache.cocoon.acting.DatabaseAddAction) and the following mapping: 




<root>
  <parameter name="ProjectId" type="long" nullable="no"/>
  <parameter name="ProjectName" type="string" min-len="5" max-len="64"/>
  <parameter name="UserId" type="long" nullable="no"/>

  <connection>demo</connection>
  <table name="projects">
    <keys>
      		<key param="ProjectId" dbcol="projectid" type="int" mode="manual"/>
    </keys>
    <values>
      <value param="ProjectName" dbcol="projectname" type="string"/>
      <value param="UserId" dbcol="userid" type="string"/>
    </values>  		            
    
   <table name="userprojects">	    	      		    
	    <keys>
      		<key param="ProjectId" dbcol="projectid" type="int"/>
            </keys>
	    <values>      	      				
		<value param="UserId" dbcol="userid" type="int"/>
	    </values>    
      </table>          	        
  </table>                	    
</root>


This mapping works fine for the first table, but tries to insert a ProjectId of NULL into the second table. What I want is to insert the generated key of the first table instead.

Any ideas how to do this? 

Thanks for your time

  Malte


======================================================
Malte Vahlenkamp
Bruker Daltonik GmbH
Fahrenheitstr. 4
28359 Bremen, Germany
Phone: +49-421-2205-486
email: mv@bdal.de
======================================================


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


Re: DatabaseAction

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 06.Feb.2002 -- 03:21 PM, Malte Vahlenkamp wrote:
> Hello,
> is there a way, to insert the data of an HTML-Form into more than one database table? I have tried to do this via a database action (org.apache.cocoon.acting.DatabaseAddAction) and the following mapping: 
> 
>   <table name="projects">
>     <keys>
>       <key param="ProjectId" dbcol="projectid" type="int" mode="manual"/>
>     </keys>
>     <values>
>       <value param="ProjectName" dbcol="projectname" type="string"/>
>       <value param="UserId" dbcol="userid" type="string"/>
>     </values>  		            
>     
>    <table name="userprojects">	    	      		    
> 	<keys>
>         <key param="ProjectId" dbcol="projectid" type="int"/>
>       </keys>
> 	<values>      	      				
> 	  <value param="UserId" dbcol="userid" type="int"/>
> 	</values>    
>    </table>          	        
>  </table>          	        
> 
> This mapping works fine for the first table, but tries to insert a ProjectId of NULL into the second table. What I want is to insert the generated key of the first table instead.

AFAIK Database Action sets request attributes with the following
naming scheme

"org.apache.cocoon.acting.AbstractDatabaseAction:"+key

so you'd need to read from
org.apache.cocoon.acting.AbstractDatabaseAction:ProjectId and hope
that there's no request parameter of that name because it will have
precedence. 

Although still not prime time (helper handling needs complete redo)
you might want to check out the ModularDatabaseActions from the
scratchpad directory. I wouldn't advise using them for mission
critical work right now because they will change a bit before they
will migrate to the main trunk but it might still be worth a look.
Note that their descriptor format differs from the above.

BTW: one closing tag </table> seems to be misplaced above.

	Chris.

-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

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