@@ -53,8 +53,8 @@ def test_minimal_working_example(self):
5353 session .run ("CREATE (a:Person {name:'Arthur', title:'King'})" , )
5454
5555 result = session .run ("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
56- while result . next () :
57- print ("%s %s" % (result ["title" ], result ["name" ]))
56+ for record in result :
57+ print ("%s %s" % (record ["title" ], record ["name" ]))
5858
5959 session .close ()
6060 # end::minimal-example[]
@@ -96,16 +96,18 @@ def test_statement(self):
9696 driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
9797 session = driver .session ()
9898 # tag::statement[]
99- session .run ("CREATE (person:Person {name: {name}})" , {"name" : "Arthur" }). close ( )
99+ result = session .run ("CREATE (person:Person {name: {name}})" , {"name" : "Arthur" })
100100 # end::statement[]
101+ result .discard ()
101102 session .close ()
102103
103104 def test_statement_without_parameters (self ):
104105 driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
105106 session = driver .session ()
106107 # tag::statement-without-parameters[]
107- session .run ("CREATE (person:Person {name: 'Arthur'})" ). close ( )
108+ result = session .run ("CREATE (person:Person {name: 'Arthur'})" )
108109 # end::statement-without-parameters[]
110+ result .discard ()
109111 session .close ()
110112
111113 def test_result_cursor (self ):
@@ -116,8 +118,8 @@ def test_result_cursor(self):
116118 result = session .run ("MATCH (tool:Tool) WHERE tool.name CONTAINS {term} "
117119 "RETURN tool.name" , {"term" : search_term })
118120 print ("List of tools called %r:" % search_term )
119- while result . next () :
120- print (result ["tool.name" ])
121+ for record in result :
122+ print (record ["tool.name" ])
121123 # end::result-cursor[]
122124 session .close ()
123125
@@ -127,10 +129,10 @@ def test_cursor_nesting(self):
127129 # tag::retain-result-query[]
128130 result = session .run ("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
129131 "RETURN id(knight) AS knight_id" , {"castle" : "Camelot" })
130- while result . next () :
132+ for record in result :
131133 session .run ("MATCH (knight) WHERE id(knight) = {id} "
132134 "MATCH (king:Person) WHERE king.name = {king} "
133- "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : result ["knight_id" ], "king" : "Arthur" })
135+ "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : record ["knight_id" ], "king" : "Arthur" })
134136 # end::retain-result-query[]
135137 session .close ()
136138
@@ -140,9 +142,8 @@ def test_result_retention(self):
140142 # tag::retain-result-process[]
141143 result = session .run ("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} "
142144 "RETURN id(knight) AS knight_id" , {"castle" : "Camelot" })
143- id_records = list (result .stream ())
144-
145- for record in id_records :
145+ retained_result = list (result )
146+ for record in retained_result :
146147 session .run ("MATCH (knight) WHERE id(knight) = {id} "
147148 "MATCH (king:Person) WHERE king.name = {king} "
148149 "CREATE (knight)-[:DEFENDS]->(king)" , {"id" : record ["knight_id" ], "king" : "Arthur" })
@@ -158,9 +159,8 @@ def test_transaction_commit(self):
158159 tx .commit ()
159160 # end::transaction-commit[]
160161 result = session .run ("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)" )
161- assert result .next ()
162- assert result ["count(p)" ] == 1
163- assert result .at_end
162+ record = next (result )
163+ assert record ["count(p)" ] == 1
164164 session .close ()
165165
166166 def test_transaction_rollback (self ):
@@ -172,9 +172,8 @@ def test_transaction_rollback(self):
172172 tx .rollback ()
173173 # end::transaction-rollback[]
174174 result = session .run ("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)" )
175- assert result .next ()
176- assert result ["count(p)" ] == 0
177- assert result .at_end
175+ record = next (result )
176+ assert record ["count(p)" ] == 0
178177 session .close ()
179178
180179 def test_result_summary_query_profile (self ):
@@ -183,8 +182,7 @@ def test_result_summary_query_profile(self):
183182 # tag::result-summary-query-profile[]
184183 result = session .run ("PROFILE MATCH (p:Person {name: {name}}) "
185184 "RETURN id(p)" , {"name" : "Arthur" })
186- while result .next ():
187- pass # skip the records to get to the summary
185+ list (result ) # skip the records to get to the summary
188186 print (result .summary .statement_type )
189187 print (result .summary .profile )
190188 # end::result-summary-query-profile[]
@@ -195,8 +193,7 @@ def test_result_summary_notifications(self):
195193 session = driver .session ()
196194 # tag::result-summary-notifications[]
197195 result = session .run ("EXPLAIN MATCH (king), (queen) RETURN king, queen" )
198- while result .next ():
199- pass # skip the records to get to the summary
196+ list (result ) # skip the records to get to the summary
200197 for notification in result .summary .notifications :
201198 print (notification )
202199 # end::result-summary-notifications[]
0 commit comments