[sr-dev] git:master: modules/db_postgres: Added support for creating new non-pooled DB connections

Peter Dunkley peter.dunkley at crocodile-rcs.com
Fri Apr 20 18:22:02 CEST 2012


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

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Fri Apr 20 17:18:57 2012 +0100

modules/db_postgres: Added support for creating new non-pooled DB connections

- There is a new dbf.init_nopool() function to be used instead of the
  current dbf.init() when you want a unique (non-pooled) connection.

---

 modules/db_postgres/km_db_postgres.c |    1 +
 modules/db_postgres/km_dbase.c       |   12 +++++++++++-
 modules/db_postgres/km_dbase.h       |    5 +++++
 3 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/modules/db_postgres/km_db_postgres.c b/modules/db_postgres/km_db_postgres.c
index 9292319..74b1a96 100644
--- a/modules/db_postgres/km_db_postgres.c
+++ b/modules/db_postgres/km_db_postgres.c
@@ -85,6 +85,7 @@ int db_postgres_bind_api(db_func_t *dbb)
 
 	dbb->use_table        = db_postgres_use_table;
 	dbb->init             = db_postgres_init;
+	dbb->init_nopool      = db_postgres_init_nopool;
 	dbb->close            = db_postgres_close;
 	dbb->query            = db_postgres_query;
 	dbb->fetch_result     = db_postgres_fetch_result;
diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index 216ca05..e664a69 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/modules/db_postgres/km_dbase.c
@@ -130,9 +130,19 @@ static void db_postgres_free_query(const db1_con_t* _con);
  */
 db1_con_t *db_postgres_init(const str* _url)
 {
-	return db_do_init(_url, (void*) db_postgres_new_connection);
+	return db_do_init(_url, (void*) db_postgres_new_connection, 0);
 }
 
+/*!
+ * \brief Initialize database for future queries - no pooling
+ * \param _url URL of the database that should be opened
+ * \return database connection on success, NULL on error
+ * \note this function must be called prior to any database functions
+ */
+db1_con_t *db_postgres_init_nopool(const str* _url)
+{
+	return db_do_init(_url, (void*) db_postgres_new_connection, 1);
+}
 
 /*!
  * \brief Close database when the database is no longer needed
diff --git a/modules/db_postgres/km_dbase.h b/modules/db_postgres/km_dbase.h
index bfdd5b1..c219a32 100644
--- a/modules/db_postgres/km_dbase.h
+++ b/modules/db_postgres/km_dbase.h
@@ -47,6 +47,11 @@
 db1_con_t* db_postgres_init(const str* _url);
 
 /*
+ * Initialize database connection - no pooling
+ */
+db1_con_t* db_postgres_init_nopool(const str* _url);
+
+/*
  * Close a database connection
  */
 void db_postgres_close(db1_con_t* _h);




More information about the sr-dev mailing list