Browse Source

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.
Peter Dunkley 13 years ago
parent
commit
a03955fff9

+ 1 - 0
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;

+ 11 - 1
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

+ 5 - 0
modules/db_postgres/km_dbase.h

@@ -46,6 +46,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
  */