mirror of
https://github.com/postgres/postgres.git
synced 2025-06-20 15:22:23 +03:00
Throw an error if a DATA() line contains wrong # of attributes.
David Christensen, reviewed by Dagfinn Ilmari Mannsåker Discussion: http://postgr.es/m/20170215154018.fs5vwtqhp5d2sifs@veeddeux.attlocal.net
This commit is contained in:
@ -46,6 +46,9 @@ sub Catalogs
|
|||||||
|
|
||||||
open(INPUT_FILE, '<', $input_file) || die "$input_file: $!";
|
open(INPUT_FILE, '<', $input_file) || die "$input_file: $!";
|
||||||
|
|
||||||
|
my ($filename) = ($input_file =~ m/(\w+)\.h$/);
|
||||||
|
my $natts_pat = "Natts_$filename";
|
||||||
|
|
||||||
# Scan the input file.
|
# Scan the input file.
|
||||||
while (<INPUT_FILE>)
|
while (<INPUT_FILE>)
|
||||||
{
|
{
|
||||||
@ -70,8 +73,15 @@ sub Catalogs
|
|||||||
s/\s+/ /g;
|
s/\s+/ /g;
|
||||||
|
|
||||||
# Push the data into the appropriate data structure.
|
# Push the data into the appropriate data structure.
|
||||||
if (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/)
|
if (/$natts_pat\s+(\d+)/)
|
||||||
{
|
{
|
||||||
|
$catalog{natts} = $1;
|
||||||
|
}
|
||||||
|
elsif (/^DATA\(insert(\s+OID\s+=\s+(\d+))?\s+\(\s*(.*)\s*\)\s*\)$/)
|
||||||
|
{
|
||||||
|
check_natts($filename, $catalog{natts}, $3,
|
||||||
|
$input_file, INPUT_FILE->input_line_number);
|
||||||
|
|
||||||
push @{ $catalog{data} }, { oid => $2, bki_values => $3 };
|
push @{ $catalog{data} }, { oid => $2, bki_values => $3 };
|
||||||
}
|
}
|
||||||
elsif (/^DESCR\(\"(.*)\"\)$/)
|
elsif (/^DESCR\(\"(.*)\"\)$/)
|
||||||
@ -216,4 +226,20 @@ sub RenameTempFile
|
|||||||
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
|
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# verify the number of fields in the passed-in bki structure
|
||||||
|
sub check_natts
|
||||||
|
{
|
||||||
|
my ($catname, $natts, $bki_val, $file, $line) = @_;
|
||||||
|
die "Could not find definition for Natts_${catname} before start of DATA() in $file\n"
|
||||||
|
unless defined $natts;
|
||||||
|
|
||||||
|
# we're working with a copy and need to count the fields only, so collapse
|
||||||
|
$bki_val =~ s/"[^"]*?"/xxx/g;
|
||||||
|
my @atts = split /\s+/, $bki_val;
|
||||||
|
|
||||||
|
die sprintf
|
||||||
|
"Wrong number of attributes in DATA() entry at %s:%d (expected %d but got %d)\n",
|
||||||
|
$file, $line, $natts, scalar @atts
|
||||||
|
unless $natts == @atts;
|
||||||
|
}
|
||||||
1;
|
1;
|
||||||
|
Reference in New Issue
Block a user