Mailing List Archive

roll back
I'm using MS SQL Server 2000 and eGenix mxODBC on W2K3 platform with
Zope 2.7.5.



DTML method:



...

<dtml-try>

<dtml-call "insertMAT(mat_id = '18', mat_name = 'This string is too
long for the attribute',)">

<dtml-except>

<dtml-raise MAT_SQL_FAILURE> <dtml-var error_value></dtml-raise>

</dtml-try>

...



---------

insertMAT ZSQL method:



BEGIN TRANSACTION

insert into mat1 (mat_id)

values (<dtml-sqlvar mat_id type=int>);



insert into mat2 (mat_id, mat_name)

values (<dtml-sqlvar mat_id type=int>, <dtml-sqlvar mat_name
type=string>);



COMMIT TRANSACTION;





Renders the error:

Error Message:('22001', 8152, '[Microsoft][ODBC SQL Server Driver][SQL
Server]String or binary data would be truncated.', 4721)



The error occurs in the insert into mat2 where mat_name is too long. But
the first insert into mat1 is being written and committed.



I understood the entire transaction would be rolled back, either by Zope
as a result of the exception or by MS SQL since the two inserts are
written as a single transaction. Can you please correct my mistake or my
misunderstanding?



Thank you,



Michael Maslak, Jr.
Re: roll back [ In reply to ]
Am 29.08.2006, 22:42 Uhr, schrieb Maslak, Michael
<Michael.Maslak@gdit.com>:

> Can you please correct my mistake or my
> misunderstanding?

Yes, you don't need to explicitly start and commit transactions in ZSQL as
Zoep does this for you.

Charlie
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: roll back [ In reply to ]
Am 30.08.2006, 00:35 Uhr, schrieb Maslak, Michael
<Michael.Maslak@gdit.com>:

> It is allowing a record to be committed in mat1 even as mat2 fails.
> There is no roll back happening.

Normally, if you leave the transaction management to Zope and the RDBMS
can manage it, then all transactions will indeed be rolled back by Zope if
one fails. So, remove the transactional logic from your ZSQL and your
problems should be over.

Charlie
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: roll back [ In reply to ]
Am 30.08.2006, 00:44 Uhr, schrieb Maslak, Michael
<Michael.Maslak@gdit.com>:

> Did what you suggested. That is, removed the BEGIN TRANSACTION & COMMIT
> TRANSACTION statements. It has the same behavior: a non-atomic commit.
> No roll back. mat1 has a new record mat2 errors.

Please keep your reply on list.

<dtml-except>

<dtml-raise MAT_SQL_FAILURE> <dtml-var error_value></dtml-raise>

I don't use DTML - but if your DTML maps to a
try:
this()
except:
that()

Then you are still acting outside the Zope transactional management! I
suggest you rewrite your code to use two ZSQL methods and call them from a
PythonScript
simply
context.mat_1()
content.mat_2()

It's easier than you think.

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