Corrected DB query of PDM
authorRandeep Singh <randeep.s@samsung.com>
Thu, 1 Oct 2015 09:59:57 +0000 (18:59 +0900)
committerSachin Agrawal <sachin.agrawal@intel.com>
Fri, 2 Oct 2015 15:34:04 +0000 (15:34 +0000)
To check the existence of link between two devices, We should use query with
‘and’ not ‘or’.
Previously link  was checked with ‘or’ thats why if we try to create multiple
links involving one same device and other different devices then it was showing
link already exists. for example if we create link between A-B then if we try
to create link between A-C then we are getting error that link already exists.

Change-Id: I408658af4f423a641bab077439435711ecac876e
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3361
Reviewed-by: Woochul Shim <woochul.shim@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/security/provisioning/src/provisioningdatabasemanager.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 0d3182e..e50b5f8
@@ -73,6 +73,7 @@
 #define PDM_SQLITE_LIST_ALL_UUID "SELECT UUID FROM T_DEVICE_LIST"
 #define PDM_SQLITE_GET_UUID "SELECT UUID FROM T_DEVICE_LIST WHERE ID = ?"
 #define PDM_SQLITE_GET_LINKED_DEVICES "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE ID = ? or ID2 = ?"
+#define PDM_SQLITE_GET_DEVICE_LINKS "SELECT ID,ID2 FROM T_DEVICE_LINK_STATE WHERE ID = ? and ID2 = ?"
 
 #define ASCENDING_ORDER(id1, id2) do{if( (id1) > (id2) )\
   { int temp; temp = id1; id1 = id2; id2 = temp; }}while(0)
@@ -704,8 +705,8 @@ OCStackResult PDMIsLinkExists(const OicUuid_t* uuidOfDevice1, const OicUuid_t* u
 
     sqlite3_stmt *stmt = 0;
     int res = 0;
-    res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_LINKED_DEVICES,
-                              strlen(PDM_SQLITE_GET_LINKED_DEVICES) + 1, &stmt, NULL);
+    res = sqlite3_prepare_v2(g_db, PDM_SQLITE_GET_DEVICE_LINKS,
+                              strlen(PDM_SQLITE_GET_DEVICE_LINKS) + 1, &stmt, NULL);
     PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
 
     res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1);