From f12969a4d8dd8a4f91a9da4cc9d855457a5a0060 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Wed, 2 Apr 2008 11:39:26 +0000 Subject: - Revamped the Connection memoize decorator a bit, moved to engine - MySQL character set caching is more aggressive but will invalidate the cache if a SET is issued. - MySQL connection memos are namespaced: info[('mysql', 'server_variable')] --- test/dialect/mysql.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/dialect') diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py index e1bd47d29..00478908e 100644 --- a/test/dialect/mysql.py +++ b/test/dialect/mysql.py @@ -927,6 +927,49 @@ class SQLTest(TestBase, AssertsCompiledSQL): self.assert_compile(cast(t.c.col, type_), expected) +class ExecutionTest(TestBase): + """Various MySQL execution special cases.""" + + __only_on__ = 'mysql' + + def test_charset_caching(self): + engine = engines.testing_engine() + + cx = engine.connect() + meta = MetaData() + + assert ('mysql', 'charset') not in cx.info + assert ('mysql', 'force_charset') not in cx.info + + cx.execute(text("SELECT 1")).fetchall() + assert ('mysql', 'charset') not in cx.info + + meta.reflect(cx) + assert ('mysql', 'charset') in cx.info + + cx.execute(text("SET @squiznart=123")) + assert ('mysql', 'charset') in cx.info + + # the charset invalidation is very conservative + cx.execute(text("SET TIMESTAMP = DEFAULT")) + assert ('mysql', 'charset') not in cx.info + + cx.info[('mysql', 'force_charset')] = 'latin1' + + assert engine.dialect._detect_charset(cx) == 'latin1' + assert cx.info[('mysql', 'charset')] == 'latin1' + + del cx.info[('mysql', 'force_charset')] + del cx.info[('mysql', 'charset')] + + meta.reflect(cx) + assert ('mysql', 'charset') in cx.info + + # String execution doesn't go through the detector. + cx.execute("SET TIMESTAMP = DEFAULT") + assert ('mysql', 'charset') in cx.info + + def colspec(c): return testing.db.dialect.schemagenerator(testing.db.dialect, testing.db, None, None).get_column_specification(c) -- cgit v1.2.1