Esempio n. 1
0
        /// <summary>
        /// Parses a subsection of the given string into a TypeCode and size, returning the nested content
        /// as a remainder.
        /// Given a string of  ARRAY{STRING}, the remainer will be 'STRING' and the returned typecode will be ARRAY.
        /// </summary>
        private static bool TryParsePartial(string complexName, out TypeCode typeCode, out int?size, out string remainder)
        {
            typeCode  = TypeCode.Unspecified;
            size      = null;
            remainder = null;
            if (string.IsNullOrEmpty(complexName))
            {
                return(false);
            }

            int remainderStart = complexName.IndexOfAny(new[] { '<', '(' });

            remainderStart = remainderStart != -1 ? remainderStart : complexName.Length;
            typeCode       = TypeCodeExtensions.GetTypeCode(complexName.Substring(0, remainderStart));
            if (typeCode == TypeCode.Unspecified)
            {
                return(false);
            }
            if (complexName.Length > remainderStart)
            {
                if (complexName[remainderStart] == '(')
                {
                    //get the size and remainder to send back
                    var sizeEnd = complexName.IndexOf(')');
                    if (sizeEnd == -1)
                    {
                        return(false);
                    }
                    var sizeString = complexName.Substring(remainderStart + 1, sizeEnd - remainderStart - 1).Trim();
                    if (!sizeString.Equals("MAX", StringComparison.OrdinalIgnoreCase) &&
                        int.TryParse(sizeString, out int parsedSize))
                    {
                        size = parsedSize;
                    }
                    remainder = complexName.Substring(sizeEnd + 1).Trim();
                }
                else
                {
                    var innerEnd = complexName.LastIndexOf('>');
                    if (innerEnd == -1)
                    {
                        return(false);
                    }
                    //get the remainder to send back.
                    remainder = complexName.Substring(remainderStart + 1, innerEnd - remainderStart - 1).Trim();
                }
            }
            return(true);
        }
 private static ResultSetMetadata CreateSingleFieldMetadata(TypeCode typeCode) =>
 new ResultSetMetadata
 {
     RowType = new StructType
     {
         Fields =
         {
             new StructType.Types.Field
             {
                 Name = "col1", Type = new V1.Type{
                     Code = typeCode
                 }
             }
         }
     }
 };
Esempio n. 3
0
 /// <inheritdoc />
 public override string ToString()
 {
     if (ArrayElementType != null)
     {
         return($"ARRAY<{ArrayElementType}>");
     }
     if (StructMembers != null && StructMembers.Count > 0)
     {
         var s = new StringBuilder();
         foreach (var keyValuePair in StructMembers)
         {
             s.Append(s.Length == 0 ? "STRUCT<" : ", ");
             s.Append($"{keyValuePair.Key}:{keyValuePair.Value}");
         }
         s.Append(">");
         return(s.ToString());
     }
     return(Size.HasValue ? $"{TypeCode.GetOriginalName()}({Size})" : TypeCode.GetOriginalName());
 }
Esempio n. 4
0
 /// <inheritdoc />
 public override string ToString()
 {
     if (ArrayElementType != null)
     {
         return($"ARRAY<{ArrayElementType}>");
     }
     if (StructFields != null && StructFields.Count > 0)
     {
         var s = new StringBuilder();
         foreach (var field in StructFields)
         {
             s.Append(s.Length == 0 ? "STRUCT<" : ", ");
             s.Append(field.Name == "" ? field.Type.ToString() : $"{field.Name}: {field.Type}");
         }
         s.Append(">");
         return(s.ToString());
     }
     return(Size.HasValue ? $"{TypeCode.GetOriginalName()}({Size})" : TypeCode.GetOriginalName());
 }
Esempio n. 5
0
 private SpannerDbType(TypeCode typeCode, SpannerDbType arrayElementType)
     : this(typeCode) => ArrayElementType = arrayElementType;
Esempio n. 6
0
 private SpannerDbType(TypeCode typeCode, int?size = null)
 {
     GaxPreconditions.CheckNonNegative(size.GetValueOrDefault(), "Size must be nonnegative.");
     TypeCode = typeCode;
     Size     = size;
 }
Esempio n. 7
0
 internal static SpannerDbType FromTypeCode(TypeCode code)
 => s_simpleTypes.TryGetValue(code, out SpannerDbType type) ? type : null;
 private SpannerDbType(TypeCode typeCode, int?size = null)
 {
     TypeCode = typeCode;
     Size     = size;
 }