Browse Source

- change behaviour of db_str2val, this now copy strings
- this change was necessary because in some circumstances the memory that is
returned from the database driver is used by some other means too fast,
causes crashed or wrong results later on, this bug is timing related
- this means for mysql and unixodbc that the performance will be decreased a
bit, postgres already copied the string, so here nothing change
- add a new function to DB core API, db_val2str that, usable to convert
numerical values to a string, and common things like NULL values conversion,
parameter checks
- convert mysql, postgres and unixodbc module to use this new function
- convert postgres function to use the core db_str2val function, the copying
is now done at a different place, cleanup the code somewhat
- remove unnecessary assignment if a NULL value is encountered in postgres
- TODO: fix NULL handling and double copying that is done now for unixodbc


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

Henning Westerholt 16 years ago
parent
commit
b32ac21f17
1 changed files with 4 additions and 62 deletions
  1. 4 62
      modules/db_mysql/km_val.c

+ 4 - 62
modules/db_mysql/km_val.c

@@ -32,9 +32,6 @@
 #include "val.h"
 #include "val.h"
 #include "my_con.h"
 #include "my_con.h"
 
 
-#include <string.h>
-#include <stdio.h>
-
 
 
 /*!
 /*!
  * \brief Converting a value to a string
  * \brief Converting a value to a string
@@ -48,60 +45,14 @@
  */
  */
 int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
 int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
 {
 {
-	int l;
+	int l, tmp;
 	char* old_s;
 	char* old_s;
 
 
-	if (!_c || !_v || !_s || !_len || !*_len) {
-		LM_ERR("invalid parameter value\n");
-		return -1;
-	}
+	tmp = db_val2str(_c, _v, _s, _len);
+	if (tmp < 1)
+		return tmp;
 
 
-	if (VAL_NULL(_v)) {
-		if (*_len < sizeof("NULL")) {
-			LM_ERR("buffer too small\n");
-			return -1;
-		}
-		*_len = snprintf(_s, *_len, "NULL");
-		return 0;
-	}
-	
 	switch(VAL_TYPE(_v)) {
 	switch(VAL_TYPE(_v)) {
-	case DB_INT:
-		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
-			LM_ERR("error while converting string to int\n");
-			return -2;
-		} else {
-			return 0;
-		}
-		break;
-
-	case DB_BIGINT:
-		if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) {
-			LM_ERR("error while converting string to big int\n");
-			return -3;
-		} else {
-			return 0;
-		}
-		break;
-
-	case DB_BITMAP:
-		if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
-			LM_ERR("error while converting string to int\n");
-			return -4;
-		} else {
-			return 0;
-		}
-		break;
-
-	case DB_DOUBLE:
-		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
-			LM_ERR("error while converting string to double\n");
-			return -5;
-		} else {
-			return 0;
-		}
-		break;
-
 	case DB_STRING:
 	case DB_STRING:
 		l = strlen(VAL_STRING(_v));
 		l = strlen(VAL_STRING(_v));
 		if (*_len < (l * 2 + 3)) {
 		if (*_len < (l * 2 + 3)) {
@@ -133,15 +84,6 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
 		}
 		}
 		break;
 		break;
 
 
-	case DB_DATETIME:
-		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
-			LM_ERR("error while converting string to time_t\n");
-			return -8;
-		} else {
-			return 0;
-		}
-		break;
-
 	case DB_BLOB:
 	case DB_BLOB:
 		l = VAL_BLOB(_v).len;
 		l = VAL_BLOB(_v).len;
 		if (*_len < (l * 2 + 3)) {
 		if (*_len < (l * 2 + 3)) {