diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2017-06-16 18:39:59 -0400 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@awstats.zzzcomputing.com> | 2017-06-16 18:39:59 -0400 |
| commit | 0b9aa75c0094a02110ab09376b5ac32a63c657ea (patch) | |
| tree | d1519c4f3d3c017c1c15d1ea8e0468b329f26400 /lib/sqlalchemy | |
| parent | 7a47c32bb098257402f94a3d01aee1493ddbd823 (diff) | |
| parent | 94a0ed697a120629715ab1fd73d708ec75775e3d (diff) | |
| download | sqlalchemy-0b9aa75c0094a02110ab09376b5ac32a63c657ea.tar.gz | |
Merge "Handle SHOW VARIABLES returning no row" into rel_1_1
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 93f35ef2f..7ddd0e1b3 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1648,13 +1648,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() @@ -1695,6 +1703,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 @@ -1962,21 +1971,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 |
