@@ -129,7 +129,7 @@ def __init__(self, connection, statement, parameters):
129
129
super (ResultCursor , self ).__init__ ()
130
130
self .statement = statement
131
131
self .parameters = parameters
132
- self .keys = None
132
+ self ._keys = None
133
133
self ._connection = connection
134
134
self ._current = None
135
135
self ._next = deque ()
@@ -156,7 +156,7 @@ def next(self):
156
156
"""
157
157
if self ._next :
158
158
values = self ._next .popleft ()
159
- self ._current = Record (self .keys , tuple (map (hydrated , values )))
159
+ self ._current = Record (self .keys () , tuple (map (hydrated , values )))
160
160
self ._position += 1
161
161
return True
162
162
elif self ._consumed :
@@ -199,6 +199,14 @@ def __getitem__(self, item):
199
199
raise TypeError ("No current record" )
200
200
return current [item ]
201
201
202
+ def keys (self ):
203
+ """ Return the keys for the records.
204
+ """
205
+ # Fetch messages until we have the header or a failure
206
+ while self ._keys is None and not self ._consumed :
207
+ self ._connection .fetch_next ()
208
+ return self ._keys
209
+
202
210
def get (self , item , default = None ):
203
211
current = self ._current
204
212
if current is None :
@@ -224,7 +232,7 @@ def _consume(self):
224
232
225
233
def _on_header (self , metadata ):
226
234
# Called on receipt of the result header.
227
- self .keys = metadata ["fields" ]
235
+ self ._keys = metadata ["fields" ]
228
236
229
237
def _on_record (self , values ):
230
238
# Called on receipt of each result record.
0 commit comments