Source

bloodhound-mq / t288 / t288_r1440987_dbcursor_debug_sql.diff

Full commit
# HG changeset patch
# Parent 504ca48f1d77fc904f93d70c60f28440fa7f73e7
BH Multiproduct #288 : Log translated SQL queries by default at testing time

diff -r 504ca48f1d77 bloodhound_multiproduct/multiproduct/dbcursor.py
--- a/bloodhound_multiproduct/multiproduct/dbcursor.py	Fri Feb 01 00:02:30 2013 -0500
+++ b/bloodhound_multiproduct/multiproduct/dbcursor.py	Fri Feb 01 00:54:21 2013 -0500
@@ -16,6 +16,7 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
+from trac.db.api import DatabaseManager
 import trac.db.util
 from trac.util import concurrency
 
@@ -55,7 +56,9 @@
     def _translate_sql(self, sql):
         if self._translator is translator_not_set:
             self._translator = None
-            if not self.env is None:
+            if self.env is not None:
+                if DatabaseManager(self.env).debug_sql:
+                    self.log = self.env.log
                 product_prefix = self.env.product.prefix if self.env.product else GLOBAL_PRODUCT
                 self._translator = BloodhoundProductSQLTranslate(SKIP_TABLES,
                                                                  TRANSLATE_TABLES,
diff -r 504ca48f1d77 bloodhound_multiproduct/tests/env.py
--- a/bloodhound_multiproduct/tests/env.py	Fri Feb 01 00:02:30 2013 -0500
+++ b/bloodhound_multiproduct/tests/env.py	Fri Feb 01 00:54:21 2013 -0500
@@ -138,6 +138,10 @@
         config.set('logging', 'log_file', logpath)
         config.set('logging', 'log_type', 'file')
         config.set('logging', 'log_level', 'DEBUG')
+
+        # Log SQL queries
+        config.set('trac', 'debug_sql', True)
+
         config.save()
         env.setup_log()
         env.log.info('%s test case: %s %s',