You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mike Dickson <mi...@yahoo.com> on 2004/04/24 04:16:50 UTC

Database Insert Across Multiple Tables

We are using Cocoon 2.1/MySQL 4.0.16 and have user data from a HTML form
that needs to be inserted into two tables inside a single transaction.
Inserts into a single table seem to be simple, but into multiple tables is
little harder...

How should I accomplish this?

I have looked at <table-set> in the new Cocoon 2.1 Database Actions, but am
stumped as to how to use them from the docs.  Sorry Reinhard Horn!  :-)


Thanks,

Mike Dickson
DayScribe.com Founder


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


Re: Database Insert Across Multiple Tables

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Mike Dickson wrote:
> <mode name="request-param" type="request"/> means that there is a param
> named request?

No - it means that the value should be obtained from an input module 
called "request-param" but only if the table-set indicated to use
the modes labled "request". IOW, "request" is just an arbitrary lable 
with no inherent meaning.


    <table-set name="user_groups">
       <table name="user_groups" others-mode="request"/>
    </table-set>

Chris.

>>-----Original Message-----
>>From: Christian Haul [mailto:haul@informatik.tu-darmstadt.de]
>>
>>Please have a look at the descriptor.xml (I've removed the comments):
>>
>>    <table name="user_groups">
>>       <keys>
>>          <key name="uid" type="int">
>>             <mode name="request-param" type="request"/>
>>             <mode name="request-attr" type="attrib">
>>
>><parameter>org.apache.cocoon.components.modules.output.OutputM
>>odule:user.uid[0]</parameter>
>>             </mode>
>>          </key>
>>          <key name="gid" type="int" set="master">
>>             <mode name="request-param" type="all"/>
>>          </key>
>>       </keys>
>>    </table>

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


RE: Database Insert Across Multiple Tables

Posted by Mike Dickson <mi...@yahoo.com>.
<mode name="request-param" type="request"/> means that there is a param
named request?

> -----Original Message-----
> From: Christian Haul [mailto:haul@informatik.tu-darmstadt.de]
> Sent: Tuesday, April 27, 2004 3:08 PM
> To: users@cocoon.apache.org
> Subject: Re: Database Insert Across Multiple Tables
>
>
> Mike Dickson wrote:
> > When you hit the "new user" button in the Modular Database
> Actions demo
> > application it does a GET with the user info and the group
> info.  Why are
> > only the user data listed below as params?  Shouldn't the
> group data be also
> > listed as params?
>
> Oh well, this is only a guard -- a condition that protects the
> invocation of the insert with a check that the most important
> attributes
> are present. The add action reads the data directly from the request.
>
> > In other words, how are the group params being passed in?
>
> Please have a look at the descriptor.xml (I've removed the comments):
>
>     <table name="user_groups">
>        <keys>
>           <key name="uid" type="int">
>              <mode name="request-param" type="request"/>
>              <mode name="request-attr" type="attrib">
>
> <parameter>org.apache.cocoon.components.modules.output.OutputM
> odule:user.uid[0]</parameter>
>              </mode>
>           </key>
>           <key name="gid" type="int" set="master">
>              <mode name="request-param" type="all"/>
>           </key>
>        </keys>
>     </table>
>
> There are two <mode/> declarations for the UID column. The
> second is the
> one you may care about: It accesses a request attribute instead of a
> request parameter. The attribute will be set by the preceeding insert
> to the users table! This is necessary, since the UID is a
> autoincrement
> column and the value is known only after the insert.
>
> However, the "GID" data is read from a request parameter
> again (because
> it has been entered by the user on the form).
>
> 	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: Database Insert Across Multiple Tables

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Mike Dickson wrote:
> When you hit the "new user" button in the Modular Database Actions demo
> application it does a GET with the user info and the group info.  Why are
> only the user data listed below as params?  Shouldn't the group data be also
> listed as params?

Oh well, this is only a guard -- a condition that protects the 
invocation of the insert with a check that the most important attributes 
are present. The add action reads the data directly from the request.

> In other words, how are the group params being passed in?

Please have a look at the descriptor.xml (I've removed the comments):

    <table name="user_groups">
       <keys>
          <key name="uid" type="int">
             <mode name="request-param" type="request"/>
             <mode name="request-attr" type="attrib">
 
<parameter>org.apache.cocoon.components.modules.output.OutputModule:user.uid[0]</parameter>
             </mode>
          </key>
          <key name="gid" type="int" set="master">
             <mode name="request-param" type="all"/>
          </key>
       </keys>
    </table>

There are two <mode/> declarations for the UID column. The second is the 
one you may care about: It accesses a request attribute instead of a 
request parameter. The attribute will be set by the preceeding insert
to the users table! This is necessary, since the UID is a autoincrement 
column and the value is known only after the insert.

However, the "GID" data is read from a request parameter again (because 
it has been entered by the user on the form).

	Chris.

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


RE: Database Insert Across Multiple Tables

Posted by Mike Dickson <mi...@yahoo.com>.
When you hit the "new user" button in the Modular Database Actions demo
application it does a GET with the user info and the group info.  Why are
only the user data listed below as params?  Shouldn't the group data be also
listed as params?

In other words, how are the group params being passed in?

<!--

 add one new user plus groups

-->
<map:act type="req-params">
	<map:parameter name="parameters" value="add-user-groups user.name
user.firstname user.uname"/>
	<map:act type="mod-db-add">
		<map:parameter name="table-set" value="user+groups"/>
	</map:act>
</map:act>

> -----Original Message-----
> From: Christian Haul [mailto:haul@informatik.tu-darmstadt.de]
> Sent: Saturday, April 24, 2004 10:45 AM
> To: users@cocoon.apache.org
> Subject: Re: Database Insert Across Multiple Tables
>
>
> Mike Dickson wrote:
> > We are using Cocoon 2.1/MySQL 4.0.16 and have user data
> from a HTML form
> > that needs to be inserted into two tables inside a single
> transaction.
> > Inserts into a single table seem to be simple, but into
> multiple tables is
> > little harder...
> >
> > How should I accomplish this?
> >
> > I have looked at <table-set> in the new Cocoon 2.1 Database
> Actions, but am
> > stumped as to how to use them from the docs.  Sorry
> Reinhard Horn!  :-)
>
> Could you elaborate a little more on were you're stuck?
> Essentially, you
> just list multiple tables in a table set and ask the action to use it.
> The sample that comes with Cocoon does it BTW.
>
> 	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: Database Insert Across Multiple Tables

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Mike Dickson wrote:
> We are using Cocoon 2.1/MySQL 4.0.16 and have user data from a HTML form
> that needs to be inserted into two tables inside a single transaction.
> Inserts into a single table seem to be simple, but into multiple tables is
> little harder...
> 
> How should I accomplish this?
> 
> I have looked at <table-set> in the new Cocoon 2.1 Database Actions, but am
> stumped as to how to use them from the docs.  Sorry Reinhard Horn!  :-)

Could you elaborate a little more on were you're stuck? Essentially, you
just list multiple tables in a table set and ask the action to use it.
The sample that comes with Cocoon does it BTW.

	Chris.

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