File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -508,6 +508,7 @@ def _config(key, default):
508
508
self .encoders = encoders
509
509
self .decoders = conv
510
510
511
+ self ._result = None
511
512
self ._affected_rows = 0
512
513
self .host_info = "Not connected"
513
514
@@ -685,6 +686,12 @@ def _read_query_result(self):
685
686
self ._result = result
686
687
return result .affected_rows
687
688
689
+ def insert_id (self ):
690
+ if self ._result :
691
+ return self ._result .insert_id
692
+ else :
693
+ return 0
694
+
688
695
def _send_command (self , command , sql ):
689
696
#send_data = struct.pack('<i', len(sql) + 1) + command + sql
690
697
# could probably be more efficient, at least it's correct
Original file line number Diff line number Diff line change @@ -240,7 +240,6 @@ def _do_get_result(self):
240
240
self .lastrowid = conn ._result .insert_id
241
241
self ._rows = conn ._result .rows
242
242
self ._has_next = conn ._result .has_next
243
- conn ._result = None
244
243
245
244
def __iter__ (self ):
246
245
return iter (self .fetchone , None )
Original file line number Diff line number Diff line change @@ -249,7 +249,17 @@ def disabled_test_issue_54(self):
249
249
c .execute ("drop table issue54" )
250
250
251
251
class TestGitHubIssues (base .PyMySQLTestCase ):
252
- pass
252
+ def test_issue_66 (self ):
253
+ conn = self .connections [0 ]
254
+ c = conn .cursor ()
255
+ self .assertEquals (0 , conn .insert_id ())
256
+ try :
257
+ c .execute ("create table issue66 (id integer primary key auto_increment, x integer)" )
258
+ c .execute ("insert into issue66 (x) values (1)" )
259
+ c .execute ("insert into issue66 (x) values (1)" )
260
+ self .assertEquals (2 , conn .insert_id ())
261
+ finally :
262
+ c .execute ("drop table issue66" )
253
263
254
264
__all__ = ["TestOldIssues" , "TestNewIssues" , "TestGitHubIssues" ]
255
265
You can’t perform that action at this time.
0 commit comments