Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / EntitySqlException.cs / 2 / 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
- MatrixIndependentAnimationStorage.cs
- XpsSerializationManager.cs
- HtmlInputCheckBox.cs
- ZipIOCentralDirectoryFileHeader.cs
- ContentElementAutomationPeer.cs
- Typeface.cs
- Point.cs
- BamlCollectionHolder.cs
- AspNetSynchronizationContext.cs
- DocumentScope.cs
- ISCIIEncoding.cs
- ProcessHostConfigUtils.cs
- WinEventHandler.cs
- AmbientValueAttribute.cs
- X509SecurityTokenAuthenticator.cs
- AdvancedBindingEditor.cs
- Double.cs
- Filter.cs
- MarkerProperties.cs
- ZipFileInfoCollection.cs
- WindowShowOrOpenTracker.cs
- SmtpDigestAuthenticationModule.cs
- HttpCapabilitiesEvaluator.cs
- LinkConverter.cs
- DoubleStorage.cs
- Single.cs
- RectAnimationBase.cs
- UrlMappingCollection.cs
- ApplyImportsAction.cs
- PropertyGroupDescription.cs
- PropertyGroupDescription.cs
- CredentialCache.cs
- ExceptionUtil.cs
- ApplicationContext.cs
- StrokeNodeOperations2.cs
- SettingsSavedEventArgs.cs
- DataGridViewColumnHeaderCell.cs
- MatrixTransform.cs
- WebPartConnectionsCancelVerb.cs
- ExpressionStringBuilder.cs
- RestClientProxyHandler.cs
- TabOrder.cs
- Misc.cs
- BitmapInitialize.cs
- ImageField.cs
- PropertyGridCommands.cs
- DataFieldEditor.cs
- PkcsMisc.cs
- IdentityModelDictionary.cs
- BamlResourceContent.cs
- HybridObjectCache.cs
- Cast.cs
- Emitter.cs
- ViewValidator.cs
- HandledEventArgs.cs
- Ops.cs
- WindowsFormsHost.cs
- ComPlusServiceHost.cs
- MessageSmuggler.cs
- TraceSection.cs
- ImageMapEventArgs.cs
- SectionXmlInfo.cs
- PersistenceException.cs
- SHA384.cs
- TaskCanceledException.cs
- TabControlCancelEvent.cs
- ImageFormat.cs
- PartialArray.cs
- ToolstripProfessionalRenderer.cs
- ItemsControlAutomationPeer.cs
- AutoGeneratedFieldProperties.cs
- RuleSettings.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- DefaultValueTypeConverter.cs
- KeyProperty.cs
- RuntimeComponentFilter.cs
- RowsCopiedEventArgs.cs
- EdmComplexPropertyAttribute.cs
- EntityCollection.cs
- ZipFileInfoCollection.cs
- HttpHandlerActionCollection.cs
- RecordsAffectedEventArgs.cs
- ConfigXmlCDataSection.cs
- DataKey.cs
- PropertyConverter.cs
- EpmCustomContentDeSerializer.cs
- CultureSpecificCharacterBufferRange.cs
- Int16Storage.cs
- LinqDataSourceDisposeEventArgs.cs
- TableItemProviderWrapper.cs
- FormsAuthenticationModule.cs
- DesignerRegion.cs
- AccessorTable.cs
- OleDbFactory.cs
- ClientConfigPaths.cs
- SignatureHelper.cs
- AlternationConverter.cs
- CallSiteOps.cs
- StyleReferenceConverter.cs
- TextSelectionProcessor.cs