Module: sip-router
Branch: janakj/postgres
Commit: a9ef20728be5d67c9cf936befeb08995d3523613
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a9ef207…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Thu May 8 16:27:08 2008 +0000
- db_postgres_convert_rows function uses now the same interface like mysql,
simplify the internal logic of this function (remove tmp variables)
- null the result in case of errors in fetch_result
- related to bug #1954586
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4139 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_postgres/km_dbase.c | 10 +++++--
modules/db_postgres/km_res.c | 59 ++++++++++-----------------------------
modules/db_postgres/km_res.h | 2 +-
3 files changed, 23 insertions(+), 48 deletions(-)
diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index eda49f8..c00029e 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/modules/db_postgres/km_dbase.c
@@ -250,17 +250,21 @@ int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nr
if(RES_ROWS(*_res) != NULL) {
db_free_rows(*_res);
}
+ RES_ROWS(*_res) = 0;
RES_ROW_N(*_res) = 0;
}
+ /* Get the number of rows (tuples) in the query result. */
+ RES_NUM_ROWS(*_res) = PQntuples(CON_RESULT(_con));
+
/* determine the number of rows remaining to be processed */
rows = RES_NUM_ROWS(*_res) - RES_LAST_ROW(*_res);
/* If there aren't any more rows left to process, exit */
if (rows <= 0)
return 0;
-
- /* if the fetch count is less than the remaining rows to process */
+
+ /* if the fetch count is less than the remaining rows to process */
/* set the number of rows to process (during this call) equal to the fetch count */
if (nrows < rows)
rows = nrows;
@@ -270,7 +274,7 @@ int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nr
LM_DBG("converting row %d of %d count %d\n", RES_LAST_ROW(*_res),
RES_NUM_ROWS(*_res), RES_ROW_N(*_res));
- if (db_postgres_convert_rows(_con, *_res, RES_LAST_ROW(*_res), RES_ROW_N(*_res)) < 0) {
+ if (db_postgres_convert_rows(_con, *_res) < 0) {
LM_ERR("failed to convert rows\n");
if (*_res)
db_free_result(*_res);
diff --git a/modules/db_postgres/km_res.c b/modules/db_postgres/km_res.c
index 1cd9983..f102987 100644
--- a/modules/db_postgres/km_res.c
+++ b/modules/db_postgres/km_res.c
@@ -69,7 +69,7 @@ int db_postgres_convert_result(const db_con_t* _h, db_res_t* _r)
return -2;
}
- if (db_postgres_convert_rows(_h, _r, 0, PQntuples(CON_RESULT(_h))) < 0) {
+ if (db_postgres_convert_rows(_h, _r) < 0) {
LM_ERR("failed to convert rows\n");
db_free_columns(_r);
return -3;
@@ -89,9 +89,6 @@ int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
return -1;
}
- /* Get the number of rows (tuples) in the query result. */
- RES_NUM_ROWS(_r) = PQntuples(CON_RESULT(_h));
-
/* Get the number of columns (fields) in each row of the query result. */
RES_COL_N(_r) = PQnfields(CON_RESULT(_h));
@@ -184,60 +181,36 @@ int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
/**
* Convert rows from PostgreSQL to db API representation
*/
-int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int row_start,
- int row_count)
+int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r)
{
- int row, col;
char **row_buf, *s;
- int len, fetch_count;
+ int row, col, len;
if (!_h || !_r) {
- LM_ERR("invalid parameter value\n");
+ LM_ERR("invalid parameter\n");
return -1;
}
- if (row_count == 0) {
- LM_ERR("no rows requested from the query\n");
- return 0;
- }
-
- if (!RES_NUM_ROWS(_r)) {
+ RES_ROW_N(_r) = PQntuples(CON_RESULT(_h));
+ if (!RES_ROW_N(_r)) {
LM_DBG("no rows returned from the query\n");
+ RES_ROWS(_r) = 0;
return 0;
}
- if (row_start < 0) {
- LM_ERR("starting row (%d) cannot be less "
- "then zero, setting it to zero\n", row_start);
- row_start = 0;
- }
-
- if ((row_start + row_count) > RES_NUM_ROWS(_r)) {
- LM_ERR("starting row + row count cannot be > "
- "total rows. Setting row count to read remainder of result set\n");
- row_count = RES_NUM_ROWS(_r) - row_start;
- }
-
- /* Save the number of rows in the current fetch */
- RES_ROW_N(_r) = row_count;
-
- /*
- * 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 *) * RES_COL_N(_r);
- row_buf = (char **)pkg_malloc(len);
- LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n", RES_COL_N(_r), len, row_buf);
+ len = sizeof(db_row_t) * RES_COL_N(_r);
+ row_buf = (char**)pkg_malloc(len);
if (!row_buf) {
LM_ERR("no private memory left\n");
return -1;
}
+ 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) * row_count;
+ 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, row_count, RES_ROWS(_r));
+ 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");
@@ -245,8 +218,7 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int row_start,
}
memset(RES_ROWS(_r), 0, len);
- fetch_count = 0;
- for(row = row_start; row < (row_start + row_count); row++) {
+ for(row = 0; row < RES_ROW_N(_r); row++) {
for(col = 0; col < RES_COL_N(_r); col++) {
/*
* The row data pointer returned by PQgetvalue points to storage
@@ -274,9 +246,9 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int row_start,
/*
** ASSERT: row_buf contains an entire row in strings
*/
- if(db_postgres_convert_row(_h, _r, &(RES_ROWS(_r)[fetch_count]), row_buf)<0){
+ if(db_postgres_convert_row(_h, _r, &(RES_ROWS(_r)[row]), row_buf)<0){
LM_ERR("failed to convert row #%d\n", row);
- RES_ROW_N(_r) = row - row_start;
+ RES_ROW_N(_r) = row - RES_LAST_ROW(_r);
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]);
@@ -328,7 +300,6 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r, int row_start,
*/
row_buf[col] = (char *)NULL;
}
- fetch_count++;
}
LM_DBG("freeing row buffer at %p\n", row_buf);
diff --git a/modules/db_postgres/km_res.h b/modules/db_postgres/km_res.h
index 08223d4..860ef56 100644
--- a/modules/db_postgres/km_res.h
+++ b/modules/db_postgres/km_res.h
@@ -34,6 +34,6 @@ int db_postgres_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r,
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 db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r);
#endif
Module: sip-router
Branch: janakj/postgres
Commit: 393e4acea8ca6795be3ad308dfae887b9aecedb6
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=393e4ac…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Mar 10 11:17:28 2008 +0000
- content of faq removed (mistakenly added by me after Henning did the cleanup for modules' docs; rev 3839)
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3901 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_postgres/km_README | 43 +---------------------------------------
1 files changed, 2 insertions(+), 41 deletions(-)
diff --git a/modules/db_postgres/km_README b/modules/db_postgres/km_README
index 8304dd8..9c30832 100644
--- a/modules/db_postgres/km_README
+++ b/modules/db_postgres/km_README
@@ -10,8 +10,8 @@ Greg Fausak
Copyright � 2003 Greg Fausak
Revision History
- Revision $Revision$ $Date: 2008-03-07 21:52:29 +0200
- (Fri, 07 Mar 2008) $
+ Revision $Revision$ $Date: 2008-03-08 01:03:56 +0200
+ (Sat, 08 Mar 2008) $
__________________________________________________________
Table of Contents
@@ -28,8 +28,6 @@ Greg Fausak
1.4. Exported Functions
1.5. Installation and Running
- 2. Frequently Asked Questions
-
Chapter 1. User's Guide
1.1. Overview
@@ -62,40 +60,3 @@ Chapter 1. User's Guide
1.5. Installation and Running
Notes about installation and running.
-
-Chapter 2. Frequently Asked Questions
-
- Revision History
- Revision $Revision$ $Date: 2005-06-13 19:47:24 +0300 (Mon,
- 13 Jun 2005) $
-
- 2.1.
-
- Where can I find more about OpenSER?
-
- Take a look at http://openser.org/.
-
- 2.2.
-
- Where can I post a question about this module?
-
- First at all check if your question was already answered on one
- of our mailing lists:
- * User Mailing List -
- http://openser.org/cgi-bin/mailman/listinfo/users
- * Developer Mailing List -
- http://openser.org/cgi-bin/mailman/listinfo/devel
-
- E-mails regarding any stable OpenSER release should be sent to
- <users(a)openser.org> and e-mails regarding development versions
- should be sent to <devel(a)openser.org>.
-
- If you want to keep the mail private, send it to
- <team(a)openser.org>.
-
- 2.3.
-
- How can I report a bug?
-
- Please follow the guidelines provided at:
- http://sourceforge.net/tracker/?group_id=139143.