Module: kamailio
Branch: master
Commit: b9da65bcf0dea2740be9ddb2773d99e178d07117
URL:
https://github.com/kamailio/kamailio/commit/b9da65bcf0dea2740be9ddb2773d99e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-01-28T10:32:49+01:00
sqlops: exported sql_result_get() to kemi
- return value of sql query result by id, row and column
---
Modified: src/modules/sqlops/sqlops.c
---
Diff:
https://github.com/kamailio/kamailio/commit/b9da65bcf0dea2740be9ddb2773d99e…
Patch:
https://github.com/kamailio/kamailio/commit/b9da65bcf0dea2740be9ddb2773d99e…
---
diff --git a/src/modules/sqlops/sqlops.c b/src/modules/sqlops/sqlops.c
index 3943b1b81a..7172bcc8b4 100644
--- a/src/modules/sqlops/sqlops.c
+++ b/src/modules/sqlops/sqlops.c
@@ -531,6 +531,56 @@ static int ki_sqlops_is_null(sip_msg_t *msg, str *sres, int i, int
j)
return sqlops_is_null(sres, i, j);
}
+/**
+ *
+ */
+static sr_kemi_xval_t _ksr_kemi_sqlops_xval = {0};
+
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_sqlops_result_get(sip_msg_t *msg, str *resid, int row, int
col)
+{
+ sql_result_t *res = NULL;
+
+ memset(&_ksr_kemi_sqlops_xval, 0, sizeof(sr_kemi_xval_t));
+
+ if (resid == NULL || resid->s == NULL || resid->len == 0) {
+ LM_ERR("invalid result name\n");
+ sr_kemi_xval_null(&_ksr_kemi_sqlops_xval, SR_KEMI_XVAL_NULL_NONE);
+ return &_ksr_kemi_sqlops_xval;
+ }
+
+ res = sql_get_result(resid);
+ if(res==NULL) {
+ LM_ERR("invalid result container [%.*s]\n", resid->len, resid->s);
+ sr_kemi_xval_null(&_ksr_kemi_sqlops_xval, SR_KEMI_XVAL_NULL_NONE);
+ return &_ksr_kemi_sqlops_xval;
+ }
+
+ if(row >= res->nrows) {
+ sr_kemi_xval_null(&_ksr_kemi_sqlops_xval, SR_KEMI_XVAL_NULL_NONE);
+ return &_ksr_kemi_sqlops_xval;
+ }
+ if(col >= res->ncols) {
+ sr_kemi_xval_null(&_ksr_kemi_sqlops_xval, SR_KEMI_XVAL_NULL_NONE);
+ return &_ksr_kemi_sqlops_xval;
+ }
+ if(res->vals[row][col].flags&PV_VAL_NULL) {
+ sr_kemi_xval_null(&_ksr_kemi_sqlops_xval, SR_KEMI_XVAL_NULL_NONE);
+ return &_ksr_kemi_sqlops_xval;
+ }
+ if(res->vals[row][col].flags&PV_VAL_INT) {
+ _ksr_kemi_sqlops_xval.vtype = SR_KEMIP_STR;
+ _ksr_kemi_sqlops_xval.v.n = res->vals[row][col].value.n;
+ return &_ksr_kemi_sqlops_xval;
+ }
+ _ksr_kemi_sqlops_xval.vtype = SR_KEMIP_STR;
+ _ksr_kemi_sqlops_xval.v.s = res->vals[row][col].value.s;
+ return &_ksr_kemi_sqlops_xval;
+}
+
/**
*
*/
@@ -571,6 +621,11 @@ static sr_kemi_t sr_kemi_sqlops_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("sqlops"), str_init("sql_result_get"),
+ SR_KEMIP_XVAL, ki_sqlops_result_get,
+ { SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_INT,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};