Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / EntitySqlException.cs / 1 / EntitySqlException.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- //#define CLEAN_INTERNALS_FROM_STACK namespace System.Data { using System; using System.IO; using System.Data.Common.EntitySql; using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics; using System.Text; ////// Represents an eSql Query compilation exception; /// The class of exceptional conditions that may cause this exception to be raised are mainly: /// 1) Syntax Errors: raised during query text parsing and when a given query does not conform to eSql formal grammar; /// 2) Semantic Errors: raised when semantic rules of eSql language are not met such as metadata or schema information /// not accurate or not present, type validation errors, scoping rule violations, user of undefined variables, etc. /// For more information, see eSql Language Spec. /// [Serializable] public sealed class EntitySqlException : EntityException { #region Private Fields ////// represents the full error message containing the error description, the error context if available, line /// and column number if available. /// private string _message; ////// error message description. /// private string _errorDescription; ////// information about the context where the error occurred /// private string _errorContext; ////// error line number /// private int _line; ////// error column number /// private int _column; #endregion #region Public Constructors ////// initializes a new instance of EntityException with the generic error message /// public EntitySqlException() : this(System.Data.Entity.Strings.GeneralQueryError) { HResult = HResults.InvalidQuery; } ////// initializes a new instance of EntityException with a given message /// /// public EntitySqlException( string message ) { _message = message; HResult = HResults.InvalidQuery; } ////// initializes a new instance of EntityException with a given message and innerException instance /// /// /// public EntitySqlException( string message, Exception innerException ) : base(message,innerException) { _message = message; HResult = HResults.InvalidQuery; } ////// initializes a new instance EntityException with a given SerializationInfo and StreamingContext /// /// /// private EntitySqlException( SerializationInfo serializationInfo, StreamingContext streamingContext ) : base(serializationInfo, streamingContext) { HResult = HResults.InvalidQuery; } #endregion #region Internal Constructors ////// initializes a new instance EntityException with an ErrorContext instance and a given error message /// internal static EntitySqlException Create(ErrorContext errCtx, string errorMessage, Exception innerException) { return EntitySqlException.Create(errCtx.QueryText, errorMessage, errCtx.InputPosition, errCtx.ErrorContextInfo, errCtx.UseContextInfoAsResourceIdentifier, innerException); } ////// initializes a new instance EntityException with contextual information to allow detailed error feedback /// internal static EntitySqlException Create( string queryText, string errorDescription, int errorPosition, string errorContextInfo, bool loadErrorContextFromResource, Exception innerException) { string errorContext; int line; int column; string errorMessage; if (loadErrorContextFromResource) { errorContext = (null != errorContextInfo) ? EntityRes.GetString(errorContextInfo) : String.Empty; } else { errorContext = errorContextInfo; } errorMessage = FormatQueryError(queryText, errorDescription, errorPosition, errorContext, out line, out column); return new EntitySqlException(errorMessage, errorDescription, errorContext, line, column, innerException); } ////// core constructor /// private EntitySqlException( string message, string errorDescription, string errorContext, int line, int column, Exception innerException ) : base(message,innerException) { _message = message; _errorDescription = errorDescription; _errorContext = errorContext; _line = line; _column = column; HResult = HResults.InvalidQuery; } #endregion #region Public Properties ////// Gets the full error message containing the error description, the error context if available, line /// and column numbers if available /// public override string Message { get { return _message ?? String.Empty; } } ////// Gets the error description explaining the reason why the query was not accepted or an empty String.Empty /// public string ErrorDescription { get { return _errorDescription ?? String.Empty; } } ////// Gets the aproximate context where the error occurred if available. /// public string ErrorContext { get { return _errorContext ?? String.Empty; } } ////// Returns the the aproximate line number where the error occurred /// public int Line { get { return _line; } } ////// Returns the the aproximate column number where the error occurred /// public int Column { get { return _column; } } #endregion #region Private helpers ////// formats error message adding query context to exception message /// /// original query text /// error message /// error position in the input stream /// optional additional information /// aproximate line number where the error occurred /// aproximate column number where the error occurred ///string error message in the format: error such and such[,near [additional information,] line ddd, column ddd]. private static string FormatQueryError( string queryText, string errorMessage, int errPos, string additionalInfo, out int lineNumber, out int columnNumber ) { lineNumber = columnNumber = 0; if (null == queryText) { return (errorMessage ?? String.Empty); } Debug.Assert(errPos > -1, "position in input stream cannot be < 0"); Debug.Assert(errPos <= queryText.Length, "position in input stream cannot be greater than query text size"); // // replace control chars and newLines for single representation characters // StringBuilder sb = new StringBuilder(queryText.Length); for (int i = 0; i < queryText.Length; i++) { Char c = queryText[i]; if (CqlLexer.IsNewLine(c)) { c = '\n'; } else if ((Char.IsControl(c) || Char.IsWhiteSpace(c)) && ('\r' != c)) { c = ' '; } sb.Append(c); } queryText = sb.ToString().TrimEnd(new char[] {'\n' }); // // now compute line and column // int colNum = errPos; int linNum = 1; string[] queryLines = queryText.Split(new char[] {'\n' }, StringSplitOptions.None); for(int i=0; i< queryLines.Length; i++) { if (colNum < queryLines[i].Length) { break; } colNum -= (queryLines[i].Length + 1); linNum++; } colNum++; // // Message format: error such and such[,near [additional information,] line ddd, column ddd]. // sb = new Text.StringBuilder(); sb.Append(errorMessage); bool wasNearTermUsed = false; if ( !String.IsNullOrEmpty(additionalInfo)) { wasNearTermUsed = true; sb.AppendFormat(CultureInfo.CurrentCulture, ", {0}", System.Data.Entity.Strings.LocalizedNear); sb.AppendFormat(CultureInfo.CurrentCulture, " {0}", additionalInfo); } if (0 < errPos) { if (wasNearTermUsed) { sb.Append(","); } else { sb.AppendFormat(CultureInfo.CurrentCulture, ", {0}", System.Data.Entity.Strings.LocalizedNear); } sb.AppendFormat(CultureInfo.CurrentCulture, " {0} {1}, {2} {3}", System.Data.Entity.Strings.LocalizedLine, linNum, System.Data.Entity.Strings.LocalizedColumn, colNum); } lineNumber = linNum; columnNumber = colNum; return sb.Append(".").ToString(); } #endregion #region ISerializable implementation ////// sets the System.Runtime.Serialization.SerializationInfo /// with information about the exception. /// /// The System.Runtime.Serialization.SerializationInfo that holds the serialized /// object data about the exception being thrown. /// /// [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData( SerializationInfo info, StreamingContext context ) { base.GetObjectData(info, context); info.AddValue("Message", _message); info.AddValue("ErrorDescription", _errorDescription); info.AddValue("ErrorContext", _errorContext); info.AddValue("Line", _line); info.AddValue("Column", _column); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- //#define CLEAN_INTERNALS_FROM_STACK namespace System.Data { using System; using System.IO; using System.Data.Common.EntitySql; using System.Globalization; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics; using System.Text; ////// Represents an eSql Query compilation exception; /// The class of exceptional conditions that may cause this exception to be raised are mainly: /// 1) Syntax Errors: raised during query text parsing and when a given query does not conform to eSql formal grammar; /// 2) Semantic Errors: raised when semantic rules of eSql language are not met such as metadata or schema information /// not accurate or not present, type validation errors, scoping rule violations, user of undefined variables, etc. /// For more information, see eSql Language Spec. /// [Serializable] public sealed class EntitySqlException : EntityException { #region Private Fields ////// represents the full error message containing the error description, the error context if available, line /// and column number if available. /// private string _message; ////// error message description. /// private string _errorDescription; ////// information about the context where the error occurred /// private string _errorContext; ////// error line number /// private int _line; ////// error column number /// private int _column; #endregion #region Public Constructors ////// initializes a new instance of EntityException with the generic error message /// public EntitySqlException() : this(System.Data.Entity.Strings.GeneralQueryError) { HResult = HResults.InvalidQuery; } ////// initializes a new instance of EntityException with a given message /// /// public EntitySqlException( string message ) { _message = message; HResult = HResults.InvalidQuery; } ////// initializes a new instance of EntityException with a given message and innerException instance /// /// /// public EntitySqlException( string message, Exception innerException ) : base(message,innerException) { _message = message; HResult = HResults.InvalidQuery; } ////// initializes a new instance EntityException with a given SerializationInfo and StreamingContext /// /// /// private EntitySqlException( SerializationInfo serializationInfo, StreamingContext streamingContext ) : base(serializationInfo, streamingContext) { HResult = HResults.InvalidQuery; } #endregion #region Internal Constructors ////// initializes a new instance EntityException with an ErrorContext instance and a given error message /// internal static EntitySqlException Create(ErrorContext errCtx, string errorMessage, Exception innerException) { return EntitySqlException.Create(errCtx.QueryText, errorMessage, errCtx.InputPosition, errCtx.ErrorContextInfo, errCtx.UseContextInfoAsResourceIdentifier, innerException); } ////// initializes a new instance EntityException with contextual information to allow detailed error feedback /// internal static EntitySqlException Create( string queryText, string errorDescription, int errorPosition, string errorContextInfo, bool loadErrorContextFromResource, Exception innerException) { string errorContext; int line; int column; string errorMessage; if (loadErrorContextFromResource) { errorContext = (null != errorContextInfo) ? EntityRes.GetString(errorContextInfo) : String.Empty; } else { errorContext = errorContextInfo; } errorMessage = FormatQueryError(queryText, errorDescription, errorPosition, errorContext, out line, out column); return new EntitySqlException(errorMessage, errorDescription, errorContext, line, column, innerException); } ////// core constructor /// private EntitySqlException( string message, string errorDescription, string errorContext, int line, int column, Exception innerException ) : base(message,innerException) { _message = message; _errorDescription = errorDescription; _errorContext = errorContext; _line = line; _column = column; HResult = HResults.InvalidQuery; } #endregion #region Public Properties ////// Gets the full error message containing the error description, the error context if available, line /// and column numbers if available /// public override string Message { get { return _message ?? String.Empty; } } ////// Gets the error description explaining the reason why the query was not accepted or an empty String.Empty /// public string ErrorDescription { get { return _errorDescription ?? String.Empty; } } ////// Gets the aproximate context where the error occurred if available. /// public string ErrorContext { get { return _errorContext ?? String.Empty; } } ////// Returns the the aproximate line number where the error occurred /// public int Line { get { return _line; } } ////// Returns the the aproximate column number where the error occurred /// public int Column { get { return _column; } } #endregion #region Private helpers ////// formats error message adding query context to exception message /// /// original query text /// error message /// error position in the input stream /// optional additional information /// aproximate line number where the error occurred /// aproximate column number where the error occurred ///string error message in the format: error such and such[,near [additional information,] line ddd, column ddd]. private static string FormatQueryError( string queryText, string errorMessage, int errPos, string additionalInfo, out int lineNumber, out int columnNumber ) { lineNumber = columnNumber = 0; if (null == queryText) { return (errorMessage ?? String.Empty); } Debug.Assert(errPos > -1, "position in input stream cannot be < 0"); Debug.Assert(errPos <= queryText.Length, "position in input stream cannot be greater than query text size"); // // replace control chars and newLines for single representation characters // StringBuilder sb = new StringBuilder(queryText.Length); for (int i = 0; i < queryText.Length; i++) { Char c = queryText[i]; if (CqlLexer.IsNewLine(c)) { c = '\n'; } else if ((Char.IsControl(c) || Char.IsWhiteSpace(c)) && ('\r' != c)) { c = ' '; } sb.Append(c); } queryText = sb.ToString().TrimEnd(new char[] {'\n' }); // // now compute line and column // int colNum = errPos; int linNum = 1; string[] queryLines = queryText.Split(new char[] {'\n' }, StringSplitOptions.None); for(int i=0; i< queryLines.Length; i++) { if (colNum < queryLines[i].Length) { break; } colNum -= (queryLines[i].Length + 1); linNum++; } colNum++; // // Message format: error such and such[,near [additional information,] line ddd, column ddd]. // sb = new Text.StringBuilder(); sb.Append(errorMessage); bool wasNearTermUsed = false; if ( !String.IsNullOrEmpty(additionalInfo)) { wasNearTermUsed = true; sb.AppendFormat(CultureInfo.CurrentCulture, ", {0}", System.Data.Entity.Strings.LocalizedNear); sb.AppendFormat(CultureInfo.CurrentCulture, " {0}", additionalInfo); } if (0 < errPos) { if (wasNearTermUsed) { sb.Append(","); } else { sb.AppendFormat(CultureInfo.CurrentCulture, ", {0}", System.Data.Entity.Strings.LocalizedNear); } sb.AppendFormat(CultureInfo.CurrentCulture, " {0} {1}, {2} {3}", System.Data.Entity.Strings.LocalizedLine, linNum, System.Data.Entity.Strings.LocalizedColumn, colNum); } lineNumber = linNum; columnNumber = colNum; return sb.Append(".").ToString(); } #endregion #region ISerializable implementation ////// sets the System.Runtime.Serialization.SerializationInfo /// with information about the exception. /// /// The System.Runtime.Serialization.SerializationInfo that holds the serialized /// object data about the exception being thrown. /// /// [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData( SerializationInfo info, StreamingContext context ) { base.GetObjectData(info, context); info.AddValue("Message", _message); info.AddValue("ErrorDescription", _errorDescription); info.AddValue("ErrorContext", _errorContext); info.AddValue("Line", _line); info.AddValue("Column", _column); } #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
- WorkflowFileItem.cs
- ParamArrayAttribute.cs
- QueryCacheManager.cs
- DetailsViewUpdateEventArgs.cs
- HttpRequest.cs
- ChangesetResponse.cs
- BooleanFacetDescriptionElement.cs
- RegistrationServices.cs
- TTSEngineTypes.cs
- FileDialog_Vista_Interop.cs
- SortFieldComparer.cs
- WebPartCatalogCloseVerb.cs
- Emitter.cs
- XmlAttributes.cs
- PolyLineSegment.cs
- AbstractSvcMapFileLoader.cs
- Expression.cs
- DesignerAutoFormatCollection.cs
- Message.cs
- TransactionBridgeSection.cs
- BitmapEffectState.cs
- SQLInt64.cs
- StylusOverProperty.cs
- AnimationClock.cs
- ListViewItemMouseHoverEvent.cs
- NopReturnReader.cs
- MobileFormsAuthentication.cs
- FileVersion.cs
- GrowingArray.cs
- XslTransform.cs
- EpmContentDeSerializer.cs
- ContextMenu.cs
- HtmlElementErrorEventArgs.cs
- CurrencyWrapper.cs
- Set.cs
- RandomNumberGenerator.cs
- ParserOptions.cs
- CreateCardRequest.cs
- EventLogRecord.cs
- ToolStripControlHost.cs
- TextParaClient.cs
- XPathDocumentIterator.cs
- DmlSqlGenerator.cs
- SynchronizedPool.cs
- SqlDataSourceStatusEventArgs.cs
- ViewManagerAttribute.cs
- WebSysDescriptionAttribute.cs
- CommandField.cs
- ExpressionWriter.cs
- MergeLocalizationDirectives.cs
- HtmlTableCellCollection.cs
- HttpCacheParams.cs
- Camera.cs
- AutomationEvent.cs
- KeyInterop.cs
- Simplifier.cs
- BookmarkTable.cs
- HtmlLink.cs
- RemotingException.cs
- SqlBinder.cs
- CharacterMetrics.cs
- ViewStateException.cs
- PrintSystemException.cs
- DispatcherExceptionEventArgs.cs
- DriveInfo.cs
- ECDsaCng.cs
- TextElementAutomationPeer.cs
- UnsignedPublishLicense.cs
- JsonFormatReaderGenerator.cs
- ListViewGroupConverter.cs
- AuthenticatedStream.cs
- RowToFieldTransformer.cs
- ViewStateException.cs
- DataGridViewComboBoxEditingControl.cs
- EventLogEntry.cs
- __ConsoleStream.cs
- SecurityPolicySection.cs
- XPathParser.cs
- PeerDuplexChannel.cs
- InternalsVisibleToAttribute.cs
- WebSysDisplayNameAttribute.cs
- TextSimpleMarkerProperties.cs
- PersonalizablePropertyEntry.cs
- TrustLevel.cs
- CallContext.cs
- FontInfo.cs
- LicenseManager.cs
- DataServiceQuery.cs
- DataGridViewSelectedCellCollection.cs
- Type.cs
- SecureStringHasher.cs
- MarshalDirectiveException.cs
- SqlDataSourceSelectingEventArgs.cs
- HierarchicalDataBoundControlAdapter.cs
- SqlMetaData.cs
- SharedUtils.cs
- SqlRemoveConstantOrderBy.cs
- OutputCacheSettingsSection.cs
- ManipulationInertiaStartingEventArgs.cs
- ProgressiveCrcCalculatingStream.cs