Commits

Mike Bayer committed 46bb248

- adjust server side logic to work with standalone default execution
- a little bit of inlining of same

Comments (0)

Files changed (2)

lib/sqlalchemy/databases/postgres.py

 
 class PGExecutionContext(default.DefaultExecutionContext):
 
-    def _is_server_side(self):
-        return self.dialect.server_side_cursors and self.is_select() and not re.search(r'FOR UPDATE(?: NOWAIT)?\s*$', self.statement, re.I)
-
     def is_select(self):
         return SELECT_RE.match(self.statement)
         
     def create_cursor(self):
-        if self._is_server_side():
+        # executing a default or Sequence standalone creates an execution context without a statement.  
+        # so slightly hacky "if no statement assume we're server side" logic
+        self.__is_server_side = \
+            self.dialect.server_side_cursors and (self.statement is None or \
+            (SELECT_RE.match(self.statement) and not re.search(r'FOR UPDATE(?: NOWAIT)?\s*$', self.statement, re.I))
+        )
+
+        if self.__is_server_side:
             # use server-side cursors:
             # http://lists.initd.org/pipermail/psycopg/2007-January/005251.html
             ident = "c" + hex(random.randint(0, 65535))[2:]
             return self._connection.connection.cursor()
 
     def get_result_proxy(self):
-        if self._is_server_side():
+        if self.__is_server_side:
             return base.BufferedRowResultProxy(self)
         else:
             return base.ResultProxy(self)

test/profiling/zoomark.py

         metadata.create_all()
         
     @testing.supported('postgres')
-    @profiling.profiled('populate', call_range=(4390, 4420), always=True)        
+    @profiling.profiled('populate', call_range=(4380, 4410), always=True)        
     def test_1a_populate(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']
             tick = i.execute(Species='Tick', Name='Tick %d' % x, Legs=8)
     
     @testing.supported('postgres')
-    @profiling.profiled('properties', call_range=(3440, 3450), always=True)        
+    @profiling.profiled('properties', call_range=(3430, 3440), always=True)        
     def test_3_properties(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']
             ticks = fullobject(Animal.select(Animal.c.Species=='Tick'))
     
     @testing.supported('postgres')
-    @profiling.profiled('expressions', call_range=(13260, 13270), always=True)        
+    @profiling.profiled('expressions', call_range=(13210, 13230), always=True)        
     def test_4_expressions(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']
             assert len(fulltable(Animal.select(func.date_part('day', Animal.c.LastEscape) == 21))) == 1
     
     @testing.supported('postgres')
-    @profiling.profiled('aggregates', call_range=(1270, 1280), always=True)        
+    @profiling.profiled('aggregates', call_range=(1260, 1270), always=True)        
     def test_5_aggregates(self):
         Animal = metadata.tables['Animal']
         Zoo = metadata.tables['Zoo']
             legs.sort()
     
     @testing.supported('postgres')
-    @profiling.profiled('editing', call_range=(1390, 1400), always=True)        
+    @profiling.profiled('editing', call_range=(1380, 1390), always=True)        
     def test_6_editing(self):
         Zoo = metadata.tables['Zoo']
         
             assert SDZ['Founded'] == datetime.date(1935, 9, 13)
     
     @testing.supported('postgres')
-    @profiling.profiled('multiview', call_range=(3160, 3170), always=True)        
+    @profiling.profiled('multiview', call_range=(3150, 3160), always=True)        
     def test_7_multiview(self):
         Zoo = metadata.tables['Zoo']
         Animal = metadata.tables['Animal']