Mailing List Archive

Process one PloneFormGen request into many SQL tables
Hi all !

I am just starting with using Zope/Plone and mySQL(InnoDB) and am
hitting every bump on the road as I go :P

I have a Form (generated with PloneFormGen+DataGridField) and I need
to send the data entered there into several mySQL tables. I am
guessing a Python script would be the right thing here.(?)

My main questions right now are:

1) How do I maintain referencial integrity?
I need to get LAST_INSERT_ID() from the first INSERT to use on the
following inserts.
Could I have a ZSQL Method that does the insert and returns the
generated ID to the Python script?

2) Is a ZSQL Method automatically executed as a transaction? Or do I
need to manually define BEGIN; COMMIT; to guarantee I am getting the
correct data?

3) Where can I find example code (zsql, python scripts) dealing with
many related tables? All tutorials I found deal with only one table at
a time, completely ignoring the relational part of the database.


Thanks !

--
Paul Eipper
Brasil
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
Hi,

if you want to do things like this, you also could use the alchmist product.
However, I think the archetype / plone formgen integration at the moment
is not functional. (ask kapil t. and roché c. for closer info)
You would have to start out with plain zope 3 schema and formlib like in
the alchemist included orgpeople example.
I developed a neat little application that uses the unit of work and
automatic transaction support of sql alchemy and all dependent tables
are deleted, updated and inserted automatically by the mapper
(www.*sqlalchemy*.org/)

Dennis


Paul Eipper escribió:
> Hi all !
>
> I am just starting with using Zope/Plone and mySQL(InnoDB) and am
> hitting every bump on the road as I go :P
>
> I have a Form (generated with PloneFormGen+DataGridField) and I need
> to send the data entered there into several mySQL tables. I am
> guessing a Python script would be the right thing here.(?)
>
> My main questions right now are:
>
> 1) How do I maintain referencial integrity?
> I need to get LAST_INSERT_ID() from the first INSERT to use on the
> following inserts.
> Could I have a ZSQL Method that does the insert and returns the
> generated ID to the Python script?
>
> 2) Is a ZSQL Method automatically executed as a transaction? Or do I
> need to manually define BEGIN; COMMIT; to guarantee I am getting the
> correct data?
>
> 3) Where can I find example code (zsql, python scripts) dealing with
> many related tables? All tutorials I found deal with only one table at
> a time, completely ignoring the relational part of the database.
>
>
> Thanks !
>
> --
> Paul Eipper
> Brasil
> _______________________________________________
> Zope-DB mailing list
> Zope-DB@zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
>
>


_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
(this list replies to authors instead of the list as default >_< )

---------- Forwarded message ----------
From: Paul Eipper <lkraider@gmail.com>
Date: 19/01/2007 13:52
Subject: Re: [Zope-DB] Process one PloneFormGen request into many SQL tables
To: d.schulz81@gmx.net


Hi Dennis,

I was referred to the alchemist product by the PloneFormGen dev, but
unfortunatelly I found the documentation for it extremely lacking (as
in nonexistant :P)

Since I am only learning all this, I can't take a product where there
aren't at least intro docs for it and try to figure it all out by
myself :(

The only thing i could find is a video presentation that I will be
taking a look at this weekend. Maybe it will serve as a good intro
doc. For now I am trying to make it work using Python scripts + ZSQL
methods manually.

Would alchemist really simplify the coding? (/me has no idea)

Thanks for the reply!

--
Paul Eipper
Brasil

2007/1/19, Dennis Schulz <d.schulz81@gmx.net>:
> Hi,
>
> if you want to do things like this, you also could use the alchmist product.
> However, I think the archetype / plone formgen integration at the moment
> is not functional. (ask kapil t. and roché c. for closer info)
> You would have to start out with plain zope 3 schema and formlib like in
> the alchemist included orgpeople example.
> I developed a neat little application that uses the unit of work and
> automatic transaction support of sql alchemy and all dependent tables
> are deleted, updated and inserted automatically by the mapper
> (www.*sqlalchemy*.org/)
>
> Dennis
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
Am 19.01.2007, 14:30 Uhr, schrieb Paul Eipper <lkraider@gmail.com>:

> I have a Form (generated with PloneFormGen+DataGridField) and I need
> to send the data entered there into several mySQL tables. I am
> guessing a Python script would be the right thing here.(?)

Can't tell you much about what the Plone thing wants but a PythonScript is
probably indeed what you want.

> My main questions right now are:
> 1) How do I maintain referencial integrity?
> I need to get LAST_INSERT_ID() from the first INSERT to use on the
> following inserts.
> Could I have a ZSQL Method that does the insert and returns the
> generated ID to the Python script?

Yes, or you could call do this call directly in SQL or possibly even in
the default for a particularl relational variable.

> 2) Is a ZSQL Method automatically executed as a transaction? Or do I
> need to manually define BEGIN; COMMIT; to guarantee I am getting the
> correct data?

