Skip to content

Commit ba3ee5c

Browse files
committed
Fixes to remove remaining cursor references
1 parent 5a5b80a commit ba3ee5c

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

examples/test_examples.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,44 +110,43 @@ def test_statement_without_parameters(self):
110110
result.discard()
111111
session.close()
112112

113-
def test_result_cursor(self):
113+
def test_result_traversal(self):
114114
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
115115
session = driver.session()
116-
# tag::result-cursor[]
117-
search_term = "hammer"
118-
result = session.run("MATCH (tool:Tool) WHERE tool.name CONTAINS {term} "
119-
"RETURN tool.name", {"term": search_term})
120-
print("List of tools called %r:" % search_term)
116+
# tag::result-traversal[]
117+
search_term = "sword"
118+
result = session.run("MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} "
119+
"RETURN weapon.name", {"term": search_term})
120+
print("List of weapons called %r:" % search_term)
121121
for record in result:
122-
print(record["tool.name"])
123-
# end::result-cursor[]
122+
print(record["weapon.name"])
123+
# end::result-traversal[]
124124
session.close()
125125

126-
def test_cursor_nesting(self):
126+
def test_result_retention(self):
127127
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
128+
# tag::retain-result[]
128129
session = driver.session()
129-
# tag::retain-result-query[]
130130
result = session.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
131-
"RETURN id(knight) AS knight_id", {"castle": "Camelot"})
132-
for record in result:
133-
session.run("MATCH (knight) WHERE id(knight) = {id} "
134-
"MATCH (king:Person) WHERE king.name = {king} "
135-
"CREATE (knight)-[:DEFENDS]->(king)", {"id": record["knight_id"], "king": "Arthur"})
136-
# end::retain-result-query[]
131+
"RETURN knight.name AS name", {"castle": "Camelot"})
132+
retained_result = list(result)
137133
session.close()
134+
for record in retained_result:
135+
print("%s is a knight of Camelot" % record["name"])
136+
# end::retain-result[]
137+
assert isinstance(retained_result, list)
138138

139-
def test_result_retention(self):
139+
def test_nested_statements(self):
140140
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
141141
session = driver.session()
142-
# tag::retain-result-process[]
142+
# tag::nested-statements[]
143143
result = session.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
144144
"RETURN id(knight) AS knight_id", {"castle": "Camelot"})
145-
retained_result = list(result)
146-
for record in retained_result:
145+
for record in result:
147146
session.run("MATCH (knight) WHERE id(knight) = {id} "
148147
"MATCH (king:Person) WHERE king.name = {king} "
149148
"CREATE (knight)-[:DEFENDS]->(king)", {"id": record["knight_id"], "king": "Arthur"})
150-
# end::retain-result-process[]
149+
# end::nested-statements[]
151150
session.close()
152151

153152
def test_transaction_commit(self):

neo4j/v1/session.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class StatementResult(object):
165165
def __init__(self, connection, run_response, pull_all_response):
166166
super(StatementResult, self).__init__()
167167

168-
# The Connection instance behind this cursor.
168+
# The Connection instance behind this result.
169169
self.connection = connection
170170

171171
# The keys for the records in the result stream. These are
@@ -229,7 +229,7 @@ def keys(self):
229229

230230
def discard(self):
231231
""" Consume the remainder of this result and detach the connection
232-
from this cursor.
232+
from this result.
233233
"""
234234
if self.connection and not self.connection.closed:
235235
fetch = self.connection.fetch
@@ -456,16 +456,16 @@ def run(self, statement, parameters=None):
456456

457457
run_response = Response(self.connection)
458458
pull_all_response = Response(self.connection)
459-
cursor = StatementResult(self.connection, run_response, pull_all_response)
460-
cursor.statement = statement
461-
cursor.parameters = parameters
459+
result = StatementResult(self.connection, run_response, pull_all_response)
460+
result.statement = statement
461+
result.parameters = parameters
462462

463463
self.connection.append(RUN, (statement, parameters), response=run_response)
464464
self.connection.append(PULL_ALL, response=pull_all_response)
465465
self.connection.send()
466466

467-
self.last_result = cursor
468-
return cursor
467+
self.last_result = result
468+
return result
469469

470470
def close(self):
471471
""" Recycle this session through the driver it came from.

0 commit comments

Comments
 (0)