Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,35 @@ dumpCreateProcFunction(FILE *output, PQLFunction *f, bool orreplace, char t)
freeStringList(sl);
}

fprintf(output, "\nAS $$%s$$;", f->body);
/*
* Determine if the function/procedure's body contains
* a double dollar sign string ($$) and fill the the quote
* string with X's until the quote string is not found in
* the function body
*/
char *str;
char *dollarquote = "$$";
int counter = 1;

str = strstr(f->body, dollarquote);
while (str != NULL)
{
char *expandedquote = malloc(strlen(dollarquote) + 2);
strcpy(expandedquote, "$");

for (int i = 0; i < counter; i++)
{
strcat(expandedquote, "X");
}

counter++;
strcat(expandedquote, "$");
dollarquote = expandedquote;

str = strstr(f->body, dollarquote);
};

fprintf(output, "\nAS %s%s%s;", dollarquote, f->body, dollarquote);

/* comment */
if (options.comment && f->comment != NULL)
Expand Down