Hi All,
I'm having trouble rolling back a transaction and wanted to know if
the problem is me, web.py, or MySQL. Perhaps I just don't understand
how this should work.
Basically, I have a tables
mysql> CREATE TABLE foo (bar FLOAT);
And I try to insert or update some values. In some cases, MySQL cause
the exception to be thrown (such as inserting into a table that
doesn't exist) and in other cases I try to manually throw an
exception.
// Python Code
from __future__ import with_statement
import web
db = web.database(dbn='mysql', db='databse', user='user',
pw='password')
t = db.transaction()
try:
db.insert('foo',bar=2.0)
db.insert('foo',bar='sghsglhslhsdgh')
db.insert('DoesNotExist',bar=-1)
raise Exception
except:
print 'ROLLBACK'
t.rollback()
else:
print 'COMMIT'
t.commit()
with db.transaction():
db.insert('foo',bar=3.0)
db.insert('foo',bar='g')
db.insert('DoesNotExist',bar=-1)
Running that code produces:
/usr/lib/python2.5/site-packages/web/db.py:472: Warning: Data
truncated for column 'bar' at row 1
for x in sql_query.values()])
ROLLBACK
Traceback (most recent call last):
File "test.py", line 21, in <module>
db.insert('DoesNotExist',bar=-1)
File "/usr/lib/python2.5/site-packages/web/db.py", line 625, in
insert
self._db_execute(db_cursor, q1)
File "/usr/lib/python2.5/site-packages/web/db.py", line 472, in
_db_execute
for x in sql_query.values()])
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
166, in execute
self.errorhandler(self, exc, value)
File "/var/lib/python-support/python2.5/MySQLdb/connections.py",
line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, "Table 'ibm.DoesNotExist'
doesn't exist")
Yet the database doesn't seem to rollback.
mysql> SELECT * FROM foo;
+------+
| bar |
+------+
| 2 |
| 0 |
| 3 |
| 0 |
+------+
I'm using web.py 0.3 and MySQL Server version: 5.0.51a-3ubuntu5.1
(Ubuntu). Any help would be appreciated.
Thanks,
--Ian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---