On Tue, Mar 21, 2006 at 10:46:25AM +0100, David Faure wrote:
> On Tuesday 21 March 2006 10:24, Oleg Broytmann wrote:
> > > for i in xrange(100):
> > >         print i
> > > 
> > >         try:
> > >                 agg = Aggregates.select(connection = t, forUpdate = 
> > > True).getOne()
> > >         except:
> > >                 agg = Aggregates(total = 0, connection = t)
> > 
> >    I have a problem converting the test to SQLObject. In the beginning the
> > test database is always empty so .select() always raises a "not found"
> > exception.
> ... which is caught by the "except:", and then a row is created by that 
> Aggregates constructor, isn't it?

   Not with the SQLObject tests.

> I must be misunderstanding the issue.
> Do you mean that it creates trouble when two instances of the script are 
> running
> in parallel? It is true that I always ran it once first, to create the row.
> This probably means that there should be some initialization code ran first.

   Please add the initializations. I've converted the test to the SQLObject
test and it is:

from sqlobject import *
from dbtest import *

class BaseSQLObject(SQLObject):
    class sqlmeta:
        cacheValues = False

class Aggregates(BaseSQLObject):
    total = IntCol()

class AggValues(BaseSQLObject):
    value = IntCol()

def test_1():
    if not supports('selectForUpdate'):
        return
    setupClass([Aggregates, AggValues])

    t = Aggregates._connection.transaction()

    for i in xrange(100):
        try:
            agg = Aggregates.select(connection=t, forUpdate=True).getOne()
        except:
            agg = Aggregates(total=0, connection=t)

        newVal = i % 10 + 1
        agg.total = agg.total + newVal
        newValue = AggValues(value=newVal, connection=t)
        t.commit()

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to