Re: [SQLObject] MySQL and transactions
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Dan P. <da...@ag...> - 2007-10-22 15:18:24
|
On Monday 22 October 2007, Jaime Wyant wrote:
> Hi all. Can anyone tell me why the code below commits rows to the
> table? I've read the documentation and I'm not quite sure why it is
> happening. # BEGIN CODE SNIPPET
> from sqlobject import *
>
> conn = connectionForURI('mysql://user:pass@localhost/test?debug=1')
>
> class TestTable(SQLObject):
> _connection = conn
> col1 = StringCol()
> col2 = StringCol()
>
> TestTable.createTable(ifNotExists = True)
>
> trans = conn.transaction()
> t = TestTable(col1 = 'col1', col2 = 'col2')
> trans.rollback()
>
> # END CODE SNIPPET
> The console output is below. I expected to see a `BEGIN` or `START
> TRANSACTION` somewhere at the beginning of the output, but it is not
> there. Is this a bug, or user error :) ?
I'd say it's an user error. You assigned a non-transactional connection to
the TestTable class (with _connection = conn). The transaction you
created later will not be used with the statements unless you explicitly
say so with:
t = TestTable(col1 = 'col1', col2 = 'col2', connection=trans)
otherwise TestTable._connection will be used, which is non-transactional
>
> 1/Query : DESCRIBE test_table
> 2/QueryIns: INSERT INTO test_table (col2, col1) VALUES ('col2',
> 'col1') 2/QueryOne: SELECT col1, col2 FROM test_table WHERE
> ((test_table.id) = (3))
> 1/ROLLBACK:
>
> Thanks!
> jw
--
Dan
|