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

Jan Janak jan at iptel.org
Wed Feb 18 01:26:22 CET 2009


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

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_postgres/km_res.c |   33 +++++++--------------------------
 1 files changed, 7 insertions(+), 26 deletions(-)

diff --git a/modules/db_postgres/km_res.c b/modules/db_postgres/km_res.c
index 061f157..c1f7509 100644
--- a/modules/db_postgres/km_res.c
+++ b/modules/db_postgres/km_res.c
@@ -222,16 +222,10 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r)
 	LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n", RES_COL_N(_r), len, row_buf);
 	memset(row_buf, 0, len);
 
-	/* Allocate a row structure for each row in the current fetch. */
-	len = sizeof(db_row_t) * RES_ROW_N(_r);
-	RES_ROWS(_r) = (db_row_t*)pkg_malloc(len);
-	LM_DBG("allocate %d bytes for %d rows at %p\n", len, RES_ROW_N(_r), RES_ROWS(_r));
-
-	if (!RES_ROWS(_r)) {
-		LM_ERR("no private memory left\n");
-		return -1;
+	if (db_allocate_rows(_r) < 0) {
+		LM_ERR("could not allocate rows");
+		return -2;
 	}
-	memset(RES_ROWS(_r), 0, len);
 
 	for(row = RES_LAST_ROW(_r); row < (RES_LAST_ROW(_r) + RES_ROW_N(_r)); row++) {
 		for(col = 0; col < RES_COL_N(_r); col++) {
@@ -293,30 +287,17 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r)
 int db_postgres_convert_row(const db_con_t* _h, db_res_t* _r, db_row_t* _row,
 		char **row_buf)
 {
-	int col, len, col_len;
+	int col, col_len;
 
 	if (!_h || !_r || !_row)  {
 		LM_ERR("invalid parameter value\n");
 		return -1;
 	}
 
-	/*
-	 * Allocate storage to hold the data type value converted from a string
-	 * because PostgreSQL returns (most) data as strings
-	 */
-	len = sizeof(db_val_t) * RES_COL_N(_r);
-	ROW_VALUES(_row) = (db_val_t*)pkg_malloc(len);
-
-	if (!ROW_VALUES(_row)) {
-		LM_ERR("no private memory left\n");
-		return -1;
+	if (db_allocate_row(_r, _row) != 0) {
+		LM_ERR("could not allocate row");
+		return -2;
 	}
-	LM_DBG("allocate %d bytes for row values at %p\n", len, ROW_VALUES(_row));
-	ROW_N(_row) = RES_COL_N(_r);
-	memset(ROW_VALUES(_row), 0, len);
-
-	/* Save the number of columns in the ROW structure */
-	ROW_N(_row) = RES_COL_N(_r);
 
 	/* For each column in the row */
 	for(col = 0; col < ROW_N(_row); col++) {




More information about the sr-dev mailing list