From 38f9b6097033a255a816ea0b6a0f29a4f2beacd2 Mon Sep 17 00:00:00 2001 From: Mohamed Rashd Date: Mon, 21 Mar 2022 18:21:40 +0530 Subject: [PATCH] Fix sql query that gets subscribed devices --- .../mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 9b7568c2a1..aff4465a04 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -902,6 +902,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); + String query = null; try { List devices = new ArrayList<>(); if (deviceIds.isEmpty()) { @@ -937,10 +938,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "WHERE DM_DEVICE.ID IN (", - ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != " + EnrolmentInfo.Status.REMOVED); + ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ?"); deviceIds.stream().map(ignored -> "?").forEach(joiner::add); - String query = joiner.toString(); + query = joiner.toString(); if (name != null && !name.isEmpty()) { query += " AND DM_DEVICE.NAME LIKE ?"; @@ -967,6 +968,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { ps.setObject(index++, deviceId); } ps.setInt(index++, tenantId); + ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString()); if (isDeviceNameProvided) { ps.setString(index++, name + "%"); } @@ -993,7 +995,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } } catch (SQLException e) { String msg = "Error occurred while retrieving information of all registered devices " + - "according to device ids and the limit area."; + "according to device ids and the limit area. Executed query " + query; log.error(msg, e); throw new DeviceManagementDAOException(msg, e); }