Changeset 3592

Show
Ignore:
Timestamp:
11/03/07 05:54:16 (1 year ago)
Author:
paj
Message:

Workaround in paginate for databases without OFFSET.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/CHANGELOG.txt

    r3579 r3592  
    1212    * Introduction of tg.mochikit_suppress to prevent the inclusion of  
    1313      the shipped MochiKit 1.3.1. That allows to include custom mochikit versions. 
     14    * Ticket #1601. Workaround in paginate for databases without OFFSET. 
    1415 
    1516*Fixes* 
    1617    * Ticket #1595. Fixed broken quickstart change. 
     18     
     19*Contributors* 
     20 
     21Joel Pearson 
    1722 
    18231.0.4b2 (October, 27, 2007): 
  • branches/1.0/turbogears/paginate.py

    r3527 r3592  
    3131 
    3232log = logging.getLogger("turbogears.paginate") 
     33 
     34# lists of databases that lack support for OFFSET 
     35# this will need to be updated periodically as modules change 
     36_so_no_offset = 'mssql maxdb sybase'.split() 
     37_sa_no_offset = 'mssql maxdb access'.split() 
     38 
     39# this is a global that is set the first time paginate() is called 
     40_simulate_offset = None 
    3341 
    3442def paginate(var_name, default_order='', default_reversed=False, limit=10, 
     
    201209            endpoint = offset + limit_ 
    202210            log.debug("slicing data between %d and %d", offset, endpoint) 
    203             output[var_name] = var_data[offset:endpoint] 
     211 
     212            global _simulate_offset 
     213            get = turbogears.config.get 
     214            if _simulate_offset is None: 
     215                _simulate_offset = get('paginate.simulate_offset', None) 
     216                if _simulate_offset is None: 
     217                    _simulate_offset = False 
     218                    so_db = get('sqlobject.dburi', 'NOMATCH:').split(':', 1)[0] 
     219                    sa_db = get('sqlalchemy.dburi', 'NOMATCH:').split(':', 1)[0] 
     220                    if so_db in _so_no_offset or sa_db in _sa_no_offset: 
     221                        _simulate_offset = True 
     222                        log.warning("simulating OFFSET, paginate may be slow") 
     223                        log.warning("to turn off, set " 
     224                                     "paginate.simulate_offset=False") 
     225 
     226            if _simulate_offset: 
     227                var_data_iter = iter(var_data[:endpoint]) 
     228                # skip over the number of records specified by offset 
     229                for i in range(offset):    
     230                    var_data_iter.next() 
     231                # return the records that remain 
     232                output[var_name] = list(var_data_iter) 
     233            else: 
     234                output[var_name] = var_data[offset:endpoint] 
    204235 
    205236            return output