Hi all,

I'm trying to better understand the rowcount issue, starting from
ticket:370.

Currently Firebird has both 'supports_sane_rowcount' and
'supports_sane_multi_rowcount' set to False. I do not exactly get what
"sane" means there... seeing the result of my tests (below).

Maybe something changed from my last checks on
it (in fact, AFAIK the multi version of the flag was introduced later
than then...), but the strange thing is that setting the first one, ie
'supports_sane_rowcount' to True does not trigger any test failure
anymore, while there are still failures when the second flag is set to
True.

I wrote the attached test/orm/rowcount.py script mimicing
test/sql/rowcount.py in a cascading scenario, but again I must be
misunderstanding the "sane" meaning, because both test succeed on
Firebird...

Can you point me to a more correct way of testing the expected
behaviour of "sane_multi_rowcount"? And given new results on
"sane_rowcount", is it right turning it to True on Firebird too?

thank you,
ciao, lele.
-- 
nickname: Lele Gaifax    | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas    | comincerò ad aver paura di chi mi copia.
[EMAIL PROTECTED] |                 -- Fortunato Depero, 1929.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

import testbase

from sqlalchemy import *
from sqlalchemy.orm import *
from testlib import *

class MultiRowCountTest(AssertMixin):
    """Test rowcount in a cascading context"""
    
    def setUpAll(self):
        global metadata, Author, Book, Account, authors_table, books_table, accounts_table
        
        metadata = MetaData(testbase.db)

        authors_table = Table("authors", metadata,
                              Column("id", Integer, Sequence("s_authors_id", optional=True), primary_key=True),
                              Column("name", String(100), unique=True, nullable=False))
        books_table = Table("books", metadata,
                            Column("id", Integer, Sequence("s_books_id", optional=True), primary_key=True),
                            Column("author_id", Integer),
                            Column("title", String(50), nullable=False),
                            ForeignKeyConstraint(["author_id"], ["authors.id"], ondelete="SET NULL", onupdate="CASCADE"))
        accounts_table = Table('accounts', metadata,
                               Column('author_id', Integer, primary_key=True),
                               Column('amount', Float()),
                               ForeignKeyConstraint(["author_id"], ["authors.id"], ondelete="CASCADE", onupdate="CASCADE"))

        metadata.create_all()

        class Author(object):
            def __init__(self, name):
                self.name = name
        class Book(object):
            def __init__(self, title):
                self.title = title
        class Account(object):
            def __init__(self, money):
                self.amount = money

        mapper(Author, authors_table, properties={
            'books': relation(Book, backref="author", lazy=True, cascade='all, delete-orphan', passive_deletes=True),
            'account': relation(Account, backref="author", lazy=True, uselist = False, cascade='all, delete-orphan'),
            })
        mapper(Book, books_table)
        mapper(Account, accounts_table)

    def setUp(self):
        session = create_session()
        
        # Some authors
        t = Author('Tolkien')
        b = Author('Baricco')
        a = Author('Asimov')
        
        # Some books
        lotr = Book('Lord of the rings')
        ts = Book('The silmarillion')
        
        ss = Book('Senza sangue')
        om = Book('Oceano mare')

        f = Book('Foundation')
        ir = Book('I, Robot')
        
        t.books.append(lotr)
        t.books.append(ts)

        b.books.append(ss)
        b.books.append(om)

        a.books.append(f)
        a.books.append(ir)
        
        # Some money

        t.account = Account(100)
        b.account = Account(50)
        a.account = Account(66)

        session.save(t)
        session.save(b)
        session.save(a)
        session.flush()

    def tearDown(self):
        accounts_table.delete().execute()
        books_table.delete().execute()
        authors_table.delete().execute()
        
    def tearDownAll(self):
        metadata.drop_all()

    def testbasic(self):
        session = create_session()

        t = session.query(Author).filter(Author.name=='Baricco').one()
        assert len(t.books) == 2
        
    def test_ticket_370(self):
        session = create_session()

        t = session.query(Author).filter(Author.name=='Asimov').one()
        session.delete(t)
        session.flush()

        assert books_table.count().scalar() == 6
        assert accounts_table.count().scalar() == 2

    def test_multi_rowcount(self):
        id,name = authors_table.c.id,authors_table.c.name
        
        r = authors_table.update(name=='Tolkien').execute(id=100)
        print "expecting 1, dialect reports %s" % r.rowcount
        if testbase.db.dialect.supports_sane_multi_rowcount:
            assert r.rowcount == 1
        assert accounts_table.select(accounts_table.c.author_id==100).count().scalar() == 1
        
        r = authors_table.delete(name=='Baricco').execute()
        print "expecting 1, dialect reports %s" % r.rowcount
        if testbase.db.dialect.supports_sane_multi_rowcount:
            assert r.rowcount == 1
        
if __name__ == '__main__':
    testbase.main()




Reply via email to