Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / SqlClient / SqlGen / Symbol.cs / 2 / Symbol.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using System.Data.SqlClient; using System.Data.Metadata.Edm; using System.Data.Common.CommandTrees; namespace System.Data.SqlClient.SqlGen { ////// internal class Symbol : ISqlFragment { private Dictionary/// This class represents an extent/nested select statement, /// or a column. /// /// The important fields are Name, Type and NewName. /// NewName starts off the same as Name, and is then modified as necessary. /// /// /// The rest are used by special symbols. /// e.g. NeedsRenaming is used by columns to indicate that a new name must /// be picked for the column in the second phase of translation. /// /// IsUnnest is used by symbols for a collection expression used as a from clause. /// This allows to add the column list /// after the alias. /// /// columns; internal Dictionary Columns { get { if (null == columns) { columns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return columns; } } private bool needsRenaming; internal bool NeedsRenaming { get { return needsRenaming; } set { needsRenaming = value; } } private bool outputColumnsRenamed; internal bool OutputColumnsRenamed { get { return outputColumnsRenamed; } set { outputColumnsRenamed = value; } } private string name; public string Name { get { return name; } } private string newName; public string NewName { get { return newName; } set { newName = value; } } private TypeUsage type; internal TypeUsage Type { get { return type; } set { type = value; } } public Symbol(string name, TypeUsage type) { this.name = name; this.newName = name; this.Type = type; } /// /// Use this constructor the symbol represents a SqlStatement with renamed output columns. /// /// /// /// public Symbol(string name, TypeUsage type, Dictionarycolumns) { this.name = name; this.newName = name; this.Type = type; this.columns = columns; this.OutputColumnsRenamed = true; } #region ISqlFragment Members /// /// Write this symbol out as a string for sql. This is just /// the new name of the symbol (which could be the same as the old name). /// /// We rename columns here if necessary. /// /// /// public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) { if (this.NeedsRenaming) { int i; if (sqlGenerator.AllColumnNames.TryGetValue(this.NewName, out i)) { string newNameCandidate; do { ++i; newNameCandidate = this.NewName + i.ToString(System.Globalization.CultureInfo.InvariantCulture); } while (sqlGenerator.AllColumnNames.ContainsKey(newNameCandidate)); sqlGenerator.AllColumnNames[this.NewName] = i; this.NewName = newNameCandidate; } // Add this column name to list of known names so that there are no subsequent // collisions sqlGenerator.AllColumnNames[this.NewName] = 0; // Prevent it from being renamed repeatedly. this.NeedsRenaming = false; } writer.Write(SqlGenerator.QuoteIdentifier(this.NewName)); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using System.Data.SqlClient; using System.Data.Metadata.Edm; using System.Data.Common.CommandTrees; namespace System.Data.SqlClient.SqlGen { ////// internal class Symbol : ISqlFragment { private Dictionary/// This class represents an extent/nested select statement, /// or a column. /// /// The important fields are Name, Type and NewName. /// NewName starts off the same as Name, and is then modified as necessary. /// /// /// The rest are used by special symbols. /// e.g. NeedsRenaming is used by columns to indicate that a new name must /// be picked for the column in the second phase of translation. /// /// IsUnnest is used by symbols for a collection expression used as a from clause. /// This allows to add the column list /// after the alias. /// /// columns; internal Dictionary Columns { get { if (null == columns) { columns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return columns; } } private bool needsRenaming; internal bool NeedsRenaming { get { return needsRenaming; } set { needsRenaming = value; } } private bool outputColumnsRenamed; internal bool OutputColumnsRenamed { get { return outputColumnsRenamed; } set { outputColumnsRenamed = value; } } private string name; public string Name { get { return name; } } private string newName; public string NewName { get { return newName; } set { newName = value; } } private TypeUsage type; internal TypeUsage Type { get { return type; } set { type = value; } } public Symbol(string name, TypeUsage type) { this.name = name; this.newName = name; this.Type = type; } /// /// Use this constructor the symbol represents a SqlStatement with renamed output columns. /// /// /// /// public Symbol(string name, TypeUsage type, Dictionarycolumns) { this.name = name; this.newName = name; this.Type = type; this.columns = columns; this.OutputColumnsRenamed = true; } #region ISqlFragment Members /// /// Write this symbol out as a string for sql. This is just /// the new name of the symbol (which could be the same as the old name). /// /// We rename columns here if necessary. /// /// /// public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) { if (this.NeedsRenaming) { int i; if (sqlGenerator.AllColumnNames.TryGetValue(this.NewName, out i)) { string newNameCandidate; do { ++i; newNameCandidate = this.NewName + i.ToString(System.Globalization.CultureInfo.InvariantCulture); } while (sqlGenerator.AllColumnNames.ContainsKey(newNameCandidate)); sqlGenerator.AllColumnNames[this.NewName] = i; this.NewName = newNameCandidate; } // Add this column name to list of known names so that there are no subsequent // collisions sqlGenerator.AllColumnNames[this.NewName] = 0; // Prevent it from being renamed repeatedly. this.NeedsRenaming = false; } writer.Write(SqlGenerator.QuoteIdentifier(this.NewName)); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeNamespaceImportCollection.cs
- DataSourceProvider.cs
- ScalarConstant.cs
- BindingValueChangedEventArgs.cs
- String.cs
- FastEncoderWindow.cs
- FtpRequestCacheValidator.cs
- GeometryGroup.cs
- BeginCreateSecurityTokenRequest.cs
- DispatcherOperation.cs
- CLSCompliantAttribute.cs
- HtmlInputFile.cs
- OleDbWrapper.cs
- TableCellCollection.cs
- DynamicDocumentPaginator.cs
- XomlSerializationHelpers.cs
- BrowserCapabilitiesFactory.cs
- InvalidProgramException.cs
- URI.cs
- ElementsClipboardData.cs
- Viewport2DVisual3D.cs
- DefaultBindingPropertyAttribute.cs
- ToolStripSeparatorRenderEventArgs.cs
- AudioSignalProblemOccurredEventArgs.cs
- Misc.cs
- XmlElementAttributes.cs
- DispatcherHookEventArgs.cs
- XmlILOptimizerVisitor.cs
- DynamicDataRoute.cs
- AssemblyFilter.cs
- HtmlInputRadioButton.cs
- SqlClientPermission.cs
- ColorComboBox.cs
- SplitContainerDesigner.cs
- WindowsFormsHostPropertyMap.cs
- PartialCachingAttribute.cs
- WasAdminWrapper.cs
- XPathPatternBuilder.cs
- TimelineGroup.cs
- coordinatorscratchpad.cs
- XPathNodeInfoAtom.cs
- ConfigPathUtility.cs
- TableLayoutPanel.cs
- DrawingAttributeSerializer.cs
- ConnectionManagementElementCollection.cs
- ToolCreatedEventArgs.cs
- TraceSection.cs
- TextPenaltyModule.cs
- SiteOfOriginPart.cs
- AttributeUsageAttribute.cs
- ApplicationActivator.cs
- WebSysDefaultValueAttribute.cs
- ProviderManager.cs
- FolderBrowserDialogDesigner.cs
- Content.cs
- ItemAutomationPeer.cs
- DbConnectionPoolGroupProviderInfo.cs
- DbConnectionOptions.cs
- XPathExpr.cs
- Viewport3DVisual.cs
- SHA256Cng.cs
- AuthenticationService.cs
- WebPartMovingEventArgs.cs
- DispatcherExceptionEventArgs.cs
- DomNameTable.cs
- ScriptDescriptor.cs
- MetadataStore.cs
- VirtualDirectoryMapping.cs
- KeyInterop.cs
- FileDialog_Vista.cs
- WebPartMinimizeVerb.cs
- TransformFinalBlockRequest.cs
- EntityDataSourceContextCreatedEventArgs.cs
- TaskHelper.cs
- basemetadatamappingvisitor.cs
- ManagedCodeMarkers.cs
- SemaphoreSecurity.cs
- SortKey.cs
- DataReaderContainer.cs
- TextRangeProviderWrapper.cs
- OdbcEnvironmentHandle.cs
- xml.cs
- XmlNodeChangedEventManager.cs
- InvalidComObjectException.cs
- ColumnCollection.cs
- PublisherIdentityPermission.cs
- RoleGroup.cs
- ImageButton.cs
- IDataContractSurrogate.cs
- PeerOutputChannel.cs
- SymbolEqualComparer.cs
- GridViewRow.cs
- ReadOnlyDataSource.cs
- KeyedCollection.cs
- KnownBoxes.cs
- DataBinder.cs
- CaretElement.cs
- ComponentEditorPage.cs
- AutoGeneratedField.cs
- HostingEnvironmentSection.cs