Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / SqlClient / SqlGen / Symbol.cs / 1305376 / Symbol.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- 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 { ////// 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. /// /// /// Used to track the columns originating from this Symbol when it is used /// in as a from extent in a SqlSelectStatement with a Join or as a From Extent /// in a Join Symbol. /// private Dictionarycolumns; internal Dictionary Columns { get { if (null == columns) { columns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return columns; } } /// /// Used to track the output columns of a SqlSelectStatement it represents /// private DictionaryoutputColumns; internal Dictionary OutputColumns { get { if (null == outputColumns) { outputColumns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return outputColumns; } } 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 if the symbol represents a SqlStatement for which the output columns need to be tracked. /// /// /// /// /// public Symbol(string name, TypeUsage type, DictionaryoutputColumns, bool outputColumnsRenamed) { this.name = name; this.newName = name; this.Type = type; this.outputColumns = outputColumns; this.OutputColumnsRenamed = outputColumnsRenamed; } #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 [....] // @backupOwner [....] //--------------------------------------------------------------------- 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 { ////// 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. /// /// /// Used to track the columns originating from this Symbol when it is used /// in as a from extent in a SqlSelectStatement with a Join or as a From Extent /// in a Join Symbol. /// private Dictionarycolumns; internal Dictionary Columns { get { if (null == columns) { columns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return columns; } } /// /// Used to track the output columns of a SqlSelectStatement it represents /// private DictionaryoutputColumns; internal Dictionary OutputColumns { get { if (null == outputColumns) { outputColumns = new Dictionary (StringComparer.OrdinalIgnoreCase); } return outputColumns; } } 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 if the symbol represents a SqlStatement for which the output columns need to be tracked. /// /// /// /// /// public Symbol(string name, TypeUsage type, DictionaryoutputColumns, bool outputColumnsRenamed) { this.name = name; this.newName = name; this.Type = type; this.outputColumns = outputColumns; this.OutputColumnsRenamed = outputColumnsRenamed; } #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
- ConsumerConnectionPointCollection.cs
- HwndSubclass.cs
- QilValidationVisitor.cs
- LambdaCompiler.Expressions.cs
- BoundingRectTracker.cs
- CodeDirectionExpression.cs
- EditorPartCollection.cs
- ValueSerializerAttribute.cs
- EditorServiceContext.cs
- UriParserTemplates.cs
- TextParaClient.cs
- XmlNodeChangedEventManager.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- PageThemeBuildProvider.cs
- SurrogateSelector.cs
- SoapAttributeOverrides.cs
- TabItemAutomationPeer.cs
- SmtpMail.cs
- XmlSchemaSequence.cs
- ChangeInterceptorAttribute.cs
- WorkflowServiceNamespace.cs
- FillBehavior.cs
- QilReplaceVisitor.cs
- Rules.cs
- CodeDomSerializer.cs
- PingReply.cs
- HttpCacheVaryByContentEncodings.cs
- TemplateXamlParser.cs
- SystemUnicastIPAddressInformation.cs
- parserscommon.cs
- CompareValidator.cs
- QueryContinueDragEvent.cs
- LicenseContext.cs
- EastAsianLunisolarCalendar.cs
- StackOverflowException.cs
- DeviceContext2.cs
- DataControlCommands.cs
- NTAccount.cs
- MemoryStream.cs
- TemplateInstanceAttribute.cs
- handlecollector.cs
- WindowsListViewItem.cs
- AutomationPattern.cs
- XmlArrayAttribute.cs
- BaseParser.cs
- WebBrowser.cs
- ActiveXHelper.cs
- WebContext.cs
- EditCommandColumn.cs
- VectorAnimationBase.cs
- StringToken.cs
- XmlCustomFormatter.cs
- GAC.cs
- CounterCreationData.cs
- DbSetClause.cs
- CodeTypeDelegate.cs
- AnnotationAdorner.cs
- XmlSchemaObject.cs
- DynamicDiscoveryDocument.cs
- OleDbTransaction.cs
- TextTreeNode.cs
- StopStoryboard.cs
- URLEditor.cs
- SerializationFieldInfo.cs
- DataSourceGroupCollection.cs
- EntityContainerRelationshipSet.cs
- Delay.cs
- Tag.cs
- BinaryObjectInfo.cs
- Models.cs
- SqlDataSourceCommandParser.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- InstanceOwnerQueryResult.cs
- NotificationContext.cs
- Set.cs
- ConfigXmlElement.cs
- SystemWebCachingSectionGroup.cs
- XmlToDatasetMap.cs
- ContractMapping.cs
- HttpListenerContext.cs
- ScalarOps.cs
- DependencyPropertyKind.cs
- CollectionConverter.cs
- XmlHierarchicalDataSourceView.cs
- FormsAuthenticationEventArgs.cs
- CommonGetThemePartSize.cs
- WorkItem.cs
- DynamicValidator.cs
- SessionSwitchEventArgs.cs
- DetailsViewUpdateEventArgs.cs
- HandlerBase.cs
- Empty.cs
- DataDocumentXPathNavigator.cs
- SchemaTypeEmitter.cs
- XmlTypeMapping.cs
- PageBuildProvider.cs
- TextElementEditingBehaviorAttribute.cs
- XmlSerializerVersionAttribute.cs
- WebAdminConfigurationHelper.cs
- EditorZone.cs