Skip to content

Commit 466d61d

Browse files
committed
Fix regression in 2220edf (#9058)
1 parent 2220edf commit 466d61d

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

src/dsql/StmtNodes.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,15 +1806,13 @@ DmlNode* DeclareLocalTableNode::parse(thread_db* tdbb, MemoryPool& pool, Compile
18061806
node->format = Format::newFormat(pool, fieldCount);
18071807
node->format->fmt_length = FLAG_BYTES(fieldCount);
18081808
node->notNullFields.grow(fieldCount);
1809-
node->fieldNames.grow(fieldCount);
18101809

18111810
for (USHORT fieldNum = 0; fieldNum < fieldCount; ++fieldNum)
18121811
{
18131812
dsc& fmtDesc = node->format->fmt_desc[fieldNum];
18141813
ItemInfo itemInfo;
18151814
PAR_desc(tdbb, csb, &fmtDesc, &itemInfo);
18161815
node->notNullFields[fieldNum] = !itemInfo.nullable;
1817-
blrReader.getMetaName(node->fieldNames[fieldNum]);
18181816

18191817
if (fmtDesc.dsc_dtype >= dtype_aligned)
18201818
node->format->fmt_length = FB_ALIGN(node->format->fmt_length, type_alignments[fmtDesc.dsc_dtype]);
@@ -1825,11 +1823,31 @@ DmlNode* DeclareLocalTableNode::parse(thread_db* tdbb, MemoryPool& pool, Compile
18251823

18261824
break;
18271825

1826+
case blr_dcl_local_table_field_names:
1827+
{
1828+
if (node->fieldNames.hasData())
1829+
PAR_error(csb, Arg::Gds(isc_random) << "duplicate local table field names");
1830+
1831+
const USHORT nameCount = blrReader.getWord();
1832+
node->fieldNames.grow(nameCount);
1833+
1834+
for (USHORT fieldNum = 0; fieldNum < nameCount; ++fieldNum)
1835+
blrReader.getMetaName(node->fieldNames[fieldNum]);
1836+
1837+
break;
1838+
}
1839+
18281840
default:
18291841
PAR_error(csb, Arg::Gds(isc_random) << "Invalid blr_dcl_local_table sub code");
18301842
}
18311843
}
18321844

1845+
if (node->fieldNames.hasData() && node->fieldNames.getCount() != fieldCount)
1846+
{
1847+
PAR_error(csb, Arg::Gds(isc_random) <<
1848+
"Local table field names count does not match format field count");
1849+
}
1850+
18331851
if (fieldCount == 0)
18341852
PAR_error(csb, Arg::Gds(isc_random) << "Local table without fields");
18351853

@@ -1986,14 +2004,19 @@ void DeclareLocalTableNode::genBlr(DsqlCompilerScratch* dsqlScratch)
19862004
for (auto field = dsqlRelation->rel_fields; field; field = field->fld_next)
19872005
++fieldCount;
19882006

2007+
// Format layout: count + descriptors only.
19892008
dsqlScratch->appendUChar(blr_dcl_local_table_format);
19902009
dsqlScratch->appendUShort(fieldCount);
19912010

19922011
for (auto field = dsqlRelation->rel_fields; field; field = field->fld_next)
1993-
{
19942012
dsqlScratch->putType(field, true);
2013+
2014+
// Field names are optional and use a separate subcode.
2015+
dsqlScratch->appendUChar(blr_dcl_local_table_field_names);
2016+
dsqlScratch->appendUShort(fieldCount);
2017+
2018+
for (auto field = dsqlRelation->rel_fields; field; field = field->fld_next)
19952019
dsqlScratch->appendNullString(field->fld_name.c_str());
1996-
}
19972020

19982021
dsqlScratch->appendUChar(blr_end);
19992022
}
@@ -2114,7 +2137,12 @@ jrd_rel* DeclareLocalTableNode::getRelation(thread_db* tdbb, Request* request) c
21142137

21152138
auto& field = (*newRelation->rel_fields)[i];
21162139
field = FB_NEW_POOL(pool) jrd_fld(pool);
2117-
field->fld_name.printf("FIELD_%" SIZEFORMAT, i + 1);
2140+
2141+
if (i < fieldNames.getCount() && fieldNames[i].hasData())
2142+
field->fld_name = fieldNames[i];
2143+
else
2144+
field->fld_name.printf("FIELD_%" SIZEFORMAT, i + 1);
2145+
21182146
field->fld_length = relFormat->fmt_desc[i].dsc_length;
21192147
field->fld_pos = i;
21202148
field->fld_flags = notNullFields[i] ? FLD_not_null : 0;

src/include/firebird/impl/blr.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@
461461
#define blr_dcl_local_table (unsigned char) 218
462462

463463
// subcodes of blr_dcl_local_table
464-
#define blr_dcl_local_table_format (unsigned char) 1
465-
#define blr_dcl_local_table_ltt (unsigned char) 2
464+
#define blr_dcl_local_table_format (unsigned char) 1
465+
#define blr_dcl_local_table_ltt (unsigned char) 2
466+
#define blr_dcl_local_table_field_names (unsigned char) 3
466467

467468
#define blr_local_table_truncate (unsigned char) 219
468469
#define blr_local_table_id (unsigned char) 220

src/yvalve/gds.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,8 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
40344034
{
40354035
nullptr,
40364036
"format",
4037-
"ltt"
4037+
"ltt",
4038+
"field_names"
40384039
};
40394040

40404041
while ((blr_operator = control->ctl_blr_reader.getByte()) != blr_end)
@@ -4067,6 +4068,21 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
40674068
--level;
40684069
break;
40694070

4071+
case blr_dcl_local_table_field_names:
4072+
n = blr_print_word(control);
4073+
offset = blr_print_line(control, offset);
4074+
++level;
4075+
4076+
while (--n >= 0)
4077+
{
4078+
blr_indent(control, level);
4079+
blr_print_name(control);
4080+
offset = blr_print_line(control, offset);
4081+
}
4082+
4083+
--level;
4084+
break;
4085+
40704086
default:
40714087
fb_assert(false);
40724088
}

0 commit comments

Comments
 (0)