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>
#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_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)
#define ASCENDING_ORDER(id1, id2) do{if( (id1) > (id2) )\
{ int temp; temp = id1; id1 = id2; id2 = temp; }}while(0)
sqlite3_stmt *stmt = 0;
int res = 0;
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);
PDM_VERIFY_SQLITE_OK(TAG, res, ERROR, OC_STACK_ERROR);
res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id1);