|
@@ -40,6 +40,7 @@
|
|
|
#include <mysql/mysql_version.h>
|
|
|
#include "../../mem/mem.h"
|
|
|
#include "../../dprint.h"
|
|
|
+#include "../../async_task.h"
|
|
|
#include "../../lib/srdb1/db_query.h"
|
|
|
#include "../../lib/srdb1/db_ut.h"
|
|
|
#include "mysql_mod.h"
|
|
@@ -124,6 +125,66 @@ static int db_mysql_submit_query(const db1_con_t* _h, const str* _s)
|
|
|
}
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+void db_mysql_async_exec_task(void *param)
|
|
|
+{
|
|
|
+ str *p;
|
|
|
+ db1_con_t* dbc;
|
|
|
+
|
|
|
+ p = (str*)param;
|
|
|
+
|
|
|
+ dbc = db_mysql_init(&p[0]);
|
|
|
+
|
|
|
+ if(dbc==NULL) {
|
|
|
+ LM_ERR("failed to open connection for [%.*s]\n", p[0].len, p[0].s);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(db_mysql_submit_query(dbc, &p[1])<0) {
|
|
|
+ LM_ERR("failed to execute query on async worker\n");
|
|
|
+ }
|
|
|
+ db_mysql_close(dbc);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Execute a raw SQL query via core async framework.
|
|
|
+ * \param _h handle for the database
|
|
|
+ * \param _s raw query string
|
|
|
+ * \return zero on success, negative value on failure
|
|
|
+ */
|
|
|
+int db_mysql_submit_query_async(const db1_con_t* _h, const str* _s)
|
|
|
+{
|
|
|
+ struct db_id* di;
|
|
|
+ async_task_t *atask;
|
|
|
+ int asize;
|
|
|
+ str *p;
|
|
|
+
|
|
|
+ di = ((struct pool_con*)_h->tail)->id;
|
|
|
+
|
|
|
+ asize = sizeof(async_task_t) + 2*sizeof(str) + di->url.len + _s->len + 2;
|
|
|
+ atask = shm_malloc(asize);
|
|
|
+ if(atask==NULL) {
|
|
|
+ LM_ERR("no more shared memory to allocate %d\n", asize);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ atask->exec = db_mysql_async_exec_task;
|
|
|
+ atask->param = (char*)atask + sizeof(async_task_t);
|
|
|
+
|
|
|
+ p = (str*)((char*)atask + sizeof(async_task_t));
|
|
|
+ p[0].s = (char*)p + 2*sizeof(str);
|
|
|
+ p[0].len = di->url.len;
|
|
|
+ strncpy(p[0].s, di->url.s, di->url.len);
|
|
|
+ p[1].s = p[0].s + p[0].len + 1;
|
|
|
+ p[1].len = _s->len;
|
|
|
+ strncpy(p[1].s, _s->s, _s->len);
|
|
|
+
|
|
|
+ async_task_push(atask);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Initialize the database module.
|
|
@@ -397,6 +458,16 @@ int db_mysql_raw_query(const db1_con_t* _h, const str* _s, db1_res_t** _r)
|
|
|
db_mysql_store_result);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Execute a raw SQL query via core async framework.
|
|
|
+ * \param _h handle for the database
|
|
|
+ * \param _s raw query string
|
|
|
+ * \return zero on success, negative value on failure
|
|
|
+ */
|
|
|
+int db_mysql_raw_query_async(const db1_con_t* _h, const str* _s)
|
|
|
+{
|
|
|
+ return db_mysql_submit_query_async(_h, _s);
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* Insert a row into a specified table.
|
|
@@ -767,6 +838,21 @@ int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, const db_va
|
|
|
db_mysql_submit_query);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Insert a row into a specified table via core async framework.
|
|
|
+ * \param _h structure representing database connection
|
|
|
+ * \param _k key names
|
|
|
+ * \param _v values of the keys
|
|
|
+ * \param _n number of key=value pairs
|
|
|
+ * \return zero on success, negative value on failure
|
|
|
+ */
|
|
|
+int db_mysql_insert_async(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
|
|
|
+{
|
|
|
+ return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str,
|
|
|
+ db_mysql_submit_query_async);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Store the name of table that will be used by subsequent database functions
|