Beispiel #1
0
 def _reset_state(self):
     self._buffer = []
     self._rowcount = -1
     self._description = None
     if self._last_operation_active:
         self._last_operation_active = False
         rpc.close_query(self.service, self._last_operation_handle)
     self._last_operation_string = None
     self._last_operation_handle = None
Beispiel #2
0
 def _execute_sync(self, operation_fn):
     # operation_fn should set self._last_operation_string and
     # self._last_operation_handle
     self._reset_state()
     operation_fn()
     self._last_operation_active = True
     self._wait_to_finish()  # make execute synchronous
     if self.has_result_set:
         schema = rpc.get_results_metadata(self.service,
                 self._last_operation_handle)
         self._description = [tuple([tup.name, tup.type.upper()] + [None, None, None, None, None]) for tup in schema]
     else:
         self._last_operation_active = False
         rpc.close_query(self.service, self._last_operation_handle)
Beispiel #3
0
 def next(self):
     if not self.has_result_set:
         raise ProgrammingError("Trying to fetch results on an operation with no results.")
     if len(self._buffer) > 0:
         return self._buffer.pop(0)
     elif self._last_operation_active:
         # self._buffer is empty here and op is active: try to pull more rows
         rows = rpc.fetch_internal(self.service,
                 self._last_operation_handle, self.buffersize)
         self._buffer.extend(rows)
         if len(self._buffer) == 0:
             self._last_operation_active = False
             rpc.close_query(self.service, self._last_operation_handle)
             raise StopIteration
         return self._buffer.pop(0)
     else:
         # empty buffer and op is now closed: raise StopIteration
         raise StopIteration
Beispiel #4
0
 def close_operation(self):
     if self._last_operation_active:
         self._last_operation_active = False
         rpc.close_query(self.service, self._last_operation_handle)