private static List <UnifaceObjectSourceCodeBlockUxgroup> GetCodeBlockEntitiyGroups(SqlConnection connection, UnifaceObjectId objectId) { var codeBlockGroups = new List <UnifaceObjectSourceCodeBlockUxgroup>(); var command = new SqlCommand( $"SELECT * FROM uxgroup " + $"WHERE uform = '{objectId.ObjectName}'", connection); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var codeBlockGroup = new UnifaceObjectSourceCodeBlockUxgroup(); codeBlockGroup.Ubase = reader["ubase"].ToString().Trim(); codeBlockGroup.Ulabel = reader["ulabel"].ToString().Trim(); codeBlockGroup.SourceCode.Append(reader["tplactual"].ToString()); codeBlockGroups.Add(codeBlockGroup); } } // Load the overflow data. foreach (var codeBlockGroup in codeBlockGroups) { var overflowCommand = new SqlCommand( $"SELECT * FROM ouxgroup " + $"WHERE uform = '{objectId.ObjectName}' AND ulabel = '{codeBlockGroup.Ulabel}' AND ubase = '{codeBlockGroup.Ubase}' ORDER BY segm", connection); using (var reader = overflowCommand.ExecuteReader()) UnifaceSourceCodeParser.LoadOverflowSegments(reader, codeBlockGroup.SourceCode); } return(codeBlockGroups); }
UnifaceObjectData IUnifaceSourceCode.Extract(SqlConnection connection, UnifaceObjectId objectId) { var sourceCodeBlock = new StringBuilder(); Dictionary <string, object> objectData; var libraryCondition = objectId.LibraryNameIsGlobal ? $"{LibraryField} IS NULL" : $"{LibraryField} = '{objectId.LibraryName}'"; var command = new SqlCommand( $"SELECT * FROM {PrimaryTable} " + $"WHERE {IdField} = '{objectId.ObjectName}' AND {libraryCondition} AND {TypeFilter}", connection); using (var reader = command.ExecuteReader()) { if (!reader.Read()) { throw new InvalidOperationException($"Could not find {objectId} in database. Check that the object identifier is correct. SQL: '{command.CommandText}'"); } objectData = reader.ToDictionary(); sourceCodeBlock.Append(reader[CodeField].ToString()); } var overflowLibraryCondition = this.applyLibraryConditionToOverflowTable ? " AND " + libraryCondition : ""; var getSegmentsCommand = new SqlCommand($"SELECT data FROM {overflowTable} WHERE {IdField} = '{objectId.ObjectName}' {overflowLibraryCondition} ORDER BY segm", connection); using (var reader = getSegmentsCommand.ExecuteReader()) UnifaceSourceCodeParser.LoadOverflowSegments(reader, sourceCodeBlock); return(new UnifaceObjectData(objectData, new UnifaceObjectSourceCodeBlockGroup("", sourceCodeBlock))); }
private static List <UnifaceObjectSourceCodeBlockUxfield> GetCodeBlockEntityFields(SqlConnection connection, UnifaceObjectId objectId) { var codeBlockFields = new List <UnifaceObjectSourceCodeBlockUxfield>(); var command = new SqlCommand( $"SELECT * FROM uxfield " + $"WHERE uform = '{objectId.ObjectName}'", connection); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var codeBlockField = new UnifaceObjectSourceCodeBlockUxfield(); codeBlockField.Ulabel = reader["ulabel"].ToString().Trim(); codeBlockField.Grp = reader["grp"].ToString().Trim(); codeBlockField.Ubase = reader["ubase"].ToString().Trim(); codeBlockField.SourceCode.Append(reader["startmod"].ToString()); codeBlockFields.Add(codeBlockField); } } // Load the overflow data. foreach (var codeBlockField in codeBlockFields) { var overflowCommand = new SqlCommand( $"SELECT * FROM ouxfield " + $"WHERE uform = '{objectId.ObjectName}' AND ulabel = '{codeBlockField.Ulabel}' AND grp = '{codeBlockField.Grp}' AND ubase = '{codeBlockField.Ubase}' ORDER BY segm", connection); using (var reader = overflowCommand.ExecuteReader()) UnifaceSourceCodeParser.LoadOverflowSegments(reader, codeBlockField.SourceCode); } return(codeBlockFields); }