2
0
Эх сурвалжийг харах

modules/db_postgres: Fixed bug in insert/delete/update operations where success is returned when there are some errors

- Some PostgreSQL errors are only identified when the store_result()
  function is called.  Even if store_result() returns < 0 (indicating
  an error has occurred) the insert/delete/update functions can still
  return success.
Peter Dunkley 13 жил өмнө
parent
commit
c4ee278460

+ 20 - 10
modules/db_postgres/km_dbase.c

@@ -543,15 +543,19 @@ int db_postgres_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t*
 {
 {
 	db1_res_t* _r = NULL;
 	db1_res_t* _r = NULL;
 
 
-	int tmp = db_do_insert(_h, _k, _v, _n, db_postgres_val2str, db_postgres_submit_query);
+	int ret = db_do_insert(_h, _k, _v, _n, db_postgres_val2str, db_postgres_submit_query);
 	// finish the async query, otherwise the next query will not complete
 	// finish the async query, otherwise the next query will not complete
-	if (db_postgres_store_result(_h, &_r) != 0)
+	int tmp = db_postgres_store_result(_h, &_r);
+
+	if (tmp < 0) {
 		LM_WARN("unexpected result returned");
 		LM_WARN("unexpected result returned");
+		ret = tmp;
+	}
 	
 	
 	if (_r)
 	if (_r)
 		db_free_result(_r);
 		db_free_result(_r);
 
 
-	return tmp;
+	return ret;
 }
 }
 
 
 
 
@@ -568,16 +572,19 @@ int db_postgres_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _
 		const db_val_t* _v, const int _n)
 		const db_val_t* _v, const int _n)
 {
 {
 	db1_res_t* _r = NULL;
 	db1_res_t* _r = NULL;
-	int tmp = db_do_delete(_h, _k, _o, _v, _n, db_postgres_val2str,
+	int ret = db_do_delete(_h, _k, _o, _v, _n, db_postgres_val2str,
 		db_postgres_submit_query);
 		db_postgres_submit_query);
+	int tmp = db_postgres_store_result(_h, &_r);
 
 
-	if (db_postgres_store_result(_h, &_r) != 0)
+	if (tmp < 0) {
 		LM_WARN("unexpected result returned");
 		LM_WARN("unexpected result returned");
-	
+		ret = tmp;
+	}
+
 	if (_r)
 	if (_r)
 		db_free_result(_r);
 		db_free_result(_r);
 
 
-	return tmp;
+	return ret;
 }
 }
 
 
 
 
@@ -598,16 +605,19 @@ int db_postgres_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _
 		const int _un)
 		const int _un)
 {
 {
 	db1_res_t* _r = NULL;
 	db1_res_t* _r = NULL;
-	int tmp = db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un, db_postgres_val2str,
+	int ret = db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un, db_postgres_val2str,
 		db_postgres_submit_query);
 		db_postgres_submit_query);
+	int tmp = db_postgres_store_result(_h, &_r);
 
 
-	if (db_postgres_store_result(_h, &_r) != 0)
+	if (tmp < 0) {
 		LM_WARN("unexpected result returned");
 		LM_WARN("unexpected result returned");
+		ret = tmp;
+	}
 	
 	
 	if (_r)
 	if (_r)
 		db_free_result(_r);
 		db_free_result(_r);
 
 
-	return tmp;
+	return ret;
 }
 }
 
 
 /**
 /**