Skip to content

Commit

Permalink
fix: explain value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Dec 9, 2021
1 parent ac598fa commit 90c16c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
4 changes: 2 additions & 2 deletions resources/views/DatabasePanel/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
</tr>
<?php foreach ($query['explains'] as $row): ?>
<tr>
<?php foreach ($row as $col): ?>
<td><?php echo htmlspecialchars($col, ENT_NOQUOTES, 'UTF-8') ?></td>
<?php foreach ($row as $value): ?>
<td><?php echo htmlspecialchars((string) $value, ENT_NOQUOTES, 'UTF-8') ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
Expand Down
17 changes: 1 addition & 16 deletions src/Panels/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,7 @@ public static function explain(PDO $pdo, $sql, $bindings = [])
if (preg_match('#\s*\(?\s*SELECT\s#iA', $sql)) {
$statement = $pdo->prepare('EXPLAIN '.$sql);
$statement->execute($bindings);
$explains = self::filterExplains($statement->fetchAll(PDO::FETCH_CLASS));
}

return $explains;
}

/**
* @param array $explains
* @return array
*/
private static function filterExplains($explains)
{
if (! empty($explains) && ! empty($explains[0])) {
$explains[0] = array_filter($explains[0], static function ($explain) {
return ! empty($explain);
});
$explains = $statement->fetchAll(PDO::FETCH_CLASS);
}

return $explains;
Expand Down
2 changes: 1 addition & 1 deletion tests/Panels/DatabasePanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testRenderForPHP81()
$sql = 'SELECT * FROM users WHERE foo = ?';
$bindings = ['bar'];

$pdo = $this->givenExplains($sql, $bindings, [['foo' => null]]);
$pdo = $this->givenExplains($sql, $bindings, json_decode('[{"id":1,"select_type":"SIMPLE","table":"users","partitions":null,"type":"ALL","possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":3,"filtered":100,"Extra":null}]'));

$connection = m::spy(Connection::class);
$connection->expects('getPdo')->andReturns($pdo);
Expand Down

0 comments on commit 90c16c7

Please sign in to comment.