8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 01:23:03 +01:00

Fixed CORE-2932 - Wrong field position after ALTER POSITION

This commit is contained in:
asfernandes 2010-03-22 01:09:28 +00:00
parent efcf286bf3
commit a1d62c190c

View File

@ -1644,6 +1644,29 @@ static void modify_lfield_position(thread_db* tdbb,
try {
// Make sure that there are no duplicate field positions and no gaps in the position sequence.
// (gaps are introduced when fields are removed)
USHORT new_pos = 0;
FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
FLD IN RDB$RELATION_FIELDS
WITH FLD.RDB$RELATION_NAME EQ relation_name.c_str()
SORTED BY ASCENDING FLD.RDB$FIELD_POSITION
if (FLD.RDB$FIELD_POSITION != new_pos)
{
MODIFY FLD USING
FLD.RDB$FIELD_POSITION = new_pos;
END_MODIFY;
}
++new_pos;
END_FOR;
CMP_release(tdbb, request);
request = NULL;
// Find the position of the last field in the relation
SLONG max_position = -1;
DYN_UTIL_generate_field_position(tdbb, gbl, relation_name, &max_position);
@ -1689,27 +1712,6 @@ static void modify_lfield_position(thread_db* tdbb,
END_MODIFY;
END_FOR;
CMP_release(tdbb, request);
request = NULL;
// Once the field position has been changed, make sure that there are no
// duplicate field positions and no gaps in the position sequence (this can
// not be guaranteed by the query above
USHORT new_pos = 0;
FOR(REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
FLD IN RDB$RELATION_FIELDS WITH FLD.RDB$RELATION_NAME EQ relation_name.c_str()
SORTED BY ASCENDING FLD.RDB$FIELD_POSITION
if (FLD.RDB$FIELD_POSITION != new_pos)
{
MODIFY FLD USING
FLD.RDB$FIELD_POSITION = new_pos;
END_MODIFY;
}
new_pos += 1;
END_FOR;
CMP_release(tdbb, request);
}
catch (const Exception& ex)