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);
Hello Everybody,
The master branch now contains two new scripts in scripts subdirectory:
* ser_to_sr.sh: This script can be used to convert ser modules for use
with sip-router core.
* kam_to_sr.sh: This script can be used to convert kamailio modules for
use with sip-router core.
Run one of the scripts in module directory to convert a module. Both scripts
do all necessary database related changes, but I cannot guarantee that the
converted module will work or even compile. In most cases you will probably
have to do some extra changes to make the module compile, but at least you
don't have to deal with the bulk of database related changes :-).
Jan.
Hello,
I am happy to announce that I just managed to run sip-router with both
versions of the database interface, single db_mysql merged from both projects
and modules from both ser and kamailio at the same time.
I loaded sqlops (kamailio) and avp_db (ser) modules and tried to use them from
the same script and they both worked, using libsr1 and libsr2
respectively. Both modules used single db_mysql.
Here is a very simple configuration file which demonstrates how modules from
both projects can be used together:
-------------------
loadmodule "./modules/db_mysql/db_mysql.so"
loadmodule "./modules/domain/domain.so"
loadmodule "./modules/avp_db/avp_db.so"
loadmodule "./modules/sqlops/sqlops.so"
loadmodule "./modules/xlog/xlog.so"
loadmodule "./modules/avp/avp.so"
modparam("domain|avp_db", "db_url", "db_mysql://ser:heslo@localhost/ser")
modparam("sqlops","sqlcon","ca=>mysql://ser:heslo@localhost/ser")
route {
log(1, "ERR: Request received\n");
sql_query("ca", "select * from domain", "ra");
if($dbr(ra=>rows)>0) {
log(1, "ERR:Some data found\n");
} else {
log(1, "ERR:No data found\n");
}
sql_result_free("ra");
load_attrs("$fu", "100");
if ($fu.test && ($fu.test == "abc")) {
log(1, "ERR: Attribute loaded\n");
} else {
log(1, "ERR: Attribute NOT loaded\n");
}
dump_attrs();
}
-------------
As the merged db_mysql module seems to work fine, I merged it from
janakj/mysql into the master branch and I would like to encourage others to
give it a spin.
I am quite happy about the merge of db_mysql, we preserved histories from both
projects, kamailio files are prefixed with km_ and it didn't that that many
changes to make it work :-). I think this is the way to go for other database
drivers as well.
On the other hand porting kamailio modules to sip-router takes more tweaks
than I expected. There are several subsystems which are not compatible (avps)
and also kamailio seems to have more functions and data structures in the
core, some of them are missing in the sip-router core. So expect more work
when you try to port kamailio modules to sip-router.
Jan.