@@ -79,6 +79,9 @@ class Connection extends \Doctrine\DBAL\Connection {
7979 /** @var DbDataCollector|null */
8080 protected $ dbDataCollector = null ;
8181
82+ protected bool $ logDbException = false ;
83+ private ?array $ transactionBacktrace = null ;
84+
8285 protected bool $ logRequestId ;
8386 protected string $ requestId ;
8487
@@ -110,6 +113,7 @@ public function __construct(
110113 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
111114
112115 $ this ->logRequestId = $ this ->systemConfig ->getValue ('db.log_request_id ' , false );
116+ $ this ->logDbException = $ this ->systemConfig ->getValue ('db.log_exceptions ' , false );
113117 $ this ->requestId = Server::get (IRequestId::class)->getId ();
114118
115119 /** @var \OCP\Profiler\IProfiler */
@@ -263,7 +267,12 @@ public function executeQuery(string $sql, array $params = [], $types = [], Query
263267 $ sql = $ this ->finishQuery ($ sql );
264268 $ this ->queriesExecuted ++;
265269 $ this ->logQueryToFile ($ sql );
266- return parent ::executeQuery ($ sql , $ params , $ types , $ qcp );
270+ try {
271+ return parent ::executeQuery ($ sql , $ params , $ types , $ qcp );
272+ } catch (\Exception $ e ) {
273+ $ this ->logDatabaseException ($ e );
274+ throw $ e ;
275+ }
267276 }
268277
269278 /**
@@ -294,7 +303,12 @@ public function executeStatement($sql, array $params = [], array $types = []): i
294303 $ sql = $ this ->finishQuery ($ sql );
295304 $ this ->queriesExecuted ++;
296305 $ this ->logQueryToFile ($ sql );
297- return (int )parent ::executeStatement ($ sql , $ params , $ types );
306+ try {
307+ return (int )parent ::executeStatement ($ sql , $ params , $ types );
308+ } catch (\Exception $ e ) {
309+ $ this ->logDatabaseException ($ e );
310+ throw $ e ;
311+ }
298312 }
299313
300314 protected function logQueryToFile (string $ sql ): void {
@@ -360,7 +374,12 @@ public function insertIfNotExist($table, $input, array $compare = null) {
360374 }
361375
362376 public function insertIgnoreConflict (string $ table , array $ values ) : int {
363- return $ this ->adapter ->insertIgnoreConflict ($ table , $ values );
377+ try {
378+ return $ this ->adapter ->insertIgnoreConflict ($ table , $ values );
379+ } catch (\Exception $ e ) {
380+ $ this ->logDatabaseException ($ e );
381+ throw $ e ;
382+ }
364383 }
365384
366385 private function getType ($ value ) {
0 commit comments