Yes.

> 3) Where can I find example code (zsql, python scripts) dealing with
> many related tables? All tutorials I found deal with only one table at
> a time, completely ignoring the relational part of the database.

Well, to be honest they only show you how to use SQL from within Zope
which is essentially write the SQL yourself and let Zope help you manage
your variables.

Charlie
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
Hi Paul,

Ok to tell you honestly the truth, as a beginner you should try to leave
your fingers of zope 3 /alchemist.
The learning curve is steep.
You will have to learn about Zope 3 widgets, schemas, interfaces,
adapters....
You have to know how to configure the mapper, have to know how to handle
the mapped objects....
And there is a lot of automatic machinery in the background going on
such as automatic interface generation, formlib machinery etc. you have
to be aware of.

I am currently writing my final project about it and to figure out all
this it took me a lot of time....

Unfortunately I dont have much experience with Archetypes Widgets or
PloneFormGen so I can't really help you.

But what you could certainly do is to write a zope 2 filesystem product
that uses archetypes widgets.
I personally prefer not to use zsql methods since they include very
special DTML systax and variables and stuff you dont need anywhere else.
You can also query the database adapter directly when you have a product.
Here an example: (conn is the db connection)
sql = "select max(a.idAmendment) as last_id from
cyc_Amendments a"
resultset = conn.manage_test(sql)
result = int(resultset[0][0])

Or learn how to use SQLAlchemy, it really is a usefull toolkit you can
also use standalone.


Dennis

Paul Eipper escribió:
> (this list replies to authors instead of the list as default >_< )
>
> ---------- Forwarded message ----------
> From: Paul Eipper <lkraider@gmail.com>
> Date: 19/01/2007 13:52
> Subject: Re: [Zope-DB] Process one PloneFormGen request into many SQL
> tables
> To: d.schulz81@gmx.net
>
>
> Hi Dennis,
>
> I was referred to the alchemist product by the PloneFormGen dev, but
> unfortunatelly I found the documentation for it extremely lacking (as
> in nonexistant :P)
>
> Since I am only learning all this, I can't take a product where there
> aren't at least intro docs for it and try to figure it all out by
> myself :(
>
> The only thing i could find is a video presentation that I will be
> taking a look at this weekend. Maybe it will serve as a good intro
> doc. For now I am trying to make it work using Python scripts + ZSQL
> methods manually.
>
> Would alchemist really simplify the coding? (/me has no idea)
>
> Thanks for the reply!
>
> --
> Paul Eipper
> Brasil
>
> 2007/1/19, Dennis Schulz <d.schulz81@gmx.net>:
>> Hi,
>>
>> if you want to do things like this, you also could use the alchmist
>> product.
>> However, I think the archetype / plone formgen integration at the moment
>> is not functional. (ask kapil t. and roché c. for closer info)
>> You would have to start out with plain zope 3 schema and formlib like in
>> the alchemist included orgpeople example.
>> I developed a neat little application that uses the unit of work and
>> automatic transaction support of sql alchemy and all dependent tables
>> are deleted, updated and inserted automatically by the mapper
>> (www.*sqlalchemy*.org/)
>>
>> Dennis
> _______________________________________________
> Zope-DB mailing list
> Zope-DB@zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
>
>


_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
Thanks for all the responses, they really help

> > 2) Is a ZSQL Method automatically executed as a transaction? Or do I
> > need to manually define BEGIN; COMMIT; to guarantee I am getting the
> > correct data?
> Yes.

Hmm, that was "Yes, it does the transaction thing automatically." or a
"Yes, you need to do it manually." ??

Dennis, I will start looking at SQLAlchemy, it sounds very
interesting. I was under the impression I needed alchemist to work
with that on Zope.

At a point I was really thinking in doing it all with mySQL stored
procedures, but thought that doing the actual logic in Python would be
much better, since I would have to learn the stored procedures
'language' also otherwise.

Anyways, I am progressing with scripting in Python code here, even if
very slowly :P

Best Regards,
--
Paul Eipper
Brasil
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Process one PloneFormGen request into many SQL tables [ In reply to ]
Am 19.01.2007, 20:10 Uhr, schrieb Paul Eipper <lkraider@gmail.com>:

> Hmm, that was "Yes, it does the transaction thing automatically." or a
> "Yes, you need to do it manually." ??

It is done within a Zope transaction so you don't have to do anything.

> Dennis, I will start looking at SQLAlchemy, it sounds very
> interesting. I was under the impression I needed alchemist to work
> with that on Zope.

> At a point I was really thinking in doing it all with mySQL stored
> procedures, but thought that doing the actual logic in Python would be
> much better, since I would have to learn the stored procedures
> 'language' also otherwise.

Your database should manage your data, not your application.

> Anyways, I am progressing with scripting in Python code here, even if
> very slowly.

Gently does it.

Charlie


_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db