Module: sip-router
Branch: janakj/postgres
Commit: 51b3f28f8da399cac3931f34296c6f03d84ac303
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=51b3f28…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Fri Feb 8 13:54:15 2008 +0000
- smaller optimization in postgres module
git-svn-id:
https://openser.svn.sourceforge.net/svnroot/openser/trunk@3667
689a6050-402a-0410-94f2-e92a70836424
---
modules/db_postgres/km_db_res.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/modules/db_postgres/km_db_res.c b/modules/db_postgres/km_db_res.c
index 43b1afb..7cdec54 100644
--- a/modules/db_postgres/km_db_res.c
+++ b/modules/db_postgres/km_db_res.c
@@ -181,7 +181,7 @@ int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int row_start,
int row_count)
{
- int row, cols, col;
+ int row, col;
char **row_buf, *s;
int len, fetch_count;
@@ -215,16 +215,13 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int
row_start,
/* Save the number of rows in the current fetch */
RES_ROW_N(_r) = row_count;
- /* Save the number of columns in the result query */
- cols = RES_COL_N(_r);
-
/*
* Allocate an array of pointers one per column. It that will be used to hold
* the address of the string representation of each column.
*/
- len = sizeof(char *) * cols;
+ len = sizeof(char *) * RES_COL_N(_r);
row_buf = (char **)pkg_malloc(len);
- LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n", cols, len,
row_buf);
+ LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n",
RES_COL_N(_r), len, row_buf);
if (!row_buf) {
LM_ERR("no private memory left\n");
return -1;
@@ -244,7 +241,7 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int
row_start,
fetch_count = 0;
for(row = row_start; row < (row_start + row_count); row++) {
- for(col = 0; col < cols; col++) {
+ for(col = 0; col < RES_COL_N(_r); col++) {
/*
* The row data pointer returned by PQgetvalue points to storage
* that is part of the PGresult structure. One should not modify
@@ -274,7 +271,7 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int
row_start,
if(db_postgres_convert_row(_h, _r, &(RES_ROWS(_r)[fetch_count]), row_buf)<0){
LM_ERR("failed to convert row #%d\n", row);
RES_ROW_N(_r) = row - row_start;
- for (col=0; col<cols; col++) {
+ for (col = 0; col < RES_COL_N(_r); col++) {
LM_DBG("freeing row_buf[%d] at %p\n", col, row_buf[col]);
pkg_free(row_buf[col]);
}
@@ -301,7 +298,7 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int
row_start,
* that pg_free_rows(), pg_free_row() or pg_free_result() is eventually
* called.
*/
- for (col=0; col<cols; col++) {
+ for (col = 0; col < RES_COL_N(_r); col++) {
switch (RES_TYPES(_r)[col]) {
case DB_STRING:
case DB_STR:
@@ -359,8 +356,7 @@ int db_postgres_convert_row(const db_con_t* _h, db_res_t* _r,
db_row_t* _row,
LM_ERR("no private memory left\n");
return -1;
}
- LM_DBG("allocate %d bytes for row values at %p\n", sizeof(db_val_t) *
RES_COL_N(_r),
- ROW_VALUES(_row));
+ 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);