Module: sip-router
Branch: master
Commit: a9b939d7881696aab9d5c39099491e65b4902cee
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a9b939d…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Fri Jan 8 18:26:11 2010 +0100
lib/srdb1 (k): add generic helper method for bulk data loading, e.g. for route infos
- add a generic helper method for bulk data loading, e.g. for routing informations
from cr, lcr, htable or other similar tasks
- TODO: adapt cr (patch ready, testing needed), adapt more modules
---
lib/srdb1/db.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/srdb1/db.h | 16 ++++++++++++++++
2 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/lib/srdb1/db.c b/lib/srdb1/db.c
index c4bf7cf..6f85b22 100644
--- a/lib/srdb1/db.c
+++ b/lib/srdb1/db.c
@@ -425,3 +425,55 @@ int db_use_table(db1_con_t* _h, const str* _t)
CON_TABLE(_h) = _t;
return 0;
}
+
+
+/*! \brief Generic query helper for load bulk data
+ *
+ * Generic query helper method for load bulk data, e.g. lcr tables
+ * \param binding database module binding
+ * \param handle database connection
+ * \param name database table name
+ * \param cols queried columns
+ * \param count number of queried columns
+ * \param strict if set to 1 an error is returned when no data could be loaded,
+ otherwise just a warning is logged
+ * \param res database result, unchanged on failure and if no data could be found
+ * \return 0 if the query was run successful, -1 otherwise
+ */
+int db_load_bulk_data(db_func_t* binding, db1_con_t* handle, str* name, db_key_t* cols,
+ unsigned int count, unsigned int strict, db1_res_t* res)
+{
+ if (binding == NULL) {
+ LM_ERR("invalid database module binding\n");
+ return -1;
+ }
+
+ if(handle == NULL) {
+ LM_ERR("invalid database handle\n");
+ return -1;
+ }
+
+ if (binding->use_table(handle, name) < 0) {
+ LM_ERR("error in use_table for database\n");
+ return -1;
+ }
+
+ /* select the whole table and all the columns */
+ if(binding->query(handle, 0, 0, 0, cols, 0, count, 0, &res) < 0) {
+ LM_ERR("error while querying database\n");
+ return -1;
+ }
+
+ if(RES_ROW_N(res) == 0) {
+ binding->free_result(handle, res);
+ if (strict == 1) {
+ LM_ERR("no data in the database table %.*s\n", name->len, name->s);
+ return -1;
+ } else {
+ LM_WARN("no data in the database table %.*s, use an empty set\n",
name->len, name->s);
+ return 0;
+ }
+ }
+
+ return 0;
+}
diff --git a/lib/srdb1/db.h b/lib/srdb1/db.h
index 0429e2c..7da401b 100644
--- a/lib/srdb1/db.h
+++ b/lib/srdb1/db.h
@@ -398,5 +398,21 @@ int db_use_table(db1_con_t* _h, const str* _t);
typedef int (*db_bind_api_f)(db_func_t *dbb);
+/**
+ * \brief Generic query helper for load bulk data
+ *
+ * Generic query helper method for load bulk data, e.g. lcr tables
+ * \param binding database module binding
+ * \param handle database connection
+ * \param name database table name
+ * \param cols queried columns
+ * \param count number of queried columns
+ * \param strict if set to 1 an error is returned when no data could be loaded,
+ otherwise just a warning is logged
+ * \param res database result, unchanged on failure and if no data could be found
+ * \return 0 if the query was run successful, -1 otherwise
+ */
+int db_load_bulk_data(db_func_t* binding, db1_con_t* handle, str* name, db_key_t* cols,
+ unsigned int count, unsigned int strict, db1_res_t* res);
#endif /* DB1_H */