1111
1212use Nette ;
1313use Nette \Database \Connection ;
14+ use Nette \Database \DriverException ;
1415use Nette \Database \Helpers ;
1516use Nette \Database \Result ;
1617use Tracy ;
@@ -72,7 +73,7 @@ private function logQuery(Connection $connection, $result): void
7273
7374 $ this ->count ++;
7475
75- $ trace = $ result instanceof \PDOException
76+ $ trace = $ result instanceof DriverException
7677 ? array_map (fn ($ row ) => array_diff_key ($ row , ['args ' => null ]), $ result ->getTrace ())
7778 : debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS );
7879
@@ -88,26 +89,20 @@ private function logQuery(Connection $connection, $result): void
8889 if ($ this ->count < $ this ->maxQueries ) {
8990 $ this ->events [] = [$ connection , $ result ->getQueryString (), $ result ->getParameters (), $ trace , $ result ->getTime (), $ result ->getRowCount (), null ];
9091 }
91- } elseif ($ result instanceof \PDOException && $ this ->count < $ this ->maxQueries ) {
92- $ this ->events [] = [$ connection , $ result ->queryString , null , $ trace , null , null , $ result ->getMessage ()];
92+ } elseif ($ result instanceof DriverException && $ this ->count < $ this ->maxQueries ) {
93+ $ this ->events [] = [$ connection , $ result ->getQueryString () , null , $ trace , null , null , $ result ->getMessage ()];
9394 }
9495 }
9596
9697
9798 public static function renderException (?\Throwable $ e ): ?array
9899 {
99- if (!$ e instanceof \PDOException ) {
100+ if (!$ e instanceof DriverException ) {
100101 return null ;
101102 }
102103
103- if (isset ($ e ->queryString )) {
104- $ sql = $ e ->queryString ;
105-
106- } elseif ($ item = Tracy \Helpers::findTrace ($ e ->getTrace (), 'PDO::prepare ' )) {
107- $ sql = $ item ['args ' ][0 ];
108- }
109-
110- return isset ($ sql ) ? [
104+ $ sql = $ e ->getQueryString ();
105+ return $ sql ? [
111106 'tab ' => 'SQL ' ,
112107 'panel ' => Helpers::dumpSql ($ sql , $ e ->params ?? []),
113108 ] : null ;
@@ -145,7 +140,7 @@ public function getPanel(): ?string
145140 : 'EXPLAIN ' ;
146141 $ rows = $ connection ->getConnection ()->query ("$ cmd $ sql " , $ params );
147142 for ($ explain = []; $ row = $ rows ->fetch (); $ explain [] = $ row );
148- } catch (\ PDOException ) {
143+ } catch (DriverException ) {
149144 }
150145 }
151146
0 commit comments