Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit399edaf

Browse files
author
Michael Meskes
committed
Fix connection handling for DEALLOCATE and DESCRIBE statements
After binding a statement to a connection with DECLARE STATEMENT the connectionwas still not used for DEALLOCATE and DESCRIBE statements. This patch fixesthat, adds a missing warning and cleans up the code.Author: Hayato KurodaReviewed-by: Kyotaro Horiguchi, Michael PaquierDiscussion:https://postgr.es/m/TYAPR01MB5866BA57688DF2770E2F95C6F5069%40TYAPR01MB5866.jpnprd01.prod.outlook.com
1 parent512f4ca commit399edaf

File tree

11 files changed

+258
-75
lines changed

11 files changed

+258
-75
lines changed

‎src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ drop_descriptor(char *name, char *connection)
121121
}
122122
}
123123
}
124-
mmerror(PARSE_ERROR,ET_WARNING,"descriptor \"%s\" does not exist",name);
124+
if (connection)
125+
mmerror(PARSE_ERROR,ET_WARNING,"descriptor %s bound to connection %s does not exist",name,connection);
126+
else
127+
mmerror(PARSE_ERROR,ET_WARNING,"descriptor %s bound to the default connection does not exist",name);
125128
}
126129

127130
structdescriptor
@@ -141,9 +144,18 @@ lookup_descriptor(char *name, char *connection)
141144
|| (connection&&i->connection
142145
&&strcmp(connection,i->connection)==0))
143146
returni;
147+
if (connection&& !i->connection)
148+
{
149+
/* overwrite descriptor's connection */
150+
i->connection=mm_strdup(connection);
151+
returni;
152+
}
144153
}
145154
}
146-
mmerror(PARSE_ERROR,ET_WARNING,"descriptor \"%s\" does not exist",name);
155+
if (connection)
156+
mmerror(PARSE_ERROR,ET_WARNING,"descriptor %s bound to connection %s does not exist",name,connection);
157+
else
158+
mmerror(PARSE_ERROR,ET_WARNING,"descriptor %s bound to the default connection does not exist",name);
147159
returnNULL;
148160
}
149161

