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:[EMAIL PROTECTED]/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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to