/// <summary> /// Attempt to map types by issuing a query against pg_type. /// This function takes a list of NpgsqlTypeInfo and attempts to resolve the OID field /// of each by querying pg_type. If the mapping is found, the type info object is /// updated (OID) and added to the provided NpgsqlTypeMapping object. /// </summary> /// <param name="conn">NpgsqlConnector to send query through.</param> /// <param name="TypeMappings">Mapping object to add types too.</param> /// <param name="TypeInfoList">List of types that need to have OID's mapped.</param> public static void LoadTypesMappings(NpgsqlConnector conn, NpgsqlBackendTypeMapping TypeMappings, IList TypeInfoList) { StringBuilder InList = new StringBuilder(); Hashtable NameIndex = new Hashtable(); // Build a clause for the SELECT statement. // Build a name->typeinfo mapping so we can match the results of the query /// with the list of type objects efficiently. foreach (NpgsqlBackendTypeInfo TypeInfo in TypeInfoList) { NameIndex.Add(TypeInfo.Name, TypeInfo); InList.AppendFormat("{0}'{1}'", ((InList.Length > 0) ? ", " : ""), TypeInfo.Name); } if (InList.Length == 0) { return; } NpgsqlCommand command = new NpgsqlCommand("SELECT oid, typname FROM pg_type WHERE typname IN (" + InList.ToString() + ")", conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { NpgsqlBackendTypeInfo TypeInfo = (NpgsqlBackendTypeInfo)NameIndex[dr[1].ToString()]; TypeInfo._OID = Convert.ToInt32(dr[0]); TypeMappings.AddType(TypeInfo); } }
/// <summary> /// Attempt to map types by issuing a query against pg_type. /// This function takes a list of NpgsqlTypeInfo and attempts to resolve the OID field /// of each by querying pg_type. If the mapping is found, the type info object is /// updated (OID) and added to the provided NpgsqlTypeMapping object. /// </summary> /// <param name="conn">NpgsqlConnector to send query through.</param> /// <param name="TypeMappings">Mapping object to add types too.</param> /// <param name="TypeInfoList">List of types that need to have OID's mapped.</param> public static void LoadTypesMappings(NpgsqlConnector conn, NpgsqlBackendTypeMapping TypeMappings, IEnumerable <NpgsqlBackendTypeInfo> TypeInfoList) { StringBuilder InList = new StringBuilder(); Dictionary <string, NpgsqlBackendTypeInfo> NameIndex = new Dictionary <string, NpgsqlBackendTypeInfo>(); // Build a clause for the SELECT statement. // Build a name->typeinfo mapping so we can match the results of the query // with the list of type objects efficiently. foreach (NpgsqlBackendTypeInfo TypeInfo in TypeInfoList) { NameIndex.Add(TypeInfo.Name, TypeInfo); InList.AppendFormat("{0}'{1}'", ((InList.Length > 0) ? ", " : ""), TypeInfo.Name); //do the same for the equivalent array type. NameIndex.Add("_" + TypeInfo.Name, ArrayTypeInfo(TypeInfo)); InList.Append(", '_").Append(TypeInfo.Name).Append('\''); } if (InList.Length == 0) { return; } using ( NpgsqlCommand command = new NpgsqlCommand(string.Format("SELECT typname, oid FROM pg_type WHERE typname IN ({0})", InList), conn)) { using (NpgsqlDataReader dr = command.GetReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { while (dr.Read()) { NpgsqlBackendTypeInfo TypeInfo = NameIndex[dr[0].ToString()]; TypeInfo._OID = Convert.ToInt32(dr[1]); TypeMappings.AddType(TypeInfo); } } } }
/// <summary> /// Attempt to map types by issuing a query against pg_type. /// This function takes a list of NpgsqlTypeInfo and attempts to resolve the OID field /// of each by querying pg_type. If the mapping is found, the type info object is /// updated (OID) and added to the provided NpgsqlTypeMapping object. /// </summary> /// <param name="conn">NpgsqlConnector to send query through.</param> /// <param name="TypeMappings">Mapping object to add types too.</param> /// <param name="TypeInfoList">List of types that need to have OID's mapped.</param> public static void LoadTypesMappings(NpgsqlConnector conn, NpgsqlBackendTypeMapping TypeMappings, IList TypeInfoList) { StringBuilder InList = new StringBuilder(); Hashtable NameIndex = new Hashtable(); // Build a clause for the SELECT statement. // Build a name->typeinfo mapping so we can match the results of the query /// with the list of type objects efficiently. foreach (NpgsqlBackendTypeInfo TypeInfo in TypeInfoList) { NameIndex.Add(TypeInfo.Name, TypeInfo); InList.AppendFormat("{0}'{1}'", ((InList.Length > 0) ? ", " : ""), TypeInfo.Name); } if (InList.Length == 0) { return; } NpgsqlCommand command = new NpgsqlCommand("SELECT oid, typname FROM pg_type WHERE typname IN (" + InList.ToString() + ")", conn); NpgsqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { NpgsqlBackendTypeInfo TypeInfo = (NpgsqlBackendTypeInfo)NameIndex[dr[1].ToString()]; TypeInfo._OID = Convert.ToInt32(dr[0]); TypeMappings.AddType(TypeInfo); } }