Ver Fonte

- initial support for BIGINT database in DB core and SQL based database
modules, closes patch #2101659
- some tests for mysql were done, but more testing, especially for the
postgres and unixodbc would be appreciated
- Todo: fix other DB modules, at the moment some warnings are printed
during compilation because of the unhandled BIGINT state


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4928 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt há 17 anos atrás
pai
commit
7746b450f7
3 ficheiros alterados com 72 adições e 0 exclusões
  1. 43 0
      lib/srdb1/db_ut.c
  2. 21 0
      lib/srdb1/db_ut.h
  3. 8 0
      lib/srdb1/db_val.h

+ 43 - 0
lib/srdb1/db_ut.c

@@ -62,6 +62,26 @@ inline int db_str2int(const char* _s, int* _v)
 }
 
 
+inline int db_str2longlong(const char* _s, long long * _v)
+{
+	long long tmp;
+
+	if (!_s || !_v) {
+	       LM_ERR("Invalid parameter value\n");
+	       return -1;
+	}
+
+	tmp = strtoll(_s, 0, 10);
+	if ((tmp == LLONG_MAX || tmp == LLONG_MIN) && errno == ERANGE) {
+		LM_ERR("Value out of range\n");
+		return -1;
+	}
+
+	*_v = tmp;
+	return 0;
+}
+
+
 /*
  * Convert a string to double
  */
@@ -101,6 +121,29 @@ inline int db_int2str(int _v, char* _s, int* _l)
 }
 
 
+/*
+ * Convert an long long to string
+ */
+inline int db_longlong2str(long long _v, char* _s, int* _l)
+{
+	int ret;
+
+	if ((!_s) || (!_l) || (!*_l)) {
+		LM_ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	ret = snprintf(_s, *_l, "%-lld", _v);
+	if (ret < 0 || ret >= *_l) {
+		LM_ERR("Error in snprintf\n");
+		return -1;
+	}
+	*_l = ret;
+
+	return 0;
+}
+
+
 /*
  * Convert a double to string
  */

+ 21 - 0
lib/srdb1/db_ut.h

@@ -64,6 +64,16 @@
 int db_str2int(const char* _s, int* _v);
 
 
+/**
+ * Converts a char into an long long value.
+ *
+ * \param _s source value
+ * \param _v target value
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_str2longlong(const char* _s, long long* _v);
+
+
 /**
  * Converts a char into a double value.
  *
@@ -85,6 +95,17 @@ int db_str2double(const char* _s, double* _v);
 int db_int2str(int _v, char* _s, int* _l);
 
 
+/**
+ * Converts a long long value in a char pointer.
+ *
+ * \param _v source value
+ * \param _s target value
+ * \param _l available length and target length
+ * \return zero on sucess, negative on conversion errors
+ */
+int db_longlong2str(long long _v, char* _s, int* _l);
+
+
 /**
  * Converts a double value into a char pointer.
  *

+ 8 - 0
lib/srdb1/db_val.h

@@ -48,6 +48,7 @@
  */
 typedef enum {
 	DB_INT,        /**< represents an 32 bit integer number      */
+	DB_BIGINT,     /**< represents an 64 bit integer number      */
 	DB_DOUBLE,     /**< represents a floating point number       */
 	DB_STRING,     /**< represents a zero terminated const char* */
 	DB_STR,        /**< represents a string of 'str' type        */
@@ -78,6 +79,7 @@ typedef struct {
 	/** Column value structure that holds the actual data in a union.  */
 	union {
 		int           int_val;    /**< integer value              */
+		long long     ll_val;     /**< long long value            */
 		double        double_val; /**< double value               */
 		time_t        time_val;   /**< unix time_t value          */
 		const char*   string_val; /**< zero terminated string     */
@@ -121,6 +123,12 @@ typedef struct {
 #define VAL_INT(dv)    ((dv)->val.int_val)
 
 
+/**
+ * Use this macro if you need to access the long long value in the db_val_t structure.
+ */
+#define VAL_BIGINT(dv)    ((dv)->val.ll_val)
+
+
 /**
  * Use this macro if you need to access the double value in the db_val_t structure.
  */