@@ -63,11 +63,13 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
6363 * @return $this
6464 */
6565 public function execute (array $ params = []) {
66- $ this ->exceptionHandler ($ this ->query , function () use ($ params ) {
67- $ response = $ this ->statement ->execute ($ params );
68- if (!$ response ) {
69- throw new SqlException ('Execution returned with "false". ' );
70- }
66+ $ this ->exceptionHandler (function () use ($ params ) {
67+ $ this ->queryLoggers ->logRegion ($ this ->query , function () use ($ params ) {
68+ $ response = $ this ->statement ->execute ($ params );
69+ if (!$ response ) {
70+ throw new SqlException ('Execution returned with "false". ' );
71+ }
72+ });
7173 });
7274 return $ this ;
7375 }
@@ -79,11 +81,13 @@ public function execute(array $params = []) {
7981 * @return array<mixed, mixed>
8082 */
8183 public function fetchAll ($ fetchStyle = PDO ::FETCH_ASSOC , $ fetchArgument = null , array $ ctorArgs = []): array {
82- $ result = $ this ->exceptionHandler ($ this ->query , function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
83- if ($ fetchArgument !== null ) {
84- return $ this ->statement ->fetchAll ($ fetchStyle , $ fetchArgument , ...$ ctorArgs );
85- }
86- return $ this ->statement ->fetchAll ($ fetchStyle );
84+ $ result = $ this ->exceptionHandler (function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
85+ return $ this ->queryLoggers ->logRegion ($ this ->query , function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
86+ if ($ fetchArgument !== null ) {
87+ return $ this ->statement ->fetchAll ($ fetchStyle , $ fetchArgument , ...$ ctorArgs );
88+ }
89+ return $ this ->statement ->fetchAll ($ fetchStyle );
90+ });
8791 });
8892 if (is_bool ($ result )) {
8993 return [];
@@ -98,8 +102,10 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
98102 * @return mixed
99103 */
100104 public function fetch ($ fetchStyle = PDO ::FETCH_ASSOC , $ cursorOrientation = PDO ::FETCH_ORI_NEXT , $ cursorOffset = 0 ) {
101- return $ this ->exceptionHandler ($ this ->query , function () use ($ fetchStyle , $ cursorOrientation , $ cursorOffset ) {
102- return $ this ->statement ->fetch ($ fetchStyle , $ cursorOrientation , $ cursorOffset );
105+ return $ this ->exceptionHandler (function () use ($ fetchStyle , $ cursorOrientation , $ cursorOffset ) {
106+ return $ this ->queryLoggers ->logRegion ($ this ->query , function () use ($ fetchStyle , $ cursorOrientation , $ cursorOffset ) {
107+ return $ this ->statement ->fetch ($ fetchStyle , $ cursorOrientation , $ cursorOffset );
108+ });
103109 });
104110 }
105111
@@ -108,16 +114,18 @@ public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::
108114 * @return mixed
109115 */
110116 public function fetchColumn ($ columnNo = 0 ) {
111- return $ this ->exceptionHandler ($ this ->query , function () use ($ columnNo ) {
112- return $ this ->statement ->fetchColumn ($ columnNo );
117+ return $ this ->exceptionHandler (function () use ($ columnNo ) {
118+ return $ this ->queryLoggers ->logRegion ($ this ->query , function () use ($ columnNo ) {
119+ return $ this ->statement ->fetchColumn ($ columnNo );
120+ });
113121 });
114122 }
115123
116124 /**
117125 * @return bool
118126 */
119127 public function closeCursor (): bool {
120- return $ this ->exceptionHandler ($ this -> query , function () {
128+ return $ this ->exceptionHandler (function () {
121129 return $ this ->statement ->closeCursor ();
122130 });
123131 }
@@ -126,7 +134,7 @@ public function closeCursor(): bool {
126134 * @return int
127135 */
128136 public function columnCount (): int {
129- return $ this ->exceptionHandler ($ this -> query , function () {
137+ return $ this ->exceptionHandler (function () {
130138 return $ this ->statement ->columnCount ();
131139 });
132140 }
@@ -136,7 +144,7 @@ public function columnCount(): int {
136144 * @return null|array<string, mixed>
137145 */
138146 public function getColumnMeta (int $ columnNo ): ?array {
139- return $ this ->exceptionHandler ($ this -> query , function () use ($ columnNo ) {
147+ return $ this ->exceptionHandler (function () use ($ columnNo ) {
140148 $ columnMeta = $ this ->statement ->getColumnMeta ($ columnNo );
141149 if ($ columnMeta === false ) {
142150 return null ;
@@ -150,13 +158,11 @@ public function getColumnMeta(int $columnNo): ?array {
150158 * @param callable(): T $fn
151159 * @return T
152160 */
153- private function exceptionHandler (string $ query , callable $ fn ) {
154- return $ this ->queryLoggers ->logRegion ($ query , function () use ($ fn ) {
155- try {
156- return $ fn ();
157- } catch (PDOException $ exception ) {
158- throw $ this ->exceptionInterpreter ->getMoreConcreteException ($ exception );
159- }
160- });
161+ private function exceptionHandler (callable $ fn ) {
162+ try {
163+ return $ fn ();
164+ } catch (PDOException $ exception ) {
165+ throw $ this ->exceptionInterpreter ->getMoreConcreteException ($ exception );
166+ }
161167 }
162168}
0 commit comments