提交 e13614a1 authored 作者: Leon de Rooij's avatar Leon de Rooij

Fixed rowcount for nested queries


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@14798 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 f96ebe99
......@@ -27,7 +27,7 @@
* Leon de Rooij <leon@scarlet-internet.nl>
*
* Also thanks to:
* Scarlet Nederland for donating time and money
* Scarlet Telecom Nederland for funding this work.
*
*
* mod_xml_odbc.c -- Simple templating that can use ODBC to generate XML at search-time
......@@ -67,7 +67,7 @@ typedef struct xml_odbc_session_helper {
switch_xml_t xml_out_cur; /* current tag in xml that is rendered to */
int xml_out_cur_off; /* depth counter of xml_out_cur */
int render_template_count; /* when this counter > globals.max_render_template_count then stop because there's probably a loop */
int tmp_i; /* temporary counter, used for counting rows in the callback */
int rowcount; /* temporary counter, used for counting rows in the callback */
} xml_odbc_session_helper_t;
static switch_status_t xml_odbc_render_tag(xml_odbc_session_helper_t *helper);
......@@ -107,7 +107,7 @@ typedef struct xml_binding {
char *bindings;
} xml_binding_t;
static char* switch_event_expand_headers_by_pool(switch_memory_pool_t *pool, switch_event_t *event, const char *in) /* perhaps it's handy if this is moved to switch_event.c ? */
static char* switch_event_expand_headers_by_pool(switch_memory_pool_t *pool, switch_event_t *event, const char *in)
{
char *tmp, *out;
......@@ -121,21 +121,27 @@ static char* switch_event_expand_headers_by_pool(switch_memory_pool_t *pool, swi
static int xml_odbc_query_callback(void *pArg, int argc, char **argv, char **columnName)
{
xml_odbc_session_helper_t *helper = (xml_odbc_session_helper_t *) pArg;
int i;
int i, tmp_rowcount;
if (!switch_strlen_zero(helper->next_template_name)) goto done;
/* up the row counter */
helper->tmp_i++; /* TODO: WILL THIS GO WRONG FOR NESTED QUERIES ?? THINK ABOUT IT !!! */
/* loop through all columns and store them in helper->event->headers */
for (i = 0; i < argc; i++) {
switch_event_del_header(helper->event, columnName[i]);
switch_event_add_header_string(helper->event, SWITCH_STACK_BOTTOM, columnName[i], argv[i]);
}
/* up the rowcount, store it in a temporary variable and set rowcount to zero as children may use it */
helper->rowcount++;
tmp_rowcount = helper->rowcount;
helper->rowcount = 0;
/* render all children */
xml_odbc_render_children(helper);
/* restore the rowcounter - it may have been changed by a child */
helper->rowcount = tmp_rowcount;
done:
return 0;
}
......@@ -222,7 +228,7 @@ static switch_status_t xml_odbc_do_query(xml_odbc_session_helper_t *helper)
goto done;
}
if (!switch_strlen_zero(empty_result_break_to) && helper->tmp_i == 0) {
if (!switch_strlen_zero(empty_result_break_to) && helper->rowcount == 0) {
helper->next_template_name = empty_result_break_to;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论