Browse code

ims_usrloc_scscf: In case the contact_id after insert_update is 0, do the old query again (last_inserted_id is only set, if there was really an UPDATE or INSERT, not if nothing was changed)

Carsten Bock authored on 05/08/2014 15:21:06
Showing 1 changed files
... ...
@@ -252,6 +252,29 @@ int db_insert_ucontact(impurecord_t* _r, ucontact_t* _c) {
252 252
 		return -1;
253 253
 	}
254 254
 	contact_id = ul_dbf.last_inserted_id(ul_dbh);
255
+	if (contact_id <= 0) {
256
+		/* search for the ID if the contact just entered */
257
+		if (ul_dbf.query(ul_dbh, key, 0, val, key_return, 1, 1, NULL, &_rs) != 0) {
258
+			LM_ERR("Unable to find contact [%.*s] in DB to complete IMPU-contact mapping\n", _c->c.len, _c->c.s);
259
+			ul_dbf.free_result(ul_dbh, _rs);
260
+			return -1;
261
+		}
262
+
263
+		if (RES_ROW_N(_rs) == 0) {
264
+			LM_DBG("Contact %.*s not found in DB\n",_c->c.len, _c->c.s);
265
+			ul_dbf.free_result(ul_dbh, _rs);
266
+			return -1;
267
+		}
268
+
269
+		if (RES_ROW_N(_rs) > 1) {
270
+			LM_WARN("more than one contact found in DB for contact [%.*s] - this should not happen... proceeding with first entry\n",
271
+				_c->c.len, _c->c.s);
272
+		}
273
+
274
+		ret_val = ROW_VALUES(RES_ROWS(_rs));
275
+		contact_id = ret_val[0].val.int_val;
276
+		ul_dbf.free_result(ul_dbh, _rs);
277
+	}
255 278
 	LM_DBG("contact ID is %d\n", contact_id);
256 279
 
257 280
 	/* search for ID of the associated IMPU */