@@ -177,7 +177,24 @@ public function get(): ?array
177
177
178
178
// Append pessimistic write lock to FROM clause if db platform supports it
179
179
$ sql = $ query ->getSQL ();
180
- if (preg_match ('/FROM (.+) WHERE/ ' , (string ) $ sql , $ matches )) {
180
+
181
+ // Wrap the rownum query in a sub-query to allow writelocks without ORA-02014 error
182
+ if ($ this ->driverConnection ->getDatabasePlatform () instanceof OraclePlatform) {
183
+ $ query = $ this ->createQueryBuilder ('w ' )
184
+ ->where ('w.id IN ( ' .str_replace ('SELECT a.* FROM ' , 'SELECT a.id FROM ' , $ sql ).') ' );
185
+
186
+ if (method_exists (QueryBuilder::class, 'forUpdate ' )) {
187
+ $ query ->forUpdate ();
188
+ }
189
+
190
+ $ sql = $ query ->getSQL ();
191
+ } elseif (method_exists (QueryBuilder::class, 'forUpdate ' )) {
192
+ $ query ->forUpdate ();
193
+ try {
194
+ $ sql = $ query ->getSQL ();
195
+ } catch (DBALException $ e ) {
196
+ }
197
+ } elseif (preg_match ('/FROM (.+) WHERE/ ' , (string ) $ sql , $ matches )) {
181
198
$ fromClause = $ matches [1 ];
182
199
$ sql = str_replace (
183
200
sprintf ('FROM %s WHERE ' , $ fromClause ),
@@ -186,16 +203,13 @@ public function get(): ?array
186
203
);
187
204
}
188
205
189
- // Wrap the rownum query in a sub-query to allow writelocks without ORA-02014 error
190
- if ($ this ->driverConnection ->getDatabasePlatform () instanceof OraclePlatform) {
191
- $ sql = $ this ->createQueryBuilder ('w ' )
192
- ->where ('w.id IN ( ' .str_replace ('SELECT a.* FROM ' , 'SELECT a.id FROM ' , $ sql ).') ' )
193
- ->getSQL ();
206
+ // use SELECT ... FOR UPDATE to lock table
207
+ if (!method_exists (QueryBuilder::class, 'forUpdate ' )) {
208
+ $ sql .= ' ' .$ this ->driverConnection ->getDatabasePlatform ()->getWriteLockSQL ();
194
209
}
195
210
196
- // use SELECT ... FOR UPDATE to lock table
197
211
$ stmt = $ this ->executeQuery (
198
- $ sql. ' ' . $ this -> driverConnection -> getDatabasePlatform ()-> getWriteLockSQL () ,
212
+ $ sql ,
199
213
$ query ->getParameters (),
200
214
$ query ->getParameterTypes ()
201
215
);
0 commit comments