瀏覽代碼

db_mysql: added parameter unsigend_type

- if set to 1, then the module converts unsigned column value to
DB1_UINT or DB1_UBIGINT
Daniel-Constantin Mierla 7 年之前
父節點
當前提交
d66fc71462
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 2 0
      src/modules/db_mysql/db_mysql.c
  2. 6 3
      src/modules/db_mysql/km_res.c

+ 2 - 0
src/modules/db_mysql/db_mysql.c

@@ -44,6 +44,7 @@ unsigned int my_retries = 1;    /* Number of retries when command fails */
 unsigned int my_server_timezone = 0; /* Use FROM_UNIXTIME() for date conversion */
 
 unsigned long my_client_ver = 0;
+int db_mysql_unsigned_type = 0;
 
 struct mysql_counters_h mysql_cnts_h;
 counter_def_t mysql_cnt_defs[] =  {
@@ -98,6 +99,7 @@ static param_export_t params[] = {
 	{"auto_reconnect",   INT_PARAM, &db_mysql_auto_reconnect},
 	{"insert_delayed",   INT_PARAM, &db_mysql_insert_all_delayed},
 	{"update_affected_found", INT_PARAM, &db_mysql_update_affected_found},
+	{"unsigned_type",    PARAM_INT, &db_mysql_unsigned_type},
 	{0, 0, 0}
 };
 

+ 6 - 3
src/modules/db_mysql/km_res.c

@@ -38,6 +38,7 @@
 #include "km_my_con.h"
 #include "km_res.h"
 
+extern int db_mysql_unsigned_type;
 
 /*!
  * \brief Get and convert columns from a result
@@ -96,17 +97,19 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
 			case MYSQL_TYPE_LONG:
 			case MYSQL_TYPE_INT24:
 			case MYSQL_TYPE_TIMESTAMP:
-				if (fields[col].flags & UNSIGNED_FLAG) {
+				if ((db_mysql_unsigned_type != 0)
+						&& (fields[col].flags & UNSIGNED_FLAG)) {
 					LM_DBG("use DB1_UINT result type\n");
 					RES_TYPES(_r)[col] = DB1_UINT;
 				} else {
 					LM_DBG("use DB1_INT result type\n");
-					RES_TYPES(_r)[col] = DB1_UINT;
+					RES_TYPES(_r)[col] = DB1_INT;
 				}
 				break;
 
 			case MYSQL_TYPE_LONGLONG:
-				if (fields[col].flags & UNSIGNED_FLAG) {
+				if ((db_mysql_unsigned_type != 0)
+						&& (fields[col].flags & UNSIGNED_FLAG)) {
 					LM_DBG("use DB1_UBIGINT result type\n");
 					RES_TYPES(_r)[col] = DB1_UBIGINT;
 				} else {