Skip to content

Commit 0083157

Browse files
committed
Merge pull request #1 from Sp1tF1r3/master
Added cursor config variable
2 parents f12619d + 7ddfd38 commit 0083157

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

flask_mysqldb/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import MySQLdb
2+
import MySQLdb.cursors
23
from flask import _app_ctx_stack, current_app
34

45

@@ -30,6 +31,7 @@ def init_app(self, app):
3031
app.config.setdefault('MYSQL_USE_UNICODE', True)
3132
app.config.setdefault('MYSQL_CHARSET', 'utf8')
3233
app.config.setdefault('MYSQL_SQL_MODE', None)
34+
app.config.setdefault('MYSQL_CURSORCLASS', None)
3335

3436
if hasattr(app, 'teardown_appcontext'):
3537
app.teardown_appcontext(self.teardown)
@@ -73,6 +75,9 @@ def connect(self):
7375
if current_app.config['MYSQL_SQL_MODE']:
7476
kwargs['sql_mode'] = current_app.config['MYSQL_SQL_MODE']
7577

78+
if current_app.config['MYSQL_CURSORCLASS']:
79+
kwargs['cursorclass'] = getattr(MySQLdb.cursors, current_app.config['MYSQL_CURSORCLASS'])
80+
7681
return MySQLdb.connect(**kwargs)
7782

7883
@property

0 commit comments

Comments
 (0)