/// <summary> /// create code for a table that is part of a dataset /// </summary> /// <param name="ATables"></param> /// <param name="ASqltable"></param> /// <param name="tabletype"></param> /// <param name="variablename"></param> /// <param name="snippetDataset"></param> /// <param name="ASnippetSubmitChanges"></param> private static void AddTableToDataset( List <TDataSetTable> ATables, TTable ASqltable, string tabletype, string variablename, ProcessTemplate snippetDataset, ProcessTemplate ASnippetSubmitChanges) { ProcessTemplate tempSnippet; if (ASqltable != null) { string SequenceColumn = ""; string SequenceName = ""; foreach (TTableField tablefield in ASqltable.grpTableField) { // is there a field filled by a sequence? // yes: get the next value of that sequence and assign to row if (tablefield.strSequence.Length > 0) { SequenceName = tablefield.strSequence; SequenceColumn = tablefield.strName; // assume only one sequence per table break; } } tempSnippet = snippetDataset.GetSnippet("SUBMITCHANGES"); tempSnippet.SetCodelet("ORIGTABLENAME", TTable.NiceTableName(ASqltable.strName)); tempSnippet.SetCodelet("TABLETYPENAME", tabletype); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); tempSnippet.SetCodelet("SQLOPERATION", "eDelete"); tempSnippet.SetCodelet("SEQUENCENAMEANDFIELD", ""); ASnippetSubmitChanges.InsertSnippetPrepend("SUBMITCHANGESDELETE", tempSnippet); tempSnippet = snippetDataset.GetSnippet("SUBMITCHANGES"); tempSnippet.SetCodelet("ORIGTABLENAME", TTable.NiceTableName(ASqltable.strName)); tempSnippet.SetCodelet("TABLETYPENAME", tabletype); tempSnippet.SetCodelet("TABLEVARIABLENAME", variablename); tempSnippet.SetCodelet("SQLOPERATION", "eInsert | TTypedDataAccess.eSubmitChangesOperations.eUpdate"); tempSnippet.SetCodelet("SEQUENCENAMEANDFIELD", ""); if (SequenceName.Length > 0) { tempSnippet.SetCodelet("SEQUENCENAMEANDFIELD", ", \"" + SequenceName + "\", \"" + SequenceColumn + "\""); // look for other tables in the dataset that have a foreign key on the sequenced column // eg. p_location_key_i is set when storing p_location. // now we should update p_partner_location, which still has negative values in p_location_key_i foreach (TDataSetTable table in ATables) { foreach (TConstraint constraint in table.grpConstraint) { if ((constraint.strType == "foreignkey") && (constraint.strOtherTable == ASqltable.strName) && constraint.strOtherFields.Contains(SequenceColumn)) { tempSnippet.SetCodelet("TABLEROWTYPE", TTable.NiceTableName(ASqltable.strName) + "Row"); tempSnippet.SetCodelet("SEQUENCEDCOLUMNNAME", TTable.NiceFieldName(SequenceColumn)); ProcessTemplate updateSnippet = snippetDataset.GetSnippet("UPDATESEQUENCEINOTHERTABLES"); bool canbeNull = !table.GetField(constraint.strThisFields[constraint.strOtherFields.IndexOf(SequenceColumn)]).bNotNull; updateSnippet.SetCodelet("TESTFORNULL", canbeNull ? "!otherRow.Is{#REFCOLUMNNAME}Null() && " : ""); updateSnippet.SetCodelet("REFERENCINGTABLEROWTYPE", TTable.NiceTableName(table.tablename) + "Row"); updateSnippet.SetCodelet("REFERENCINGTABLENAME", table.tablealias); updateSnippet.SetCodelet("REFCOLUMNNAME", TTable.NiceFieldName(constraint.strThisFields[constraint.strOtherFields.IndexOf(SequenceColumn)])); updateSnippet.SetCodelet("SEQUENCEDCOLUMNNAME", TTable.NiceFieldName(SequenceColumn)); tempSnippet.InsertSnippet("UPDATESEQUENCEINOTHERTABLES", updateSnippet); } } } } ASnippetSubmitChanges.InsertSnippet("SUBMITCHANGESINSERT", tempSnippet); ASnippetSubmitChanges.AddToCodelet("SUBMITCHANGESUPDATE", ""); } }