From ada2ad57e9b9ce2186b94c77e93c38ad23a979f3 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Mon, 4 Sep 2023 12:18:06 +0000 Subject: [PATCH 1/2] fix: input host variables with parent name --- ocesql/ppout.c | 118 +++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 42 deletions(-) diff --git a/ocesql/ppout.c b/ocesql/ppout.c index 49f26df..d9ef0a8 100644 --- a/ocesql/ppout.c +++ b/ocesql/ppout.c @@ -402,13 +402,12 @@ void ppoutputconnect(struct cb_exec_list *list) { return; } -void _ppoutputparam(char *varface, int type, int digits, int scale, - int iteration) { +static void _ppoutputparamheader(const char *mod, int type, int digits, + int scale) { char buff[256]; memset(buff, 0, sizeof(buff)); - com_sprintf(buff, sizeof(buff), - "OCESQL%5sCALL \"OCESQLSetSQLParams\" USING\n", " "); + com_sprintf(buff, sizeof(buff), "OCESQL%5sCALL \"%s\" USING\n", " ", mod); fputs(buff, outfile); memset(buff, 0, sizeof(buff)); @@ -422,6 +421,59 @@ void _ppoutputparam(char *varface, int type, int digits, int scale, memset(buff, 0, sizeof(buff)); com_sprintf(buff, sizeof(buff), "OCESQL%10sBY VALUE %d\n", " ", scale); fputs(buff, outfile); +} + +static void _ppoutputparamfooter() { + char buff[256]; + memset(buff, 0, sizeof(buff)); + + com_sprintf(buff, sizeof(buff), "OCESQL%5sEND-CALL\n", " "); + fputs(buff, outfile); +} + +void __ppoutputparambyfield(const char *mod, struct cb_field *field, int type, + int digits, int scale, int iteration) { + + char buff[256]; + + _ppoutputparamheader(mod, type, digits, scale); + + memset(buff, 0, sizeof(buff)); + com_sprintf(buff, sizeof(buff), "OCESQL%10sBY REFERENCE %s", " ", + field->sname); + fputs(buff, outfile); + struct cb_field *f = field->parent; + + while (f) { + memset(buff, 0, sizeof(buff)); + com_sprintf(buff, sizeof(buff), "\nOCESQL%10s OF %s", " ", + f->sname); + fputs(buff, outfile); + if (f->parent) { + memset(buff, 0, sizeof(buff)); + com_sprintf(buff, sizeof(buff), "\n"); + fputs(buff, outfile); + } + f = f->parent; + } + + memset(buff, 0, sizeof(buff)); + if (iteration > 0) { + com_sprintf(buff, sizeof(buff), "(1)\n", " "); + } else { + com_sprintf(buff, sizeof(buff), "\n"); + } + fputs(buff, outfile); + + _ppoutputparamfooter(type, digits, scale); +} + +void __ppoutputparam(const char *mod, char *varface, int type, int digits, + int scale, int iteration) { + char buff[256]; + + _ppoutputparamheader(mod, type, digits, scale); + memset(buff, 0, sizeof(buff)); if (iteration > 0) { com_sprintf(buff, sizeof(buff), "OCESQL%10sBY REFERENCE %s(1)\n", " ", @@ -432,11 +484,18 @@ void _ppoutputparam(char *varface, int type, int digits, int scale, } fputs(buff, outfile); - memset(buff, 0, sizeof(buff)); + _ppoutputparamfooter(); +} - com_sprintf(buff, sizeof(buff), "OCESQL%5sEND-CALL\n", " "); - fputs(buff, outfile); - return; +void _ppoutputparambyfield(struct cb_field *field, int type, int digits, + int scale, int iteration) { + __ppoutputparambyfield("OCESQLSetSQLParams", field, type, digits, scale, + iteration); +} +void _ppoutputparam(char *varface, int type, int digits, int scale, + int iteration) { + __ppoutputparam("OCESQLSetSQLParams", varface, type, digits, scale, + iteration); } int ppoutputparam(struct cb_hostreference_list *host_list, int iteration) { @@ -477,7 +536,7 @@ int ppoutputparam(struct cb_hostreference_list *host_list, int iteration) { printerrormsg(f->sname, host_list->lineno, buff); return count; } - _ppoutputparam(f->sname, type, digits, scale, iteration); + _ppoutputparambyfield(f, type, digits, scale, iteration); count++; f = f->sister; } @@ -489,41 +548,16 @@ int ppoutputparam(struct cb_hostreference_list *host_list, int iteration) { return count; } +void ppoutputresparambyfield(struct cb_field *field, int type, int digits, + int scale, int iteration) { + __ppoutputparambyfield("OCESQLSetResultParams", field, type, digits, scale, + iteration); +} + void ppoutputresparam(char *varface, int type, int digits, int scale, int iteration) { - char buff[256]; - - memset(buff, 0, sizeof(buff)); - com_sprintf(buff, sizeof(buff), - "OCESQL%5sCALL \"OCESQLSetResultParams\" USING\n", " "); - fputs(buff, outfile); - - memset(buff, 0, sizeof(buff)); - com_sprintf(buff, sizeof(buff), "OCESQL%10sBY VALUE %d\n", " ", type); - fputs(buff, outfile); - - memset(buff, 0, sizeof(buff)); - com_sprintf(buff, sizeof(buff), "OCESQL%10sBY VALUE %d\n", " ", digits); - fputs(buff, outfile); - - memset(buff, 0, sizeof(buff)); - com_sprintf(buff, sizeof(buff), "OCESQL%10sBY VALUE %d\n", " ", scale); - fputs(buff, outfile); - memset(buff, 0, sizeof(buff)); - if (iteration > 0) { - com_sprintf(buff, sizeof(buff), "OCESQL%10sBY REFERENCE %s(1)\n", " ", - varface); - } else { - com_sprintf(buff, sizeof(buff), "OCESQL%10sBY REFERENCE %s\n", " ", - varface); - } - fputs(buff, outfile); - - memset(buff, 0, sizeof(buff)); - - com_sprintf(buff, sizeof(buff), "OCESQL%5sEND-CALL\n", " "); - fputs(buff, outfile); - return; + __ppoutputparam("OCESQLSetResultParams", varface, type, digits, scale, + iteration); } void ppoutputresgroup(struct cb_field *cf, int lineno, int iteration) { From f6b1fa2c7b362e263f945b68e489c739753b51ea Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Thu, 7 Sep 2023 10:46:58 +0000 Subject: [PATCH 2/2] wip --- ocesql/ppout.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ocesql/ppout.c b/ocesql/ppout.c index d9ef0a8..a3442be 100644 --- a/ocesql/ppout.c +++ b/ocesql/ppout.c @@ -580,7 +580,7 @@ void ppoutputresgroup(struct cb_field *cf, int lineno, int iteration) { if (type == HVARTYPE_GROUP) { ppoutputresgroup(cf->children, lineno, iteration); } else { - ppoutputresparam(cf->sname, type, digits, scale, iteration); + ppoutputresparambyfield(cf, type, digits, scale, iteration); } if (cf->sister != NULL) { @@ -1695,8 +1695,7 @@ void ppbuff(struct cb_exec_list *list) { printerrormsg(child->sname, wk_res_host->lineno, buff); return; } - ppoutputresparam(child->sname, var_type, var_len, var_scale, - iteration); + ppoutputresparambyfield(child, var_type, var_len, var_scale, iteration); child = child->sister; reshostreferenceCount++; }