[SR-Dev] git:janakj/mysql: - change behaviour of db_str2val, this now copy strings
Jan Janak
jan at iptel.org
Mon Feb 16 22:07:54 CET 2009
Module: sip-router
Branch: janakj/mysql
Commit: b32ac21f17c46f6d3d6c60f3a02ddb66ae9061fe
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b32ac21f17c46f6d3d6c60f3a02ddb66ae9061fe
Author: Henning Westerholt <henning.westerholt at 1und1.de>
Committer: Henning Westerholt <henning.westerholt at 1und1.de>
Date: Mon Dec 15 15:07:12 2008 +0000
- 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
---
modules/db_mysql/km_val.c | 66 +++------------------------------------------
1 files changed, 4 insertions(+), 62 deletions(-)
diff --git a/modules/db_mysql/km_val.c b/modules/db_mysql/km_val.c
index 12f6ac5..338e48f 100644
--- a/modules/db_mysql/km_val.c
+++ b/modules/db_mysql/km_val.c
@@ -32,9 +32,6 @@
#include "val.h"
#include "my_con.h"
-#include <string.h>
-#include <stdio.h>
-
/*!
* \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 l;
+ int l, tmp;
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)) {
- 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:
l = strlen(VAL_STRING(_v));
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;
- 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:
l = VAL_BLOB(_v).len;
if (*_len < (l * 2 + 3)) {
More information about the sr-dev
mailing list