Module: sip-router
Branch: master
Commit: c4ee278460bdd9c12962d77ebafcab511a203e43
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c4ee278460bdd9c12962d77ebafcab511a203e43

Author: Peter Dunkley <[email protected]>
Committer: Peter Dunkley <[email protected]>
Date:   Wed May  2 17:40:29 2012 +0100

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.

---

 modules/db_postgres/km_dbase.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index 101cc8e..b1ac34b 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/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;
 
-       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
-       if (db_postgres_store_result(_h, &_r) != 0)
+       int tmp = db_postgres_store_result(_h, &_r);
+
+       if (tmp < 0) {
                LM_WARN("unexpected result returned");
+               ret = tmp;
+       }
        
        if (_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)
 {
        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);
+       int tmp = db_postgres_store_result(_h, &_r);
 
-       if (db_postgres_store_result(_h, &_r) != 0)
+       if (tmp < 0) {
                LM_WARN("unexpected result returned");
-       
+               ret = tmp;
+       }
+
        if (_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)
 {
        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);
+       int tmp = db_postgres_store_result(_h, &_r);
 
-       if (db_postgres_store_result(_h, &_r) != 0)
+       if (tmp < 0) {
                LM_WARN("unexpected result returned");
+               ret = tmp;
+       }
        
        if (_r)
                db_free_result(_r);
 
-       return tmp;
+       return ret;
 }
 
 /**


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to