1111
1212use Nette ;
1313use Nette \Database \Connection ;
14+ use Nette \Database \DriverException ;
1415use Nette \Database \Helpers ;
1516use Nette \Database \Result ;
1617use Tracy ;
@@ -71,7 +72,7 @@ private function logQuery(Connection $connection, $result): void
7172
7273 $ this ->count ++;
7374
74- $ trace = $ result instanceof \PDOException
75+ $ trace = $ result instanceof DriverException
7576 ? array_map (fn ($ row ) => array_diff_key ($ row , ['args ' => null ]), $ result ->getTrace ())
7677 : debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS );
7778
@@ -87,26 +88,20 @@ private function logQuery(Connection $connection, $result): void
8788 if ($ this ->count < $ this ->maxQueries ) {
8889 $ this ->events [] = [$ connection , $ result ->getQueryString (), $ result ->getParameters (), $ trace , $ result ->getTime (), $ result ->getRowCount (), null ];
8990 }
90- } elseif ($ result instanceof \PDOException && $ this ->count < $ this ->maxQueries ) {
91- $ this ->events [] = [$ connection , $ result ->queryString , null , $ trace , null , null , $ result ->getMessage ()];
91+ } elseif ($ result instanceof DriverException && $ this ->count < $ this ->maxQueries ) {
92+ $ this ->events [] = [$ connection , $ result ->getQueryString () , null , $ trace , null , null , $ result ->getMessage ()];
9293 }
9394 }
9495
9596
9697 public static function renderException (?\Throwable $ e ): ?array
9798 {
98- if (!$ e instanceof \PDOException ) {
99+ if (!$ e instanceof DriverException ) {
99100 return null ;
100101 }
101102
102- if (isset ($ e ->queryString )) {
103- $ sql = $ e ->queryString ;
104-
105- } elseif ($ item = Tracy \Helpers::findTrace ($ e ->getTrace (), 'PDO::prepare ' )) {
106- $ sql = $ item ['args ' ][0 ];
107- }
108-
109- return isset ($ sql ) ? [
103+ $ sql = $ e ->getQueryString ();
104+ return $ sql ? [
110105 'tab ' => 'SQL ' ,
111106 'panel ' => Helpers::dumpSql ($ sql , $ e ->params ?? []),
112107 ] : null ;
@@ -144,7 +139,7 @@ public function getPanel(): ?string
144139 : 'EXPLAIN ' ;
145140 $ rows = $ connection ->getConnection ()->query ("$ cmd $ sql " , $ params );
146141 for ($ explain = []; $ row = $ rows ->fetch (); $ explain [] = $ row );
147- } catch (\ PDOException ) {
142+ } catch (DriverException ) {
148143 }
149144 }
150145
0 commit comments