@@ -177,7 +177,24 @@ public function get(): ?array
177177
178178 // Append pessimistic write lock to FROM clause if db platform supports it
179179 $ 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 )) {
181198 $ fromClause = $ matches [1 ];
182199 $ sql = str_replace (
183200 sprintf ('FROM %s WHERE ' , $ fromClause ),
@@ -186,16 +203,13 @@ public function get(): ?array
186203 );
187204 }
188205
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 ();
194209 }
195210
196- // use SELECT ... FOR UPDATE to lock table
197211 $ stmt = $ this ->executeQuery (
198- $ sql. ' ' . $ this -> driverConnection -> getDatabasePlatform ()-> getWriteLockSQL () ,
212+ $ sql ,
199213 $ query ->getParameters (),
200214 $ query ->getParameterTypes ()
201215 );
0 commit comments