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

Commit49c784e

Browse files
committed
Remove hard-coded schema knowledge about pg_attribute from genbki.pl
Add the ability to label a column's default value in the catalog header,and implement this for pg_attribute. A new function in Catalog.pm isused to fill in a tuple with defaults. The build process will complainloudly if a catalog entry is incomplete,Commit8137f2c labeled variable length columns for the C preprocessor.Expose that label to genbki.pl so we can exclude those columns from schemamacros in a general fashion. Also, format schema macro entries accordingto their types.This means slightly less code maintenance, but more importantly it's aproving ground for mechanisms intended to be used in later commits.While at it, I (Álvaro) couldn't resist making some changes ingenbki.pl: rename some functions to actually indicate their purposeinstead of actively misleading onlookers; and don't iterate on the wholeof pg_type to find the entry for each catalog row, using a hash insteadof an array.Author: John Naylor, some changes by Álvaro HerreraDiscussion:https://postgr.es/m/CAJVSVGVJHwD8sfDfZW9TbCHWKf=C1YDRM-rF=2JenRU_y+VcFg@mail.gmail.com
1 parentbdb70c1 commit49c784e

File tree

4 files changed

+187
-136
lines changed

4 files changed

+187
-136
lines changed

‎src/backend/catalog/Catalog.pm

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ sub Catalogs
3737
foreachmy$input_file (@_)
3838
{
3939
my%catalog;
40+
my$is_varlen = 0;
41+
4042
$catalog{columns} = [];
4143
$catalog{data} = [];
4244

@@ -164,30 +166,39 @@ sub Catalogs
164166
elsif ($declaring_attributes)
165167
{
166168
nextif (/^{|^$/);
167-
nextif (/^#/);
169+
if (/^#/)
170+
{
171+
$is_varlen = 1if/^#ifdef\s+CATALOG_VARLEN/;
172+
next;
173+
}
168174
if (/^}/)
169175
{
170176
undef$declaring_attributes;
171177
}
172178
else
173179
{
174180
my%column;
175-
my ($atttype,$attname,$attopt) =split /\s+/,$_;
176-
die"parse error ($input_file)"unless$attname;
181+
my@attopts =split /\s+/,$_;
182+
my$atttype =shift@attopts;
183+
my$attname =shift@attopts;
184+
die"parse error ($input_file)"
185+
unless ($attnameand$atttype);
186+
177187
if (exists$RENAME_ATTTYPE{$atttype})
178188
{
179189
$atttype =$RENAME_ATTTYPE{$atttype};
180190
}
181191
if ($attname =~/(.*)\[.*\]/)# array attribute
182192
{
183193
$attname =$1;
184-
$atttype .='[]';# variable-length only
194+
$atttype .='[]';
185195
}
186196

187197
$column{type} =$atttype;
188198
$column{name} =$attname;
199+
$column{is_varlen} = 1if$is_varlen;
189200

190-
if (defined$attopt)
201+
foreachmy$attopt (@attopts)
191202
{
192203
if ($attopteq'BKI_FORCE_NULL')
193204
{
@@ -197,11 +208,20 @@ sub Catalogs
197208
{
198209
$column{forcenotnull} = 1;
199210
}
211+
elsif ($attopt =~/BKI_DEFAULT\((\S+)\)/)
212+
{
213+
$column{default} =$1;
214+
}
200215
else
201216
{
202217
die
203218
"unknown column option$attopt on column$attname";
204219
}
220+
221+
if ($column{forcenull}and$column{forcenotnull})
222+
{
223+
die"$attname is forced both null and not null";
224+
}
205225
}
206226
push @{$catalog{columns} }, \%column;
207227
}
@@ -235,6 +255,46 @@ sub SplitDataLine
235255
return@result;
236256
}
237257

258+
# Fill in default values of a record using the given schema. It's the
259+
# caller's responsibility to specify other values beforehand.
260+
subAddDefaultValues
261+
{
262+
my ($row,$schema) =@_;
263+
my@missing_fields;
264+
my$msg;
265+
266+
foreachmy$column (@$schema)
267+
{
268+
my$attname =$column->{name};
269+
my$atttype =$column->{type};
270+
271+
if (defined$row->{$attname})
272+
{
273+
;
274+
}
275+
elsif (defined$column->{default})
276+
{
277+
$row->{$attname} =$column->{default};
278+
}
279+
else
280+
{
281+
# Failed to find a value.
282+
push@missing_fields,$attname;
283+
}
284+
}
285+
286+
if (@missing_fields)
287+
{
288+
$msg ="Missing values for:" .join(',',@missing_fields);
289+
$msg .="\nShowing other values for context:\n";
290+
while (my($key,$value) =each%$row)
291+
{
292+
$msg .="$key =>$value,";
293+
}
294+
}
295+
return$msg;
296+
}
297+
238298
# Rename temporary files to final names.
239299
# Call this function with the final file name and the .tmp extension
240300
# Note: recommended extension is ".tmp$$", so that parallel make steps

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp