diff --git a/docs/index.rst b/docs/index.rst index 7ccb785..f430e6e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -67,6 +67,7 @@ directives: if they are not equal. Default: 'utf-8' ``MYSQL_SQL_MODE`` If present, the session SQL mode will be set to the given string. ``MYSQL_CURSORCLASS`` If present, the cursor class will be set to the given string. +``MYSQL_AUTOCOMMIT`` If enabled, will use the autocommit feature of MySQL. Default: False ============================ =================================================== @@ -85,6 +86,9 @@ History Changes: +- 0.2.1: September 4, 2020 + - Added option for autocommit. + - 0.2.0: September 5, 2015 - Added option to change the cursor. Thanks to `@Sp1tF1r3 `_ on GitHub. diff --git a/flask_mysqldb/__init__.py b/flask_mysqldb/__init__.py index 7811761..9c3d157 100644 --- a/flask_mysqldb/__init__.py +++ b/flask_mysqldb/__init__.py @@ -32,6 +32,7 @@ def init_app(self, app): app.config.setdefault('MYSQL_CHARSET', 'utf8') app.config.setdefault('MYSQL_SQL_MODE', None) app.config.setdefault('MYSQL_CURSORCLASS', None) + app.config.setdefault('MYSQL_AUTOCOMMIT', False) if hasattr(app, 'teardown_appcontext'): app.teardown_appcontext(self.teardown) @@ -76,7 +77,11 @@ def connect(self): kwargs['sql_mode'] = current_app.config['MYSQL_SQL_MODE'] if current_app.config['MYSQL_CURSORCLASS']: - kwargs['cursorclass'] = getattr(cursors, current_app.config['MYSQL_CURSORCLASS']) + kwargs['cursorclass'] = \ + getattr(cursors, current_app.config['MYSQL_CURSORCLASS']) + + if current_app.config['MYSQL_AUTOCOMMIT']: + kwargs['autocommit'] = current_app.config['MYSQL_AUTOCOMMIT'] return MySQLdb.connect(**kwargs)