File tree Expand file tree Collapse file tree 2 files changed +23
-14
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +23
-14
lines changed
Original file line number Diff line number Diff line change @@ -240,21 +240,10 @@ def string_decoder(s):
240
240
241
241
def autocommit (self , on ):
242
242
on = bool (on )
243
- _mysql .connection .autocommit (self , on )
243
+ if self .get_autocommit () != on :
244
+ _mysql .connection .autocommit (self , on )
244
245
self ._autocommit = on
245
246
246
- def get_autocommit (self ):
247
- if self ._autocommit is None :
248
- self ._update_autocommit ()
249
- return self ._autocommit
250
-
251
- def _update_autocommit (self ):
252
- cursor = cursors .Cursor (self )
253
- cursor .execute ("SELECT @@AUTOCOMMIT" )
254
- row = cursor .fetchone ()
255
- self ._autocommit = bool (row [0 ])
256
- cursor .close ()
257
-
258
247
def cursor (self , cursorclass = None ):
259
248
"""
260
249
Original file line number Diff line number Diff line change @@ -891,7 +891,21 @@ _mysql_ConnectionObject_autocommit(
891
891
if (err ) return _mysql_Exception (self );
892
892
Py_INCREF (Py_None );
893
893
return Py_None ;
894
- }
894
+ }
895
+
896
+ static char _mysql_ConnectionObject_get_autocommit__doc__ [] =
897
+ "Get the autocommit mode. True when enable; False when disable.\n" ;
898
+
899
+ static PyObject *
900
+ _mysql_ConnectionObject_get_autocommit (
901
+ _mysql_ConnectionObject * self ,
902
+ PyObject * args )
903
+ {
904
+ if (self -> connection .server_status & SERVER_STATUS_AUTOCOMMIT ) {
905
+ Py_RETURN_TRUE ;
906
+ }
907
+ Py_RETURN_FALSE ;
908
+ }
895
909
896
910
static char _mysql_ConnectionObject_commit__doc__ [] =
897
911
"Commits the current transaction\n\
@@ -2317,6 +2331,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
2317
2331
METH_VARARGS ,
2318
2332
_mysql_ConnectionObject_autocommit__doc__
2319
2333
},
2334
+ {
2335
+ "get_autocommit" ,
2336
+ (PyCFunction )_mysql_ConnectionObject_get_autocommit ,
2337
+ METH_NOARGS ,
2338
+ _mysql_ConnectionObject_get_autocommit__doc__
2339
+ },
2320
2340
{
2321
2341
"commit" ,
2322
2342
(PyCFunction )_mysql_ConnectionObject_commit ,
You can’t perform that action at this time.
0 commit comments