Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 096a761

Browse files
committed
Fix ecpg's mechanism for detecting unsupported cases in the grammar.
ecpg wants to emit a warning if it parses a SQL construct that the backend can parse but will immediately throw a FEATURE_NOT_SUPPORTED error for. The way it was testing for this was to see if the string ERRCODE_FEATURE_NOT_SUPPORTED appeared anywhere in the gram.y code. This is, of course, not nearly good enough, as there are plenty of rules in gram.y that throw that error only conditionally. There was a hack dating to 2008 to suppress the warning in one rule that doesn't even exist anymore, but nothing for other cases we've created since then. End result was that you could get "unsupported feature will be passed to server" warnings while compiling perfectly good SQL code in ecpg. Somehow we'd not heard complaints about this, but it was exposed by the recent addition of an ecpg test for a SQL/JSON construct. To fix, suppress the warning if the rule contains any "if" statement. Manual comparison of gram.y with the generated preproc.y file shows that the warning is now emitted only in rules where it's sensible. This problem has existed for a long time, so back-patch to all supported branches. Discussion: https://postgr.es/m/603615.1712245382@sss.pgh.pa.us
1 parent 332d406 commit 096a761

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/interfaces/ecpg/preproc/parse.pl

+18-19
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
my $yaccmode = 0;
3535
my $in_rule = 0;
3636
my $header_included = 0;
37-
my $feature_not_supported = 0;
37+
my $has_feature_not_supported = 0;
38+
my $has_if_command = 0;
3839
my $tokenmode = 0;
3940

4041
my (%buff, $infield, $comment, %tokens, %addons);
@@ -151,12 +152,6 @@ sub main
151152
{
152153
line: while (<$parserfh>)
153154
{
154-
if (/ERRCODE_FEATURE_NOT_SUPPORTED/)
155-
{
156-
$feature_not_supported = 1;
157-
next line;
158-
}
159-
160155
chomp;
161156

162157
# comment out the line below to make the result file match (blank line wise)
@@ -182,6 +177,13 @@ sub main
182177
$infield = 0;
183178
}
184179

180+
if ($yaccmode == 1)
181+
{
182+
# Check for rules that throw FEATURE_NOT_SUPPORTED
183+
$has_feature_not_supported = 1 if /ERRCODE_FEATURE_NOT_SUPPORTED/;
184+
$has_if_command = 1 if /^\s*if/;
185+
}
186+
185187
my $prec = 0;
186188

187189
# Make sure any braces are split
@@ -541,20 +543,17 @@ sub dump_fields
541543

542544
#Normal
543545
add_to_buffer('rules', $ln);
544-
if ($feature_not_supported == 1)
546+
if ($has_feature_not_supported and not $has_if_command)
545547
{
546-
547-
# we found an unsupported feature, but we have to
548-
# filter out ExecuteStmt: CREATE OptTemp TABLE ...
549-
# because the warning there is only valid in some situations
550-
if ($flds->[0] ne 'create' || $flds->[2] ne 'table')
551-
{
552-
add_to_buffer('rules',
553-
'mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server");'
554-
);
555-
}
556-
$feature_not_supported = 0;
548+
# The backend unconditionally reports
549+
# FEATURE_NOT_SUPPORTED in this rule, so let's emit
550+
# a warning on the ecpg side.
551+
add_to_buffer('rules',
552+
'mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server");'
553+
);
557554
}
555+
$has_feature_not_supported = 0;
556+
$has_if_command = 0;
558557

559558
if ($len == 0)
560559
{

0 commit comments

Comments
 (0)