]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15148 - Fix Audit paginated query for Oracle
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Wed, 28 Jul 2021 15:55:06 +0000 (17:55 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 29 Jul 2021 20:04:50 +0000 (20:04 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/audit/AuditMapper.xml

index 469560c01a555087d1e93d64f8bf2b81a252cb23..6b8a9fc56461c14e38550810bef08008cac98687 100644 (file)
     a.created_at as "createdAt"
   </sql>
 
+  <sql id="sqlColumnsInInnerQuery">
+    uuid,
+    user_uuid,
+    user_login,
+    category,
+    operation,
+    new_value,
+    created_at
+  </sql>
+
   <select id="selectByPeriodPaginated" parameterType="map" resultType="org.sonar.db.audit.AuditDto">
+    select
+      <include refid="sqlColumns"/>
+    from audits a
+    where
+      a.created_at &gt;= #{start} and a.created_at &lt; #{end}
+    limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
+  </select>
+
+  <select id="selectByPeriodPaginated" parameterType="map" resultType="org.sonar.db.audit.AuditDto" databaseId="mssql">
     select <include refid="sqlColumns"/> from (
       select
-        row_number() over(order by created_at, uuid) as row_number, *
+        row_number() over(order by created_at, uuid) as row_number,
+          <include refid="sqlColumnsInInnerQuery" />
         from audits
         where created_at &gt;= #{start} and created_at &lt; #{end}
     ) as a
     order by a.row_number asc
   </select>
 
+  <select id="selectByPeriodPaginated" parameterType="map" resultType="org.sonar.db.audit.AuditDto" databaseId="oracle">
+    select <include refid="sqlColumns"/> from (
+      select rownum as rn, t.* from (
+        select
+        <include refid="sqlColumnsInInnerQuery"/>
+        from audits
+        where created_at &gt;= #{start} and created_at &lt; #{end}
+      ) t
+    ) a
+    where
+      a.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
+    order by a.rn asc
+  </select>
+
   <insert id="insert" parameterType="Map" useGeneratedKeys="false">
     INSERT INTO audits
     (