diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2017-06-16 18:40:13 -0400 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@awstats.zzzcomputing.com> | 2017-06-16 18:40:13 -0400 |
| commit | 139cbe4f72e587228965bbb338387842fb1cf47b (patch) | |
| tree | 5954e5be21a8fc2ef8d35ff770732ce79c19e3f2 /lib/sqlalchemy | |
| parent | 6d8d89042b32078a846c67a4d33d93b0cd0e645d (diff) | |
| parent | 5650a0c306391216a9c9ce1961c5b548e534b5eb (diff) | |
| download | sqlalchemy-139cbe4f72e587228965bbb338387842fb1cf47b.tar.gz | |
Merge "Handle SHOW VARIABLES returning no row"
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 277ae5815..c19253478 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1673,13 +1673,21 @@ class MySQLDialect(default.DefaultDialect): """Proxy a result row to smooth over MySQL-Python driver inconsistencies.""" - return _DecodingRowProxy(rp.fetchone(), charset) + row = rp.fetchone() + if row: + return _DecodingRowProxy(row, charset) + else: + return None def _compat_first(self, rp, charset=None): """Proxy a result row to smooth over MySQL-Python driver inconsistencies.""" - return _DecodingRowProxy(rp.first(), charset) + row = rp.first() + if row: + return _DecodingRowProxy(row, charset) + else: + return None def _extract_error_code(self, exception): raise NotImplementedError() @@ -1720,6 +1728,7 @@ class MySQLDialect(default.DefaultDialect): def initialize(self, connection): self._connection_charset = self._detect_charset(connection) + self._detect_sql_mode(connection) self._detect_ansiquotes(connection) if self._server_ansiquotes: # if ansiquotes == True, build a new IdentifierPreparer @@ -1993,21 +2002,28 @@ class MySQLDialect(default.DefaultDialect): collations[row[0]] = row[1] return collations - def _detect_ansiquotes(self, connection): - """Detect and adjust for the ANSI_QUOTES sql mode.""" - + def _detect_sql_mode(self, connection): row = self._compat_first( connection.execute("SHOW VARIABLES LIKE 'sql_mode'"), charset=self._connection_charset) if not row: - mode = '' + util.warn( + "Could not retrieve SQL_MODE; please ensure the " + "MySQL user has permissions to SHOW VARIABLES") + self._sql_mode = '' else: - mode = row[1] or '' - # 4.0 - if mode.isdigit(): - mode_no = int(mode) - mode = (mode_no | 4 == mode_no) and 'ANSI_QUOTES' or '' + self._sql_mode = row[1] or '' + + def _detect_ansiquotes(self, connection): + """Detect and adjust for the ANSI_QUOTES sql mode.""" + + mode = self._sql_mode + if not mode: + mode = '' + elif mode.isdigit(): + mode_no = int(mode) + mode = (mode_no | 4 == mode_no) and 'ANSI_QUOTES' or '' self._server_ansiquotes = 'ANSI_QUOTES' in mode |