‎src/interfaces/ecpg/preproc/ecpg.addons

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ ECPG: stmtViewStmt rule
132132
}
133133
| ECPGDescribe
134134
{
135-
fprintf(base_yyout, "{ ECPGdescribe(__LINE__, %d, %s,", compat, $1);
135+
check_declared_list($1.stmt_name);
136+
137+
fprintf(base_yyout, "{ ECPGdescribe(__LINE__, %d, %d, %s, %s,", compat, $1.input, connection ? connection : "NULL", $1.stmt_name);
136138
dump_variables(argsresult, 1);
137139
fputs("ECPGt_EORT);", base_yyout);
138140
fprintf(base_yyout, "}");
139141
output_line_number();
140142

141-
free($1);
143+
free($1.stmt_name);
142144
}
143145
| ECPGDisconnect
144146
{
@@ -397,7 +399,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
397399
this->next = cur;
398400
this->name = $2;
399401
this->function = (current_function ? mm_strdup(current_function) : NULL);
400-
this->connection = connection;
402+
this->connection = connection ? mm_strdup(connection) : NULL;
401403
this->opened = false;
402404
this->command = cat_str(7, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for"), $7);
403405
this->argsinsert = argsinsert;

‎src/interfaces/ecpg/preproc/ecpg.header

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,14 @@ check_declared_list(const char *name)
590590
struct declared_list *ptr = NULL;
591591
for (ptr = g_declared_list; ptr != NULL; ptr = ptr -> next)
592592
{
593+
if (!ptr->connection)
594+
continue;
593595
if (strcmp(name, ptr -> name) == 0)
594596
{
595-
if (ptr -> connection)
596-
{
597-
connection = mm_strdup(ptr -> connection);
598-
return true;
599-
}
597+
if (connection)
598+
mmerror(PARSE_ERROR, ET_WARNING, "connection %s is overwritten to %s.", connection, ptr->connection);
599+
connection = mm_strdup(ptr -> connection);
600+
return true;
600601
}
601602
}
602603
return false;
@@ -621,4 +622,5 @@ check_declared_list(const char *name)
621622
struct su_symbolstruct_union;
622623
structprepprep;
623624
structexecexec;
625+
struct describedescribe;
624626
}

‎src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ statements: /*EMPTY*/
44
| statements statement
55
;
66

7-
statement: ecpgstart at toplevel_stmt ';' { connection = NULL; }
7+
statement: ecpgstart at toplevel_stmt ';'
8+
{
9+
if (connection)
10+
free(connection);
11+
connection = NULL;
12+
}
813
| ecpgstart toplevel_stmt ';'
14+
{
15+
if (connection)
16+
free(connection);
17+
connection = NULL;
18+
}
919
| ecpgstart ECPGVarDeclaration
1020
{
1121
fprintf(base_yyout, "%s", $2);
@@ -1101,41 +1111,33 @@ UsingConst: Iconst{ $$ = $1; }
11011111
*/
11021112
ECPGDescribe: SQL_DESCRIBE INPUT_P prepared_name using_descriptor
11031113
{
1104-
const char *con = connection ? connection : "NULL";
1105-
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported DESCRIBE statement");
1106-
$$ = (char *) mm_alloc(sizeof("1, , ") + strlen(con) + strlen($3));
1107-
sprintf($$, "1, %s, %s", con, $3);
1114+
$$.input = 1;
1115+
$$.stmt_name = $3;
11081116
}
11091117
| SQL_DESCRIBE opt_output prepared_name using_descriptor
11101118
{
1111-
const char *con = connection ? connection : "NULL";
11121119
struct variable *var;
1113-
11141120
var = argsinsert->variable;
11151121
remove_variable_from_list(&argsinsert, var);
11161122
add_variable_to_head(&argsresult, var, &no_indicator);
11171123

1118-
$$ =(char *) mm_alloc(sizeof("0, , ") + strlen(con) + strlen($3));
1119-
sprintf($$, "0, %s, %s", con, $3);
1124+
$$.input =0;
1125+
$$.stmt_name = $3;
11201126
}
11211127
| SQL_DESCRIBE opt_output prepared_name into_descriptor
11221128
{
1123-
const char *con = connection ? connection : "NULL";
1124-
$$ = (char *) mm_alloc(sizeof("0, , ") + strlen(con) + strlen($3));
1125-
sprintf($$, "0, %s, %s", con, $3);
1129+
$$.input = 0;
1130+
$$.stmt_name = $3;
11261131
}
11271132
| SQL_DESCRIBE INPUT_P prepared_name into_sqlda
11281133
{
1129-
const char *con = connection ? connection : "NULL";
1130-
mmerror(PARSE_ERROR, ET_WARNING, "using unsupported DESCRIBE statement");
1131-
$$ = (char *) mm_alloc(sizeof("1, , ") + strlen(con) + strlen($3));
1132-
sprintf($$, "1, %s, %s", con, $3);
1134+
$$.input = 1;
1135+
$$.stmt_name = $3;
11331136
}
11341137
| SQL_DESCRIBE opt_output prepared_name into_sqlda
11351138
{
1136-
const char *con = connection ? connection : "NULL";
1137-
$$ = (char *) mm_alloc(sizeof("0, , ") + strlen(con) + strlen($3));
1138-
sprintf($$, "0, %s, %s", con, $3);
1139+
$$.input = 0;
1140+
$$.stmt_name = $3;
11391141
}
11401142
;
11411143

@@ -1862,8 +1864,8 @@ c_anything: ecpg_ident{ $$ = $1; }
18621864
| ':'{ $$ = mm_strdup(":"); }
18631865
;
18641866

1865-
DeallocateStmt: DEALLOCATE prepared_name{ $$ = $2; }
1866-
| DEALLOCATE PREPARE prepared_name{ $$ = $3; }
1867+
DeallocateStmt: DEALLOCATE prepared_name{check_declared_list($2);$$ = $2; }
1868+
| DEALLOCATE PREPARE prepared_name{check_declared_list($3);$$ = $3; }
18671869
| DEALLOCATE ALL{ $$ = mm_strdup("all"); }
18681870
| DEALLOCATE PREPARE ALL{ $$ = mm_strdup("all"); }
18691871
;

‎src/interfaces/ecpg/preproc/ecpg.type

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
%type <str> ECPGDeclaration
1111
%type <str> ECPGDeclare
1212
%type <str> ECPGDeclareStmt
13-
%type <str> ECPGDescribe
1413
%type <str> ECPGDisconnect
1514
%type <str> ECPGExecuteImmediateStmt
1615
%type <str> ECPGFree
@@ -143,3 +142,5 @@
143142
%type <type> var_type
144143

145144
%type <action> action
145+
146+
%type <describe> ECPGDescribe

‎src/interfaces/ecpg/preproc/output.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
164164

165165
whenever_action(whenever_mode |2);
166166
free(stmt);
167-
if (connection!=NULL)
168-
free(connection);
169-
connection=NULL;
170167
}
171168

172169
void
@@ -179,9 +176,6 @@ output_prepare_statement(char *name, char *stmt)
179176
fputs(");",base_yyout);
180177
whenever_action(2);
181178
free(name);
182-
if (connection!=NULL)
183-
free(connection);
184-
connection=NULL;
185179
}
186180

187181
void
@@ -200,9 +194,6 @@ output_deallocate_prepare_statement(char *name)
200194

201195
whenever_action(2);
202196
free(name);
203-
if (connection!=NULL)
204-
free(connection);
205-
connection=NULL;
206197
}
207198

208199
staticvoid

‎src/interfaces/ecpg/preproc/type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,10 @@ struct fetch_desc
207207
char*name;
208208
};
209209

210+
structdescribe
211+
{
212+
intinput;
213+
char*stmt_name;
214+
};
215+
210216
#endif/* _ECPG_PREPROC_TYPE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp