[Zope] transaction control from Zope to Postgresql?

Reinoud van Leeuwen reinoud@xs4all.nl
Fri, 8 Jun 2001 13:40:02 +0200 (CEST)


Hello world,

I am in need for a way to explicitely contral transaction behaviour for a 
group of inserts in a postgresql database. The DTML script I use first 
inserts a header record and after that some detail records. The postgresql 
function that does the inserts might return an errorstring. So I tried the 
following code (simplified for readability)

<dtml-try>
  <dtml-call "sql_to_insert_head_record (some_parameters)">

  <dtml-in "a_loop_over_detail_lines">
    <dtml-if "check_detail_line">
      <dtml-raise required_attribute_missing> errormessage </dtml-raise>
    </dtml-if>

    <dtml-call "sql_to_insert_detail_line">
    <dtml-if "check_returncode">
      <dtml-raise inserterror> error inserting! </dtml-raise>
    </dtml-if>
  </dtml-in>

<dtml-except>
 insert failed (error: <dtml-var error_value>)
<dtml-else>
  object added to database
</dtml-try>

What I would like to do is that all the SQL executed between dtml-try and 
dtml-except is rolled back when the exception is raised. I tried 
sending "begin" and "rollback" to the database, but that does not work 
because Zope sends some transaction control by itself.
I tried getting get_transaction().begin() and get_transaction().abort() to 
work, but I cannot reach that function from dtml not python script. 
Anyone has some clues to spare?

Have a nice weekend,
Reinoud