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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Mon Sep 15 00:01:36 2014 +0200

usrloc: option to control if the null fields should be in insert statement

- ammeds previous patch 1e84aeb91cf8e7a79a9ac9091ed993be944a667b that
  introduced skipping adding the null fields
- while it was more optimal for sql backends, for non-sql that doesn't
  have a schema auto-default could break the rows
- default is to skip the null fields

---

 modules/usrloc/README               |   16 ++++++++++++++++
 modules/usrloc/doc/usrloc_admin.xml |   22 ++++++++++++++++++++++
 modules/usrloc/ucontact.c           |   34 +++++++++++++++++++++++++++++++++-
 modules/usrloc/ul_mod.c             |    2 ++
 4 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/modules/usrloc/README b/modules/usrloc/README
index ed9df55..7275236 100644
--- a/modules/usrloc/README
+++ b/modules/usrloc/README
@@ -71,6 +71,7 @@ Bogdan-Andrei Iancu
               3.33. handle_lost_tcp (int)
               3.34. expires_type (int)
               3.35. db_raw_fetch_type (int)
+              3.36. db_insert_null (int)
 
         4. Functions
         5. MI Commands
@@ -163,6 +164,7 @@ Bogdan-Andrei Iancu
    1.33. Set handle_lost_tcp parameter
    1.34. Set expires_type parameter
    1.35. Set db_raw_fetch_type parameter
+   1.36. Set db_insert_null parameter
 
 Chapter 1. Admin Guide
 
@@ -214,6 +216,7 @@ Chapter 1. Admin Guide
         3.33. handle_lost_tcp (int)
         3.34. expires_type (int)
         3.35. db_raw_fetch_type (int)
+        3.36. db_insert_null (int)
 
    4. Functions
    5. MI Commands
@@ -337,6 +340,7 @@ Chapter 1. Admin Guide
    3.33. handle_lost_tcp (int)
    3.34. expires_type (int)
    3.35. db_raw_fetch_type (int)
+   3.36. db_insert_null (int)
 
 3.1. nat_bflag (integer)
 
@@ -818,6 +822,18 @@ modparam("usrloc", "expires_type", 1)
 modparam("usrloc", "db_raw_fetch_type", 1)
 ...
 
+3.36. db_insert_null (int)
+
+   If set to 1, the insert operation to database will add null values in
+   the sql statement.
+
+   Default value is "0" (don't add null fields in insert statement).
+
+   Example 1.36. Set db_insert_null parameter
+...
+modparam("usrloc", "db_insert_null", 1)
+...
+
 4. Functions
 
    There are no exported functions that could be used in scripts.
diff --git a/modules/usrloc/doc/usrloc_admin.xml 
b/modules/usrloc/doc/usrloc_admin.xml
index 6520b49..ce2f693 100644
--- a/modules/usrloc/doc/usrloc_admin.xml
+++ b/modules/usrloc/doc/usrloc_admin.xml
@@ -945,6 +945,28 @@ modparam("usrloc", "db_raw_fetch_type", 1)
                </example>
        </section>
 
+       <section id="usrloc.p.db_insert_null">
+               <title><varname>db_insert_null</varname> (int)</title>
+               <para>
+                       If set to 1, the insert operation to database will add 
null values
+                       in the sql statement.
+               </para>
+               <para>
+               <emphasis>
+                       Default value is <quote>0</quote> (don't add null 
fields in insert
+                       statement).
+               </emphasis>
+               </para>
+               <example>
+               <title>Set <varname>db_insert_null</varname> parameter</title>
+               <programlisting format="linespecific">
+...
+modparam("usrloc", "db_insert_null", 1)
+...
+</programlisting>
+               </example>
+       </section>
+
        </section>
 
        <section>
diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c
index e16cee3..5360e3d 100644
--- a/modules/usrloc/ucontact.c
+++ b/modules/usrloc/ucontact.c
@@ -48,6 +48,8 @@
 #include "ucontact.h"
 #include "usrloc.h"
 
+extern int ul_db_insert_null;
+
 static int ul_xavp_contact_clone = 1;
 
 void ul_set_xavp_contact_clone(int v)
@@ -531,13 +533,18 @@ int db_insert_ucontact(ucontact_t* _c)
 
        nr_cols = 9;
 
-       if (_c->received.s ) {
+       if (_c->received.s) {
                keys[nr_cols] = &received_col;
                vals[nr_cols].type = DB1_STR;
                vals[nr_cols].nul = 0;
                vals[nr_cols].val.str_val.s = _c->received.s;
                vals[nr_cols].val.str_val.len = _c->received.len;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &received_col;
+               vals[nr_cols].type = DB1_STR;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
        
        if (_c->path.s) {
@@ -547,6 +554,11 @@ int db_insert_ucontact(ucontact_t* _c)
                vals[nr_cols].val.str_val.s = _c->path.s;
                vals[nr_cols].val.str_val.len = _c->path.len;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &path_col;
+               vals[nr_cols].type = DB1_STR;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
 
        if (_c->sock) {
@@ -555,6 +567,11 @@ int db_insert_ucontact(ucontact_t* _c)
                vals[nr_cols].val.str_val = _c->sock->sock_str;
                vals[nr_cols].nul = 0;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &sock_col;
+               vals[nr_cols].type = DB1_STR;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
 
        if (_c->methods != 0xFFFFFFFF) {
@@ -563,6 +580,11 @@ int db_insert_ucontact(ucontact_t* _c)
                vals[nr_cols].val.bitmap_val = _c->methods;
                vals[nr_cols].nul = 0;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &methods_col;
+               vals[nr_cols].type = DB1_BITMAP;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
 
        keys[nr_cols] = &last_mod_col;
@@ -578,6 +600,11 @@ int db_insert_ucontact(ucontact_t* _c)
                vals[nr_cols].nul = 0;
                vals[nr_cols].val.str_val = _c->ruid;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &ruid_col;
+               vals[nr_cols].type = DB1_STR;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
 
        if(_c->instance.len>0)
@@ -587,6 +614,11 @@ int db_insert_ucontact(ucontact_t* _c)
                vals[nr_cols].nul = 0;
                vals[nr_cols].val.str_val = _c->instance;
                nr_cols++;
+       } else if(ul_db_insert_null!=0) {
+               keys[nr_cols] = &instance_col;
+               vals[nr_cols].type = DB1_STR;
+               vals[nr_cols].nul = 1;
+               nr_cols++;
        }
 
        keys[nr_cols] = &reg_id_col;
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index a8a0b91..e307273 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -167,6 +167,7 @@ int handle_lost_tcp = 0;                            /*!< By 
default do not remove contacts before expira
 
 int ul_fetch_rows = 2000;                              /*!< number of rows to 
fetch from result */
 int ul_hash_size = 9;
+int ul_db_insert_null = 0;
 
 /* flags */
 unsigned int nat_bflag = (unsigned int)-1;
@@ -226,6 +227,7 @@ static param_export_t params[] = {
        {"db_ops_ruid",         INT_PARAM, &ul_db_ops_ruid},
        {"expires_type",        PARAM_INT, &ul_expires_type},
        {"db_raw_fetch_type",   PARAM_INT, &ul_db_raw_fetch_type},
+       {"db_insert_null",      PARAM_INT, &ul_db_insert_null},
        {0, 0, 0}
 };
 


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

Reply via email to