Browse Source

Re-add SQL to Query exports.

More than just Query objects can raise exceptions in their __debugInfo
method. Debugger should be catching and gracefully handling that
situation.
mark_story 11 years ago
parent
commit
f7597d4327

+ 1 - 0
src/Database/Query.php

@@ -1605,6 +1605,7 @@ class Query implements ExpressionInterface, IteratorAggregate {
  */
 	public function __debugInfo() {
 		return [
+			'sql' => $this->sql(),
 			'params' => $this->valueBinder()->bindings(),
 			'defaultTypes' => $this->defaultTypes(),
 			'decorators' => count($this->_resultDecorators),

+ 7 - 3
src/Utility/Debugger.php

@@ -577,9 +577,13 @@ class Debugger {
 		$end = "\n" . str_repeat("\t", $indent - 1);
 
 		if ($depth > 0 && method_exists($var, '__debugInfo')) {
-			return $out . "\n" .
-				substr(static::_array($var->__debugInfo(), $depth - 1, $indent), 1, -1) .
-				$end . '}';
+			try {
+				return $out . "\n" .
+					substr(static::_array($var->__debugInfo(), $depth - 1, $indent), 1, -1) .
+					$end . '}';
+			} catch (\Exception $e) {
+				return $out . "\n(unable to export object)\n }";
+			}
 		}
 
 		if ($depth > 0) {

+ 6 - 2
tests/TestCase/Database/QueryTest.php

@@ -2658,7 +2658,10 @@ class QueryTest extends TestCase {
 			->where(['id' => '1']);
 
 		$expected = [
-			'params' => [],
+			'sql' => $query->sql(),
+			'params' => [
+				':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
+			],
 			'defaultTypes' => ['id' => 'integer'],
 			'decorators' => 0,
 			'executed' => false
@@ -2668,6 +2671,7 @@ class QueryTest extends TestCase {
 
 		$query->execute();
 		$expected = [
+			'sql' => $query->sql(),
 			'params' => [
 				':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
 			],
@@ -2676,7 +2680,7 @@ class QueryTest extends TestCase {
 			'executed' => true
 		];
 		$result = $query->__debugInfo();
-		$this->assertEquals($result, $expected);
+		$this->assertEquals($expected, $result);
 	}
 
 /**

+ 1 - 0
tests/TestCase/ORM/QueryTest.php

@@ -1835,6 +1835,7 @@ class QueryTest extends TestCase {
 			});
 
 		$expected = [
+			'sql' => $query->sql(),
 			'params' => $query->valueBinder()->bindings(),
 			'defaultTypes' => [
 				'authors.id' => 'integer',