@@ -63,10 +63,8 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
6363 * @return $this
6464 */
6565 public function execute (array $ params = []) {
66- $ this ->exceptionHandler (function () use ($ params ) {
67- $ timer = microtime (true );
66+ $ this ->exceptionHandler ($ this ->query , function () use ($ params ) {
6867 $ response = $ this ->statement ->execute ($ params );
69- $ this ->queryLoggers ->log ($ this ->query , microtime (true )-$ timer );
7068 if (!$ response ) {
7169 throw new SqlException ('Execution returned with "false". ' );
7270 }
@@ -81,7 +79,7 @@ public function execute(array $params = []) {
8179 * @return array<mixed, mixed>
8280 */
8381 public function fetchAll ($ fetchStyle = PDO ::FETCH_ASSOC , $ fetchArgument = null , array $ ctorArgs = []): array {
84- return $ this ->exceptionHandler (function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
82+ return $ this ->exceptionHandler ($ this -> query , function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
8583 if ($ fetchArgument !== null ) {
8684 return $ this ->statement ->fetchAll ($ fetchStyle , $ fetchArgument , ...$ ctorArgs );
8785 }
@@ -96,7 +94,7 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
9694 * @return mixed
9795 */
9896 public function fetch ($ fetchStyle = PDO ::FETCH_ASSOC , $ cursorOrientation = PDO ::FETCH_ORI_NEXT , $ cursorOffset = 0 ) {
99- return $ this ->exceptionHandler (function () use ($ fetchStyle , $ cursorOrientation , $ cursorOffset ) {
97+ return $ this ->exceptionHandler ($ this -> query , function () use ($ fetchStyle , $ cursorOrientation , $ cursorOffset ) {
10098 return $ this ->statement ->fetch ($ fetchStyle , $ cursorOrientation , $ cursorOffset );
10199 });
102100 }
@@ -106,7 +104,7 @@ public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::
106104 * @return mixed
107105 */
108106 public function fetchColumn ($ columnNo = 0 ) {
109- return $ this ->exceptionHandler (function () use ($ columnNo ) {
107+ return $ this ->exceptionHandler ($ this -> query , function () use ($ columnNo ) {
110108 return $ this ->statement ->fetchColumn ($ columnNo );
111109 });
112110 }
@@ -115,7 +113,7 @@ public function fetchColumn($columnNo = 0) {
115113 * @return bool
116114 */
117115 public function closeCursor (): bool {
118- return $ this ->exceptionHandler (function () {
116+ return $ this ->exceptionHandler ($ this -> query , function () {
119117 return $ this ->statement ->closeCursor ();
120118 });
121119 }
@@ -124,7 +122,7 @@ public function closeCursor(): bool {
124122 * @return int
125123 */
126124 public function columnCount (): int {
127- return $ this ->exceptionHandler (function () {
125+ return $ this ->exceptionHandler ($ this -> query , function () {
128126 return $ this ->statement ->columnCount ();
129127 });
130128 }
@@ -134,7 +132,7 @@ public function columnCount(): int {
134132 * @return null|array<string, mixed>
135133 */
136134 public function getColumnMeta (int $ columnNo ): ?array {
137- return $ this ->exceptionHandler (function () use ($ columnNo ) {
135+ return $ this ->exceptionHandler ($ this -> query , function () use ($ columnNo ) {
138136 $ columnMeta = $ this ->statement ->getColumnMeta ($ columnNo );
139137 if ($ columnMeta === false ) {
140138 return null ;
@@ -144,15 +142,17 @@ public function getColumnMeta(int $columnNo): ?array {
144142 }
145143
146144 /**
147- * @param callable $fn
148- * @return mixed
145+ * @template T
146+ * @param callable(): T $fn
147+ * @return T
149148 */
150- private function exceptionHandler (callable $ fn ) {
151- try {
152- return $ fn ();
153- } catch (PDOException $ e ) {
154- $ this ->exceptionInterpreter ->throwMoreConcreteException ($ e );
155- }
156- return null ;
149+ private function exceptionHandler (string $ query , callable $ fn ) {
150+ return $ this ->queryLoggers ->logRegion ($ query , function () use ($ fn ) {
151+ try {
152+ return $ fn ();
153+ } catch (PDOException $ exception ) {
154+ return $ this ->exceptionInterpreter ->getMoreConcreteException ($ exception );
155+ }
156+ });
157157 }
158158}
0 commit comments