src/Shared/EntityFramework/Core/EntitySqlException.cs
// <summary>
// Returns error context in the format [[errorContextInfo, ]line ddd, column ddd].
// Returns empty string if errorPosition is less than 0 and errorContextInfo is not specified.
// </summary>
Returns error context in the format [[errorContextInfo, ]line ddd, column ddd].
Returns empty string if errorPosition is less than 0 and errorContextInfo is not specified.
Returns error context in the format [[ errorContextInfo ] line ddd column ddd ] . Returns empty string if errorPosition is less than 0 and errorContextInfo is not specified .
internal static string FormatErrorContext(
            string commandText,
            int errorPosition,
            string errorContextInfo,
            bool loadErrorContextInfoFromResource,
            out int lineNumber,
            out int columnNumber)
        {
            Debug.Assert(errorPosition > -1, "position in input stream cannot be < 0");
            Debug.Assert(errorPosition <= commandText.Length, "position in input stream cannot be greater than query text size");
            if (loadErrorContextInfoFromResource)
            {
                errorContextInfo = !String.IsNullOrEmpty(errorContextInfo) ? EntityRes.GetString(errorContextInfo) : String.Empty;
            }
             Replace control chars and newLines for single representation characters
            var sb = new StringBuilder(commandText.Length);
            for (var i = 0; i < commandText.Length; i++)
            {
                var c = commandText[i];
                if (CqlLexer.IsNewLine(c))
                {
                    c = '\n';
                }
                else if ((Char.IsControl(c) || Char.IsWhiteSpace(c))
                         && ('\r' != c))
                {
                    c = ' ';
                }
                sb.Append(c);
            }
            commandText = sb.ToString().TrimEnd(new[] { '\n' });
             Compute line and column
            var queryLines = commandText.Split(new[] { '\n' }, StringSplitOptions.None);
            for (lineNumber = 0, columnNumber = errorPosition;
                 lineNumber < queryLines.Length && columnNumber > queryLines[lineNumber].Length;
                 columnNumber -= (queryLines[lineNumber].Length + 1), ++lineNumber)
            {
                ;
            }
            ++lineNumber;  switch lineNum and colNum to 1-based indexes
            ++columnNumber;
             Error context format: "[errorContextInfo,] line ddd, column ddd"
            sb = new StringBuilder();
            if (!String.IsNullOrEmpty(errorContextInfo))
            {
                sb.AppendFormat(CultureInfo.CurrentCulture, "{0}, ", errorContextInfo);
            }
            if (errorPosition >= 0)
            {
                sb.AppendFormat(
                    CultureInfo.CurrentCulture,
                    "{0} {1}, {2} {3}",
                    Strings.LocalizedLine,
                    lineNumber,
                    Strings.LocalizedColumn,
                    columnNumber);
            }
            return sb.ToString();
        }
internal static string FormatErrorContext ( string commandText , int errorPosition , string errorContextInfo , bool loadErrorContextInfoFromResource , out int lineNumber , out int columnNumber ) { Debug . Assert ( errorPosition > - 1 , " " ) ; Debug . Assert ( errorPosition <= commandText . Length , " " ) ; if ( loadErrorContextInfoFromResource ) { errorContextInfo = ! String . IsNullOrEmpty ( errorContextInfo ) ? EntityRes . GetString ( errorContextInfo ) : String . Empty ; } var sb = new StringBuilder ( commandText . Length ) ; for ( var i = 0 ; i < commandText . Length ; i ++ ) { var c = commandText [ i ] ; if ( CqlLexer . IsNewLine ( c ) ) { c = ' \n ' ; } else if ( ( Char . IsControl ( c ) || Char . IsWhiteSpace ( c ) ) && ( ' \r ' != c ) ) { c = ' ' ; } sb . Append ( c ) ; } commandText = sb . ToString ( ) . TrimEnd ( new [ ] { ' \n ' } ) ; var queryLines = commandText . Split ( new [ ] { ' \n ' } , StringSplitOptions . None ) ; for ( lineNumber = 0 , columnNumber = errorPosition ; lineNumber < queryLines . Length && columnNumber > queryLines [ lineNumber ] . Length ; columnNumber -= ( queryLines [ lineNumber ] . Length + 1 ) , ++ lineNumber ) { ; } ++ lineNumber ; ++ columnNumber ; sb = new StringBuilder ( ) ; if ( ! String . IsNullOrEmpty ( errorContextInfo ) ) { sb . AppendFormat ( CultureInfo . CurrentCulture , " " , errorContextInfo ) ; } if ( errorPosition >= 0 ) { sb . AppendFormat ( CultureInfo . CurrentCulture , " " , Strings . LocalizedLine , lineNumber , Strings . LocalizedColumn , columnNumber ) ; } return sb . ToString ( ) ; }
Returns error context in the format [[errorContextInfo, ]line ddd, column ddd].
Returns error context in the format [[ errorContextInfo ] line ddd column ddd ] .
// // Replace control chars and newLines for single representation characters // // // Compute line and column // // switch lineNum and colNum to 1-based indexes // // Error context format: "[errorContextInfo,] line ddd, column ddd" //
commandText
string
errorPosition
int
errorContextInfo
string
loadErrorContextInfoFromResource
bool
int
out