#include "postgres_fe.h"
#include "extern.h"
Go to the source code of this file.
Functions | |
static void | output_escaped_str (char *cmd, bool quoted) |
void | output_line_number (void) |
void | output_simple_statement (char *stmt) |
static void | print_action (struct when *w) |
void | whenever_action (int mode) |
char * | hashline_number (void) |
void | output_statement (char *stmt, int whenever_mode, enum ECPG_statement_type st) |
void | output_prepare_statement (char *name, char *stmt) |
void | output_deallocate_prepare_statement (char *name) |
Variables | |
struct when when_error when_nf | when_warn |
static char * | ecpg_statement_type_name [] |
char* hashline_number | ( | void | ) |
Definition at line 89 of file output.c.
References input_filename, mm_alloc(), and yylineno.
Referenced by output_line_number().
{ /* do not print line numbers if we are in debug mode */ if (input_filename #ifdef YYDEBUG && !yydebug #endif ) { char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename)); sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); return line; } return EMPTY; }
void output_deallocate_prepare_statement | ( | char * | name | ) |
Definition at line 162 of file output.c.
References compat, free, NULL, output_escaped_str(), whenever_action(), and yyout.
{ const char *con = connection ? connection : "NULL"; if (strcmp(name, "all") != 0) { fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con); output_escaped_str(name, true); fputs(");", yyout); } else fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con); whenever_action(2); free(name); if (connection != NULL) free(connection); }
static void output_escaped_str | ( | char * | cmd, | |
bool | quoted | |||
) | [static] |
Definition at line 182 of file output.c.
Referenced by output_deallocate_prepare_statement(), output_prepare_statement(), output_simple_statement(), and output_statement().
{ int i = 0; int len = strlen(str); if (quoted && str[0] == '\"' && str[len - 1] == '\"') /* do not escape quotes * at beginning and end * if quoted string */ { i = 1; len--; fputs("\"", yyout); } /* output this char by char as we have to filter " and \n */ for (; i < len; i++) { if (str[i] == '"') fputs("\\\"", yyout); else if (str[i] == '\n') fputs("\\\n", yyout); else if (str[i] == '\\') { int j = i; /* * check whether this is a continuation line if it is, do not * output anything because newlines are escaped anyway */ /* accept blanks after the '\' as some other compilers do too */ do { j++; } while (str[j] == ' ' || str[j] == '\t'); if ((str[j] != '\n') && (str[j] != '\r' || str[j + 1] != '\n')) /* not followed by a * newline */ fputs("\\\\", yyout); } else if (str[i] == '\r' && str[i + 1] == '\n') { fputs("\\\r\n", yyout); i++; } else fputc(str[i], yyout); } if (quoted && str[0] == '\"' && str[len] == '\"') fputs("\"", yyout); }
void output_line_number | ( | void | ) |
Definition at line 10 of file output.c.
References free, hashline_number(), and yyout.
Referenced by main(), output_simple_statement(), and whenever_action().
{ char *line = hashline_number(); fprintf(yyout, "%s", line); free(line); }
void output_prepare_statement | ( | char * | name, | |
char * | stmt | |||
) |
Definition at line 148 of file output.c.
References free, NULL, output_escaped_str(), questionmarks, whenever_action(), and yyout.
{ fprintf(yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks); output_escaped_str(name, true); fputs(", ", yyout); output_escaped_str(stmt, true); fputs(");", yyout); whenever_action(2); free(name); if (connection != NULL) free(connection); }
void output_simple_statement | ( | char * | stmt | ) |
Definition at line 19 of file output.c.
References free, output_escaped_str(), and output_line_number().
{ output_escaped_str(stmt, false); output_line_number(); free(stmt); }
void output_statement | ( | char * | stmt, | |
int | whenever_mode, | |||
enum ECPG_statement_type | st | |||
) |
Definition at line 116 of file output.c.
References argsinsert, argsresult, auto_prepare, compat, dump_variables(), ecpg_statement_type_name, ECPGst_exec_immediate, ECPGst_execute, ECPGst_prepnormal, force_indicator, free, NULL, output_escaped_str(), questionmarks, reset_variables(), whenever_action(), and yyout.
{ fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks); if (st == ECPGst_execute || st == ECPGst_exec_immediate) { fprintf(yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt); } else { if (st == ECPGst_prepnormal && auto_prepare) fputs("ECPGst_prepnormal, \"", yyout); else fputs("ECPGst_normal, \"", yyout); output_escaped_str(stmt, false); fputs("\", ", yyout); } /* dump variables to C file */ dump_variables(argsinsert, 1); fputs("ECPGt_EOIT, ", yyout); dump_variables(argsresult, 1); fputs("ECPGt_EORT);", yyout); reset_variables(); whenever_action(whenever_mode | 2); free(stmt); if (connection != NULL) free(connection); }
static void print_action | ( | struct when * | w | ) | [static] |
Definition at line 35 of file output.c.
References when::code, when::command, W_BREAK, W_DO, W_GOTO, W_SQLPRINT, W_STOP, and yyout.
Referenced by whenever_action().
{ switch (w->code) { case W_SQLPRINT: fprintf(yyout, "sqlprint();"); break; case W_GOTO: fprintf(yyout, "goto %s;", w->command); break; case W_DO: fprintf(yyout, "%s;", w->command); break; case W_STOP: fprintf(yyout, "exit (1);"); break; case W_BREAK: fprintf(yyout, "break;"); break; default: fprintf(yyout, "{/* %d not implemented yet */}", w->code); break; } }
void whenever_action | ( | int | mode | ) |
Definition at line 61 of file output.c.
References when::code, output_line_number(), print_action(), W_NOTHING, when_warn, and yyout.
Referenced by output_deallocate_prepare_statement(), output_get_descr(), output_get_descr_header(), output_prepare_statement(), output_set_descr(), output_set_descr_header(), and output_statement().
{ if ((mode & 1) == 1 && when_nf.code != W_NOTHING) { output_line_number(); fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) "); print_action(&when_nf); } if (when_warn.code != W_NOTHING) { output_line_number(); fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') "); print_action(&when_warn); } if (when_error.code != W_NOTHING) { output_line_number(); fprintf(yyout, "\nif (sqlca.sqlcode < 0) "); print_action(&when_error); } if ((mode & 2) == 2) fputc('}', yyout); output_line_number(); }
char* ecpg_statement_type_name[] [static] |
{ "ECPGst_normal", "ECPGst_execute", "ECPGst_exec_immediate", "ECPGst_prepnormal" }
Definition at line 108 of file output.c.
Referenced by output_statement().