GUACAMOLE-394: Use subquery for querying MAX() via SQL Server.

This commit is contained in:
Michael Jumper
2017-12-11 23:15:53 -08:00
parent dbd5b98250
commit 394a289879
2 changed files with 33 additions and 20 deletions

View File

@@ -101,15 +101,17 @@
proxy_encryption_method, proxy_encryption_method,
connection_weight, connection_weight,
failover_only, failover_only,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_connection_history]
WHERE [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
) AS last_active
FROM [guacamole_connection] FROM [guacamole_connection]
LEFT JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE [guacamole_connection].connection_id IN WHERE [guacamole_connection].connection_id IN
<foreach collection="identifiers" item="identifier" <foreach collection="identifiers" item="identifier"
open="(" separator="," close=")"> open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER} #{identifier,jdbcType=INTEGER}
</foreach> </foreach>;
GROUP BY [guacamole_connection].connection_id;
SELECT primary_connection_id, sharing_profile_id SELECT primary_connection_id, sharing_profile_id
FROM [guacamole_sharing_profile] FROM [guacamole_sharing_profile]
@@ -137,18 +139,20 @@
proxy_encryption_method, proxy_encryption_method,
connection_weight, connection_weight,
failover_only, failover_only,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_connection_history]
WHERE [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
) AS last_active
FROM [guacamole_connection] FROM [guacamole_connection]
JOIN [guacamole_connection_permission] ON [guacamole_connection_permission].connection_id = [guacamole_connection].connection_id JOIN [guacamole_connection_permission] ON [guacamole_connection_permission].connection_id = [guacamole_connection].connection_id
LEFT JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE [guacamole_connection].connection_id IN WHERE [guacamole_connection].connection_id IN
<foreach collection="identifiers" item="identifier" <foreach collection="identifiers" item="identifier"
open="(" separator="," close=")"> open="(" separator="," close=")">
#{identifier,jdbcType=INTEGER} #{identifier,jdbcType=INTEGER}
</foreach> </foreach>
AND [guacamole_connection_permission].user_id = #{user.objectID,jdbcType=INTEGER} AND [guacamole_connection_permission].user_id = #{user.objectID,jdbcType=INTEGER}
AND permission = 'READ' AND permission = 'READ';
GROUP BY [guacamole_connection].connection_id;
SELECT primary_connection_id, [guacamole_sharing_profile].sharing_profile_id SELECT primary_connection_id, [guacamole_sharing_profile].sharing_profile_id
FROM [guacamole_sharing_profile] FROM [guacamole_sharing_profile]
@@ -178,14 +182,16 @@
proxy_encryption_method, proxy_encryption_method,
connection_weight, connection_weight,
failover_only, failover_only,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_connection_history]
WHERE [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
) AS last_active
FROM [guacamole_connection] FROM [guacamole_connection]
LEFT JOIN [guacamole_connection_history] ON [guacamole_connection_history].connection_id = [guacamole_connection].connection_id
WHERE WHERE
<if test="parentIdentifier != null">parent_id = #{parentIdentifier,jdbcType=INTEGER}</if> <if test="parentIdentifier != null">parent_id = #{parentIdentifier,jdbcType=INTEGER}</if>
<if test="parentIdentifier == null">parent_id IS NULL</if> <if test="parentIdentifier == null">parent_id IS NULL</if>
AND [guacamole_connection].connection_name = #{name,jdbcType=VARCHAR} AND [guacamole_connection].connection_name = #{name,jdbcType=VARCHAR}
GROUP BY [guacamole_connection].connection_id
</select> </select>

View File

@@ -80,15 +80,17 @@
email_address, email_address,
organization, organization,
organizational_role, organizational_role,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_user_history]
WHERE [guacamole_user_history].user_id = [guacamole_user].user_id
) AS last_active
FROM [guacamole_user] FROM [guacamole_user]
LEFT JOIN [guacamole_user_history] ON [guacamole_user_history].user_id = [guacamole_user].user_id
WHERE [guacamole_user].username IN WHERE [guacamole_user].username IN
<foreach collection="identifiers" item="identifier" <foreach collection="identifiers" item="identifier"
open="(" separator="," close=")"> open="(" separator="," close=")">
#{identifier,jdbcType=VARCHAR} #{identifier,jdbcType=VARCHAR}
</foreach> </foreach>;
GROUP BY [guacamole_user].user_id
</select> </select>
@@ -112,10 +114,13 @@
email_address, email_address,
organization, organization,
organizational_role, organizational_role,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_user_history]
WHERE [guacamole_user_history].user_id = [guacamole_user].user_id
) AS last_active
FROM [guacamole_user] FROM [guacamole_user]
JOIN [guacamole_user_permission] ON affected_user_id = [guacamole_user].user_id JOIN [guacamole_user_permission] ON affected_user_id = [guacamole_user].user_id
LEFT JOIN [guacamole_user_history] ON [guacamole_user_history].user_id = [guacamole_user].user_id
WHERE [guacamole_user].username IN WHERE [guacamole_user].username IN
<foreach collection="identifiers" item="identifier" <foreach collection="identifiers" item="identifier"
open="(" separator="," close=")"> open="(" separator="," close=")">
@@ -123,7 +128,6 @@
</foreach> </foreach>
AND [guacamole_user_permission].user_id = #{user.objectID,jdbcType=INTEGER} AND [guacamole_user_permission].user_id = #{user.objectID,jdbcType=INTEGER}
AND permission = 'READ' AND permission = 'READ'
GROUP BY [guacamole_user].user_id
</select> </select>
@@ -147,12 +151,15 @@
email_address, email_address,
organization, organization,
organizational_role, organizational_role,
MAX(start_date) AS last_active (
SELECT MAX(start_date)
FROM [guacamole_user_history]
WHERE [guacamole_user_history].user_id = [guacamole_user].user_id
) AS last_active
FROM [guacamole_user] FROM [guacamole_user]
LEFT JOIN [guacamole_user_history] ON [guacamole_user_history].user_id = [guacamole_user].user_id LEFT JOIN [guacamole_user_history] ON [guacamole_user_history].user_id = [guacamole_user].user_id
WHERE WHERE
[guacamole_user].username = #{username,jdbcType=VARCHAR} [guacamole_user].username = #{username,jdbcType=VARCHAR}
GROUP BY [guacamole_user].user_id
</select> </select>