MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / ops_async_sql_query

Function ops_async_sql_query

modules/sqlops/sqlops_impl.c:964–1024  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

962
963
964int ops_async_sql_query(struct sip_msg* msg, async_ctx *ctx,
965 str *query, struct db_url *url, pvname_list_t *dest, int one_row)
966{
967 int rc, read_fd;
968 query_async_param *param;
969
970 void *_priv;
971
972 if (!msg || !query)
973 {
974 LM_ERR("bad parameters\n");
975 return -1;
976 }
977
978 LM_DBG("query [%.*s]\n", query->len, query->s);
979
980 /* No async capabilities - just run it in blocking mode */
981 if (!DB_CAPABILITY(url->dbf, DB_CAP_ASYNC_RAW_QUERY))
982 {
983 rc = sql_query(url, msg, query, dest, one_row);
984 LM_DBG("sync query \"%.*s\" returned: %d\n", query->len, query->s, rc);
985
986 ctx->resume_param = NULL;
987 ASYNC_CLEAR_RESUME_F(ctx);
988 async_status = ASYNC_NO_IO;
989
990 /* Empty_set / Other_errors / Success */
991 return rc == 1 ? -2 : (rc != 0 ? -1 : 1);
992 }
993
994 read_fd = url->dbf.async_raw_query(url->hdl, query, &_priv);
995 if (read_fd < 0)
996 {
997 ctx->resume_param = NULL;
998 ASYNC_CLEAR_RESUME_F(ctx);
999 return -1;
1000 }
1001
1002 param = pkg_malloc(sizeof *param);
1003 if (!param)
1004 {
1005 LM_ERR("no more pkg mem\n");
1006 return E_OUT_OF_MEM;
1007 }
1008 memset(param, '\0', sizeof *param);
1009
1010 ctx->resume_param = param;
1011 ASYNC_SET_RESUME_F(ctx, resume_async_sqlquery);
1012 /* if supported in the backend */
1013 if (url->dbf.async_timeout != NULL)
1014 ctx->timeout_f = timeout_async_sqlquery;
1015
1016 param->output_avps = dest;
1017 param->hdl = url->hdl;
1018 param->dbf = &url->dbf;
1019 param->db_param = _priv;
1020 param->one_row = one_row;
1021

Callers 2

w_async_sql_queryFunction · 0.85
w_async_sql_query_oneFunction · 0.85

Calls 1

sql_queryFunction · 0.85

Tested by

no test coverage detected