Dictionary dictionary = new Dictionary();
DictTable dictTable;
DictField dictField;
TableId tableId,tableIdbuffer,NewtableId;
FieldId fieldId,fieldIdbuffer,newfieldId,fieldIdmin,fieldIdmax;
SqlDictionary sqlDictionaryTable;
SqlDictionary sqlDictionaryField;
SqlDictionary SqlDictionaryupdate,SqlDictionaryupdaterecordset;
PS_Table PS_Table;
int i;
setPrefix("Update of data dictionary IDs");
tableId = dictionary.tableNext(0);
ttsbegin;
select maxof(tabid) from SqlDictionaryupdate;
tableIdbuffer = SqlDictionaryupdate.tabId + 1000;
ttsBegin;
delete_from PS_Table;
ttsCommit;
while (tableId > 0)
{
dictTable = new SysDictTable(tableId);
setPrefix(dictTable.name());
if (!dictTable.isSystemTable())
{
//Finds table in SqlDictionary by name in AOT, if ID was changed.
//Empty field ID represents a table.
select sqlDictionaryTable
where sqlDictionaryTable.name == dictTable.name()
&& sqlDictionaryTable.fieldId == 0
&& sqlDictionaryTable.tabId != dictTable.id();
if (sqlDictionaryTable)
{
//Updates table ID in SqlDictionary
NewtableId = dictTable.id();
select * from SqlDictionaryupdate
where SqlDictionaryupdate.tabId == NewtableId;
if(SqlDictionaryupdate)
{
update_recordset SqlDictionaryupdaterecordset
setting TabId = tableIdbuffer
where SqlDictionaryupdaterecordset.TabId == SqlDictionaryupdate.tabId;
tableIdbuffer--;
}
if (ReleaseUpdateDB::changeTableId(
sqlDictionaryTable.tabId,
dictTable.id(),
dictTable.name()))
{
info(strFmt("Table ID changed (%1 -> %2)", sqlDictionaryTable.tabId, dictTable.id()));
}
}
fieldId = dictTable.fieldNext(0);
select maxof(fieldId) from SqlDictionaryupdate;
fieldIdbuffer = SqlDictionaryupdate.fieldId + 1000;
select minOf(fieldId) from SqlDictionaryupdate;
fieldIdmin = SqlDictionaryupdate.fieldId;
//For all fields in table
while (fieldId)
{
info(strFmt("%1",fieldId));
dictField = dictTable.fieldObject(fieldId);
// info(dictField.name());
if (dictField.isSql() && !dictField.isSystem())
{
//Finds fields in SqlDictionary by name and compares IDs
select sqlDictionaryField
where sqlDictionaryField.tabId == dictTable.id()
&& sqlDictionaryField.name == dictField.name()
&& sqlDictionaryField.fieldId != 0
&& sqlDictionaryField.fieldId != dictField.id();
if (sqlDictionaryField)
{
Newfieldid = dictField.id();
NewtableId = dictTable.id();
ttsBegin;
PS_Table.TabId = NewtableId;
PS_Table.Tablename = dictTable.name();
PS_Table.FieldName = dictField.name();
PS_Table.FieldId = Newfieldid;
PS_Table.insert();
ttsCommit;
select * from SqlDictionaryupdate
where SqlDictionaryupdate.tabId == NewtableId
&& SqlDictionaryupdate.fieldId == Newfieldid;
if(SqlDictionaryupdate)
{
update_recordset SqlDictionaryupdaterecordset
setting FieldId = fieldIdbuffer
where SqlDictionaryupdaterecordset.TabId == NewtableId
&& SqlDictionaryupdaterecordset.FieldId == Newfieldid;
fieldIdbuffer--;
}
//Updates field ID in SqlDictionary
if (ReleaseUpdateDB::changeFieldId(
dictTable.id(),
sqlDictionaryField.fieldId,
dictField.id(),
dictTable.name(),
dictField.name()))
{
info(strFmt("Field %1 - ID changed (%2 -> %3)",
dictField.name(),
sqlDictionaryField.fieldId,
dictField.id()));
}
}
}
fieldId = dictTable.fieldNext(fieldId);
}
}
tableId = dictionary.tableNext(tableId);
}
ttscommit;
DictTable dictTable;
DictField dictField;
TableId tableId,tableIdbuffer,NewtableId;
FieldId fieldId,fieldIdbuffer,newfieldId,fieldIdmin,fieldIdmax;
SqlDictionary sqlDictionaryTable;
SqlDictionary sqlDictionaryField;
SqlDictionary SqlDictionaryupdate,SqlDictionaryupdaterecordset;
PS_Table PS_Table;
int i;
setPrefix("Update of data dictionary IDs");
tableId = dictionary.tableNext(0);
ttsbegin;
select maxof(tabid) from SqlDictionaryupdate;
tableIdbuffer = SqlDictionaryupdate.tabId + 1000;
ttsBegin;
delete_from PS_Table;
ttsCommit;
while (tableId > 0)
{
dictTable = new SysDictTable(tableId);
setPrefix(dictTable.name());
if (!dictTable.isSystemTable())
{
//Finds table in SqlDictionary by name in AOT, if ID was changed.
//Empty field ID represents a table.
select sqlDictionaryTable
where sqlDictionaryTable.name == dictTable.name()
&& sqlDictionaryTable.fieldId == 0
&& sqlDictionaryTable.tabId != dictTable.id();
if (sqlDictionaryTable)
{
//Updates table ID in SqlDictionary
NewtableId = dictTable.id();
select * from SqlDictionaryupdate
where SqlDictionaryupdate.tabId == NewtableId;
if(SqlDictionaryupdate)
{
update_recordset SqlDictionaryupdaterecordset
setting TabId = tableIdbuffer
where SqlDictionaryupdaterecordset.TabId == SqlDictionaryupdate.tabId;
tableIdbuffer--;
}
if (ReleaseUpdateDB::changeTableId(
sqlDictionaryTable.tabId,
dictTable.id(),
dictTable.name()))
{
info(strFmt("Table ID changed (%1 -> %2)", sqlDictionaryTable.tabId, dictTable.id()));
}
}
fieldId = dictTable.fieldNext(0);
select maxof(fieldId) from SqlDictionaryupdate;
fieldIdbuffer = SqlDictionaryupdate.fieldId + 1000;
select minOf(fieldId) from SqlDictionaryupdate;
fieldIdmin = SqlDictionaryupdate.fieldId;
//For all fields in table
while (fieldId)
{
info(strFmt("%1",fieldId));
dictField = dictTable.fieldObject(fieldId);
// info(dictField.name());
if (dictField.isSql() && !dictField.isSystem())
{
//Finds fields in SqlDictionary by name and compares IDs
select sqlDictionaryField
where sqlDictionaryField.tabId == dictTable.id()
&& sqlDictionaryField.name == dictField.name()
&& sqlDictionaryField.fieldId != 0
&& sqlDictionaryField.fieldId != dictField.id();
if (sqlDictionaryField)
{
Newfieldid = dictField.id();
NewtableId = dictTable.id();
ttsBegin;
PS_Table.TabId = NewtableId;
PS_Table.Tablename = dictTable.name();
PS_Table.FieldName = dictField.name();
PS_Table.FieldId = Newfieldid;
PS_Table.insert();
ttsCommit;
select * from SqlDictionaryupdate
where SqlDictionaryupdate.tabId == NewtableId
&& SqlDictionaryupdate.fieldId == Newfieldid;
if(SqlDictionaryupdate)
{
update_recordset SqlDictionaryupdaterecordset
setting FieldId = fieldIdbuffer
where SqlDictionaryupdaterecordset.TabId == NewtableId
&& SqlDictionaryupdaterecordset.FieldId == Newfieldid;
fieldIdbuffer--;
}
//Updates field ID in SqlDictionary
if (ReleaseUpdateDB::changeFieldId(
dictTable.id(),
sqlDictionaryField.fieldId,
dictField.id(),
dictTable.name(),
dictField.name()))
{
info(strFmt("Field %1 - ID changed (%2 -> %3)",
dictField.name(),
sqlDictionaryField.fieldId,
dictField.id()));
}
}
}
fieldId = dictTable.fieldNext(fieldId);
}
}
tableId = dictionary.tableNext(tableId);
}
ttscommit;
No comments:
Post a Comment