Module: sip-router
Branch: master
Commit: 09c9abb0f7907132d9afee4580f0475a2e46cadc
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=09c9abb…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Nov 30 15:17:46 2011 +0100
lib/srdb1: helper functions to handle easier fetch capability
---
lib/srdb1/db.h | 16 ++++++++++
lib/srdb1/db_query.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/lib/srdb1/db.h b/lib/srdb1/db.h
index 64969a8..e27969f 100644
--- a/lib/srdb1/db.h
+++ b/lib/srdb1/db.h
@@ -452,5 +452,21 @@ int db_load_bulk_data(db_func_t* binding, db1_con_t* handle, str*
name, db_key_t
*/
int db_api_init(void);
+/**
+ * \brief wrapper around db query to handle fetch capability
+ * \return -1 error; 0 ok with no fetch capability; 1 ok with fetch capability
+ */
+int db_fetch_query(db_func_t *dbf, int frows,
+ db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+ const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
+ const db_key_t _o, db1_res_t** _r);
+
+/**
+ * \brief wrapper around db fetch to handle fetch capability
+ * \return -1 error; 0 ok with no fetch capability; 1 ok with fetch capability
+ */
+int db_fetch_next(db_func_t *dbf, int frows, db1_con_t* _h,
+ db1_res_t** _r);
+
#endif /* DB1_H */
diff --git a/lib/srdb1/db_query.c b/lib/srdb1/db_query.c
index dbde735..3f75421 100644
--- a/lib/srdb1/db_query.c
+++ b/lib/srdb1/db_query.c
@@ -357,3 +357,78 @@ int db_query_init(void)
}
return 0;
}
+
+/**
+ * wrapper around db query to handle fetch capability
+ * return: -1 error; 0 ok with no fetch capability; 1 ok with fetch capability
+ */
+int db_fetch_query(db_func_t *dbf, int frows,
+ db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+ const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
+ const db_key_t _o, db1_res_t** _r)
+{
+
+ int ret;
+
+ ret = 0;
+ *_r = NULL;
+
+ if (DB_CAPABILITY(*dbf, DB_CAP_FETCH)) {
+ if(dbf->query(_h, _k, _op, _v, _c, _n, _nc, _o, 0) < 0)
+ {
+ LM_ERR("unable to query db for fetch\n");
+ goto error;
+ }
+ if(dbf->fetch_result(_h, _r, frows)<0)
+ {
+ LM_ERR("unable to fetch the db result\n");
+ goto error;
+ }
+ ret = 1;
+ } else {
+ if(dbf->query(_h, _k, _op, _v, _c, _n, _nc, _o, _r) < 0)
+ {
+ LM_ERR("unable to do full db querry\n");
+ goto error;
+ }
+ }
+
+ return ret;
+
+error:
+ if(*_r)
+ {
+ dbf->free_result(_h, *_r);
+ *_r = NULL;
+ }
+ return -1;
+}
+
+/**
+ * wrapper around db fetch to handle fetch capability
+ * return: -1 error; 0 ok with no fetch capability; 1 ok with fetch capability
+ */
+int db_fetch_next(db_func_t *dbf, int frows, db1_con_t* _h,
+ db1_res_t** _r)
+{
+ int ret;
+
+ ret = 0;
+
+ if (DB_CAPABILITY(*dbf, DB_CAP_FETCH)) {
+ if(dbf->fetch_result(_h, _r, frows)<0) {
+ LM_ERR("unable to fetch next rows\n");
+ goto error;
+ }
+ ret = 1;
+ }
+ return ret;
+
+error:
+ if(*_r)
+ {
+ dbf->free_result(_h, *_r);
+ *_r = NULL;
+ }
+ return -1;
+}