[Bug fix] ECPG: ECPG preprocessor outputs "unsupported feature will be passed to server" even if the command is supported
Hi,
I found wrong message output when ECPG preprocessed some SQL commands .
For example, ECPG application has following command, ECPG outputs "unsupported feature will be passed to server".
-----------
EXEC SQL CREATE SCHEMA IF NOT EXISTS hollywood;
-----------
I attached sample code to reproduce this problem.
[Investigation]
I think parse.pl has some problem. The following filters do not seem to work properly:
src/interfaces/ecpg/preproc/parse.pl
if ($feature_not_supported == 1)
{
# we found an unsupported feature, but we have to
# filter out ExecuteStmt: CREATE OptTemp TABLE ...
# because the warning there is only valid in some situations
if ($flds->[0] ne 'create' || $flds->[2] ne 'table')
{
add_to_buffer('rules',
'mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server");' );
}
$feature_not_supported = 0;
}
[Solution]
I have two solutions for this.
1) This problem occurs because filter does not work properly.
So, by setting the filter conditions properly, wrong warning should not be output.
However, we have to modify the conditions when the syntax in gram.y is changed.
2) This problem occurs when a syntax is not supported under certain conditions like following:
So, when "if sentence" is found inside rule, the warning should not be output.
CreateSchemaStmt:
| CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleSpec OptSchemaEltList
{
CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
if ($9 != NIL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
parser_errposition(@9)));
I attached a draft patch of the solution 2).
Regards,
Daisuke, Higuchi
Attachments:
ECPG_unsupported_messages_fix_v1.patchapplication/octet-stream; name=ECPG_unsupported_messages_fix_v1.patchDownload
diff --git a/src/interfaces/ecpg/preproc/parse.pl b/src/interfaces/ecpg/preproc/parse.pl
index 3619706..791e7a7 100644
--- a/src/interfaces/ecpg/preproc/parse.pl
+++ b/src/interfaces/ecpg/preproc/parse.pl
@@ -26,6 +26,7 @@ my $in_rule = 0;
my $header_included = 0;
my $feature_not_supported = 0;
my $tokenmode = 0;
+my $has_condition = 0;
my (%buff, $infield, $comment, %tokens, %addons);
my ($stmt_mode, @fields);
@@ -130,9 +131,20 @@ sub main
{
line: while (<>)
{
+ # Even if ERRCODE_FEATURE_NOT_SUPPORTED is found inside a rule,
+ # its syntax may be supported in some situations.
+ # Therefore, the warning about unsupported feature is output
+ # only when no condition is specified inside the same rule.
+ if(/if \(/)
+ {
+ $has_condition = 1;
+ }
if (/ERRCODE_FEATURE_NOT_SUPPORTED/)
{
- $feature_not_supported = 1;
+ if ($has_condition ne 1)
+ {
+ $feature_not_supported = 1;
+ }
next line;
}
@@ -508,18 +520,12 @@ sub dump_fields
add_to_buffer('rules', $ln);
if ($feature_not_supported == 1)
{
-
- # we found an unsupported feature, but we have to
- # filter out ExecuteStmt: CREATE OptTemp TABLE ...
- # because the warning there is only valid in some situations
- if ($flds->[0] ne 'create' || $flds->[2] ne 'table')
- {
- add_to_buffer('rules',
- 'mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server");'
- );
- }
+ add_to_buffer('rules',
+ 'mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server");'
+ );
$feature_not_supported = 0;
}
+ $has_condition = 0;
if ($len == 0)
{