[SR-Dev] git:janakj/mysql: - unify common rows and row allocation functionality in the DB API core

Jan Janak jan at iptel.org
Mon Feb 16 22:07:54 CET 2009


Module: sip-router
Branch: janakj/mysql
Commit: 7b7e4369af24b5e5efd9b61fe91e583c3b868d2e
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7b7e4369af24b5e5efd9b61fe91e583c3b868d2e

Author: Henning Westerholt <henning.westerholt at 1und1.de>
Committer: Henning Westerholt <henning.westerholt at 1und1.de>
Date:   Mon Dec 15 16:33:22 2008 +0000

- unify common rows and row allocation functionality in the DB API core


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

---

 modules/db_mysql/km_res.c |   10 +++-------
 modules/db_mysql/km_row.c |   18 +++++-------------
 2 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/modules/db_mysql/km_res.c b/modules/db_mysql/km_res.c
index 13a5c9b..5a743f9 100644
--- a/modules/db_mysql/km_res.c
+++ b/modules/db_mysql/km_res.c
@@ -157,7 +157,7 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
  */
 static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
 {
-	int row, len;
+	int row;
 
 	if ((!_h) || (!_r)) {
 		LM_ERR("invalid parameter\n");
@@ -171,14 +171,10 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
 		return 0;
 	}
 
-	len = sizeof(db_row_t) * RES_ROW_N(_r);
-	RES_ROWS(_r) = (struct db_row*)pkg_malloc(len);
-	if (!RES_ROWS(_r)) {
-		LM_ERR("no private memory left\n");
+	if (db_allocate_rows(_r) < 0) {
+		LM_ERR("could not allocate rows");
 		return -2;
 	}
-	LM_DBG("allocate %d bytes for rows at %p\n", len, RES_ROWS(_r));
-	memset(RES_ROWS(_r), 0, len);
 
 	for(row = 0; row < RES_ROW_N(_r); row++) {
 		CON_ROW(_h) = mysql_fetch_row(CON_RESULT(_h));
diff --git a/modules/db_mysql/km_row.c b/modules/db_mysql/km_row.c
index 87aecfb..29f39f1 100644
--- a/modules/db_mysql/km_row.c
+++ b/modules/db_mysql/km_row.c
@@ -47,26 +47,18 @@
 int db_mysql_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r)
 {
 	unsigned long* lengths;
-	int i, len;
+	int i;
 
 	if ((!_h) || (!_res) || (!_r)) {
 		LM_ERR("invalid parameter value\n");
 		return -1;
 	}
 
-	len = sizeof(db_val_t) * RES_COL_N(_res);
-	ROW_VALUES(_r) = (db_val_t*)pkg_malloc(len);
-	if (!ROW_VALUES(_r)) {
-		LM_ERR("no private memory left\n");
-		return -1;
+	if (db_allocate_row(_res, _r) != 0) {
+		LM_ERR("could not allocate row");
+		return -2;
 	}
-	LM_DBG("allocate %d bytes for row values at %p\n", len,
-			ROW_VALUES(_r));
-
-	memset(ROW_VALUES(_r), 0, len);
-	/* Save the number of columns in the ROW structure */
-	ROW_N(_r) = RES_COL_N(_res);
-
+	
 	lengths = mysql_fetch_lengths(CON_RESULT(_h));
 
 	for(i = 0; i < RES_COL_N(_res); i++) {




More information about the sr-dev mailing list