@@ -79,6 +79,9 @@ class Connection extends \Doctrine\DBAL\Connection {
7979 /** @var DbDataCollector|null */
8080 protected $ dbDataCollector = null ;
8181
82+ protected bool $ logRequestId ;
83+ protected string $ requestId ;
84+
8285 /**
8386 * Initializes a new instance of the Connection class.
8487 *
@@ -106,6 +109,9 @@ public function __construct(
106109 $ this ->systemConfig = \OC ::$ server ->getSystemConfig ();
107110 $ this ->logger = \OC ::$ server ->get (LoggerInterface::class);
108111
112+ $ this ->logRequestId = $ this ->systemConfig ->getValue ('db.log_request_id ' , false );
113+ $ this ->requestId = Server::get (IRequestId::class)->getId ();
114+
109115 /** @var \OCP\Profiler\IProfiler */
110116 $ profiler = \OC ::$ server ->get (IProfiler::class);
111117 if ($ profiler ->isEnabled ()) {
@@ -266,8 +272,7 @@ public function executeQuery(string $sql, array $params = [], $types = [], Query
266272 * @throws Exception
267273 */
268274 public function executeUpdate (string $ sql , array $ params = [], array $ types = []): int {
269- $ sql = $ this ->replaceTablePrefix ($ sql );
270- $ sql = $ this ->adapter ->fixupStatement ($ sql );
275+ $ sql = $ this ->finishQuery ($ sql );
271276 $ this ->queriesExecuted ++;
272277 $ this ->logQueryToFile ($ sql );
273278 return parent ::executeUpdate ($ sql , $ params , $ types );
@@ -516,6 +521,16 @@ public function tableExists($table) {
516521 return $ schema ->tablesExist ([$ table ]);
517522 }
518523
524+ protected function finishQuery (string $ statement ): string {
525+ $ statement = $ this ->replaceTablePrefix ($ statement );
526+ $ statement = $ this ->adapter ->fixupStatement ($ statement );
527+ if ($ this ->logRequestId ) {
528+ return $ statement . " /* reqid: " . $ this ->requestId . " */ " ;
529+ } else {
530+ return $ statement ;
531+ }
532+ }
533+
519534 // internal use
520535 /**
521536 * @param string $statement
0 commit comments