@@ -63,11 +63,13 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
63
63
* @return $this
64
64
*/
65
65
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
+ });
71
73
});
72
74
return $ this ;
73
75
}
@@ -79,11 +81,13 @@ public function execute(array $params = []) {
79
81
* @return array<mixed, mixed>
80
82
*/
81
83
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
+ });
87
91
});
88
92
if (is_bool ($ result )) {
89
93
return [];
@@ -98,8 +102,10 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
98
102
* @return mixed
99
103
*/
100
104
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
+ });
103
109
});
104
110
}
105
111
@@ -108,16 +114,18 @@ public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::
108
114
* @return mixed
109
115
*/
110
116
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
+ });
113
121
});
114
122
}
115
123
116
124
/**
117
125
* @return bool
118
126
*/
119
127
public function closeCursor (): bool {
120
- return $ this ->exceptionHandler ($ this -> query , function () {
128
+ return $ this ->exceptionHandler (function () {
121
129
return $ this ->statement ->closeCursor ();
122
130
});
123
131
}
@@ -126,7 +134,7 @@ public function closeCursor(): bool {
126
134
* @return int
127
135
*/
128
136
public function columnCount (): int {
129
- return $ this ->exceptionHandler ($ this -> query , function () {
137
+ return $ this ->exceptionHandler (function () {
130
138
return $ this ->statement ->columnCount ();
131
139
});
132
140
}
@@ -136,7 +144,7 @@ public function columnCount(): int {
136
144
* @return null|array<string, mixed>
137
145
*/
138
146
public function getColumnMeta (int $ columnNo ): ?array {
139
- return $ this ->exceptionHandler ($ this -> query , function () use ($ columnNo ) {
147
+ return $ this ->exceptionHandler (function () use ($ columnNo ) {
140
148
$ columnMeta = $ this ->statement ->getColumnMeta ($ columnNo );
141
149
if ($ columnMeta === false ) {
142
150
return null ;
@@ -150,13 +158,11 @@ public function getColumnMeta(int $columnNo): ?array {
150
158
* @param callable(): T $fn
151
159
* @return T
152
160
*/
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
+ }
161
167
}
162
168
}
0 commit comments