On May 14, 2007, at 1:28 AM, Sanjay wrote: > >> Further findings and queries on SelectResults: >> >> 1. Is SelectResults still needed in certain situations: >> >> a. Observed that SelectResults was having a count() method. If we >> don't use SelectResults, either we have to query the database for >> getting the count manually, or use len(list). Using 'len' may not be >> recommended in paginated data grids.
query has a count() method as well. >> >> b. Seeing the TurboGears code for 'paginate', it checks for the type >> of variable. If it is a list, it just applies len(list)! Does that >> mean, we have to explicitly use SelectResults with TurboGears? Pylons has taken this issue into account with its own paginage function: http://pylonshq.com/docs/0.9.5/module-webhelpers.pagination.html the size of the list is passed separately (which is typically achieved via a single count() call), if not present uses len(list). TG should follow this example. >> >> 2. SelectResults not behaving properly: >> >> I have some code which returns a list although I expect a >> SelectResults. Here is the minimal version reproducing that. Can't >> guess whether I am doing something wrong or it's a bug. Need help. >> >> from sqlalchemy import * >> from sqlalchemy.ext.assignmapper import assign_mapper >> from sqlalchemy.ext.sessioncontext import SessionContext >> import sqlalchemy.mods.selectresults >> >> context = SessionContext(create_session) >> session = context.current >> >> metadata = BoundMetaData('sqlite:///satest', echo=True) >> >> # table definitions >> person_table = Table('person', metadata, >> Column('person_id', Integer, primary_key=True, autoincrement = >> True), >> Column('first_name', Unicode(30)), >> Column('last_name', Unicode(30))) >> >> metadata.drop_all() >> metadata.create_all() >> >> class Person(object): >> pass >> >> assign_mapper(context, Person, person_table) >> >> p1 = Person(first_name="Sanjay", last_name="Patel") >> p2 = Person(first_name="Ranjan", last_name="Naik") >> session.flush() >> del p1 >> del p2 >> session.clear() >> # persons = Person.select_by(person_id=1) >> # assert isinstance(persons, >> sqlalchemy.ext.selectresults.SelectResults) # OK >> persons = Person.select(Person.c.person_id.in_(1)) >> assert isinstance(persons, >> sqlalchemy.ext.selectresults.SelectResults) >> # Fails! this was a small bug that was fixed in trunk a few weeks ago. SelectResults is deprecated anyway and its easier to use query directly. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
