소스 검색

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 년 전
부모
커밋
a03955fff9
3개의 변경된 파일17개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      modules/db_postgres/km_db_postgres.c
  2. 11 1
      modules/db_postgres/km_dbase.c
  3. 5 0
      modules/db_postgres/km_dbase.h

+ 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
  */