Пример #1
0
        public TSQLStringLiteral(
            int beginPostion,
            string text) :
            base(
                beginPostion,
                text)
        {
            // need to find unescaped value insides quote characters

            // there are three different possible quote characters that we might support for string literals

            // if this is a unicode string it will begin with N
            int quotePosition = 0;
            int length        = text.Length - 2;

            if (text[0] == 'N')
            {
                quotePosition++;
                length--;
                IsUnicode = true;
            }
            else
            {
                IsUnicode = false;
            }

            // now we can find which quote character we're using
            QuoteCharacter = text[quotePosition];

            // now unescape doubled up quote characters
            Value = text.Substring(quotePosition + 1, length)
                    .Replace(new string(QuoteCharacter, 2), QuoteCharacter.ToString());
        }
        public SqlToken GenerateSqlToken(SelectCommandContext sqlCommandContext)
        {
            var result = new OrderByToken(GenerateOrderByIndex(sqlCommandContext));

            foreach (var orderByItem in sqlCommandContext.GetOrderByContext().GetItems())
            {
                string columnLabel;
                if (orderByItem.GetSegment() is ColumnOrderByItemSegment columnOrderByItemSegment)
                {
                    var            quoteCharacterEnum = columnOrderByItemSegment.GetColumn().GetIdentifier().GetQuoteCharacter();
                    QuoteCharacter quoteCharacter     = QuoteCharacter.Get(quoteCharacterEnum);
                    columnLabel = quoteCharacter.GetStartDelimiter() + columnOrderByItemSegment.GetText() + quoteCharacter.GetEndDelimiter();
                }
                else if (orderByItem.GetSegment() is ExpressionOrderByItemSegment expressionOrderByItemSegment)
                {
                    columnLabel = expressionOrderByItemSegment.GetText();
                }
                else
                {
                    columnLabel = $"{orderByItem.GetIndex()}"; // String.valueOf(each.getIndex());
                }
                result.ColumnLabels.Add(columnLabel);
                result.OrderDirections.Add(orderByItem.GetSegment().GetOrderDirection());
            }
            return(result);
        }
Пример #3
0
        public string ToString(RouteUnit routeUnit)
        {
            String actualTableName = GetLogicAndActualTables(routeUnit)[identifier.GetValue().ToLower()];

            actualTableName = null == actualTableName?identifier.GetValue().ToLower() : actualTableName;

            var quoteCharacterEnum = identifier.GetQuoteCharacter();

            return($"{QuoteCharacter.Get(quoteCharacterEnum).GetStartDelimiter()}{actualTableName}{QuoteCharacter.Get(quoteCharacterEnum).GetEndDelimiter()}");
        }
        /// <summary>
        /// Retrieves a token from a character array.
        /// </summary>
        /// <param name="chars">the character array containing the token</param>
        /// <param name="start">the index of the first character of the token</param>
        /// <param name="end">the index of the last character of the token</param>
        /// <returns>the token without the surrounding quotes, or the token itself if there are no surrounding quotes</returns>
        private string RetrieveToken(char[] chars, int start, int end)
        {
            var startQuote = start;
            var endQuote   = end;

            // Remove quotes if necessary
            if (SearchQuote(chars, ref startQuote, ref endQuote))
            {
                var token = new string(chars, startQuote + 1, endQuote - startQuote - 1);
                token = token.Replace(QuoteCharacter.ToString() + QuoteCharacter, QuoteCharacter.ToString());
                return(token);
            }
            return(new string(chars, start, end - start + 1));
        }
Пример #5
0
        public string ToString(RouteUnit routeUnit)
        {
            StringBuilder result             = new StringBuilder();
            var           quoteCharacterEnum = _identifier.GetQuoteCharacter();
            var           quoteCharacter     = QuoteCharacter.Get(quoteCharacterEnum);

            result.Append(quoteCharacter.GetStartDelimiter()).Append(_identifier.GetValue());
            IDictionary <string, string> logicAndActualTables = GetLogicAndActualTables(routeUnit);

            if (logicAndActualTables.Any())
            {
                result.Append("_").Append(logicAndActualTables.Values.FirstOrDefault());
            }
            result.Append(quoteCharacter.GetEndDelimiter());
            return(result.ToString());
        }
Пример #6
0
        internal TSQLStringLiteral(
            int beginPosition,
            string text) :
            base(
                beginPosition,
                text)
        {
            // need to find unescaped value insides quote characters

            // there are three different possible quote characters that we might support for string literals

            // if this is a unicode string it will begin with N
            int quotePosition = 0;
            int length        = text.Length - 2;

            if (text[0] == 'N')
            {
                quotePosition++;
                length--;
                IsUnicode = true;
            }
            else
            {
                IsUnicode = false;
            }

            // now we can find which quote character we're using
            QuoteCharacter = text[quotePosition];

            // trim off the leading and trailing quotes
            Value = text.Substring(quotePosition + 1, length);

            // now unescape doubled up quote characters
            Value = Value.Replace(new string(QuoteCharacter, 2), QuoteCharacter.ToString());

            // remove line continuation backslash
            // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-backslash?view=sql-server-2017
            Value = Value.Replace("\\\r\n", "");
            Value = Value.Replace("\\\n", "");
        }
 public IdentifierValue(string text)
 {
     _value = SqlUtil.GetExactlyValue(text);
     _quoteCharacterEnum = QuoteCharacter.GetQuoteCharacter(text);
 }