Browse Source

Add getter mode for logQueries.

This is useful if you want to know whether or not a connection is
currently logging queries.
mark_story 11 years ago
parent
commit
2dc13efa6d
2 changed files with 20 additions and 3 deletions
  1. 7 3
      src/Database/Connection.php
  2. 13 0
      tests/TestCase/Database/ConnectionTest.php

+ 7 - 3
src/Database/Connection.php

@@ -542,10 +542,14 @@ class Connection {
 /**
  * Enables or disables query logging for this connection.
  *
- * @param bool $enable whether to turn logging on or disable it
- * @return void
+ * @param bool $enable whether to turn logging on or disable it.
+ *   Use null to read current value.
+ * @return bool
  */
-	public function logQueries($enable) {
+	public function logQueries($enable = null) {
+		if ($enable === null) {
+			return $this->_logQueries;
+		}
 		$this->_logQueries = $enable;
 	}
 

+ 13 - 0
tests/TestCase/Database/ConnectionTest.php

@@ -655,6 +655,19 @@ class ConnectionTest extends TestCase {
 	}
 
 /**
+ * test logQueries method
+ *
+ * @return void
+ */
+	public function testLogQueries() {
+		$this->connection->logQueries(true);
+		$this->assertTrue($this->connection->logQueries());
+
+		$this->connection->logQueries(false);
+		$this->assertFalse($this->connection->logQueries());
+	}
+
+/**
  * Tests that log() function logs to the configured query logger
  *
  * @return void