コード例 #1
0
ファイル: ArrayHandling.cs プロジェクト: l1101100/Npgsql
        /// <summary>
        /// Creates an array list from pg represenation of an array.
        /// Multidimensional arrays are treated as ArrayLists of ArrayLists
        /// </summary>
        private ArrayList ToArrayList(NpgsqlBackendTypeInfo TypeInfo, String BackendData, Int16 elementTypeSize,
                                      Int32 elementTypeModifier)
        {
            ArrayList list = new ArrayList();
            //remove the braces on either side and work on what they contain.
            string stripBraces = BackendData.Trim().Substring(1, BackendData.Length - 2).Trim();

            if (stripBraces.Length == 0)
            {
                return(list);
            }
            if (stripBraces[0] == '{')
            //there are still braces so we have an n-dimension array. Recursively build an ArrayList of ArrayLists
            {
                foreach (string arrayChunk in ArrayChunkEnumeration(stripBraces))
                {
                    list.Add(ToArrayList(TypeInfo, arrayChunk, elementTypeSize, elementTypeModifier));
                }
            }
            else
            //We're either dealing with a 1-dimension array or treating a row of an n-dimension array. In either case parse the elements and put them in our ArrayList
            {
                foreach (string token in TokenEnumeration(stripBraces))
                {
                    //Use the NpgsqlBackendTypeInfo for the element type to obtain each element.
                    list.Add(_elementConverter.ConvertBackendTextToNative(BackendEncoding.UTF8Encoding.GetBytes(token), elementTypeSize, elementTypeModifier));
                }
            }
            return(list);
        }
コード例 #2
0
 ///<summary>
 /// This method is responsible to convert the string received from the backend
 /// to the corresponding NpgsqlType.
 /// The given TypeInfo is called upon to do the conversion.
 /// If no TypeInfo object is provided, no conversion is performed.
 /// </summary>
 public static Object ConvertBackendStringToSystemType(NpgsqlBackendTypeInfo TypeInfo, Byte[] data, Int16 typeSize,
                                                       Int32 typeModifier)
 {
     if (TypeInfo != null)
     {
         return(TypeInfo.ConvertBackendTextToNative(data, typeSize, typeModifier));
     }
     else
     {
         return(BackendEncoding.UTF8Encoding.GetString(data));
     }
 }
コード例 #3
0
        ///<summary>
        /// This method is responsible to convert the string received from the backend
        /// to the corresponding NpgsqlType.
        /// The given TypeInfo is called upon to do the conversion.
        /// If no TypeInfo object is provided, no conversion is performed.
        /// </summary>
        public static Object ConvertBackendStringToSystemType(NpgsqlBackendTypeInfo TypeInfo, Byte[] data, Int16 typeSize,
                                                              Int32 typeModifier)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ConvertBackendStringToSystemType");

            if (TypeInfo != null)
            {
                return(TypeInfo.ConvertBackendTextToNative(data, typeSize, typeModifier));
            }
            else
            {
                return(BackendEncoding.UTF8Encoding.GetString(data));
            }
        }