本文整理汇总了C#中NpgsqlTypes.NpgsqlBackendTypeInfo类的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlBackendTypeInfo类的具体用法?C# NpgsqlBackendTypeInfo怎么用?C# NpgsqlBackendTypeInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NpgsqlBackendTypeInfo类属于NpgsqlTypes命名空间,在下文中一共展示了NpgsqlBackendTypeInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddType
/// <summary>
/// Add the given NpgsqlBackendTypeInfo to this mapping.
/// </summary>
public void AddType(NpgsqlBackendTypeInfo T)
{
if (OIDIndex.ContainsKey(T.OID))
{
throw new Exception("Type already mapped");
}
OIDIndex[T.OID] = T;
NameIndex[T.Name] = T;
}
示例2: CreateAndLoadInitialTypesMapping
///<summary>
/// This method creates (or retrieves from cache) a mapping between type and OID
/// of all natively supported postgresql data types.
/// This is needed as from one version to another, this mapping can be changed and
/// so we avoid hardcoding them.
/// </summary>
/// <returns>NpgsqlTypeMapping containing all known data types. The mapping must be
/// cloned before it is modified because it is cached; changes made by one connection may
/// effect another connection.</returns>
public static NpgsqlBackendTypeMapping CreateAndLoadInitialTypesMapping(NpgsqlConnector conn)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "LoadTypesMapping");
// [TODO] Verify another way to get higher concurrency.
lock(CLASSNAME)
{
// Check the cache for an initial types map.
NpgsqlBackendTypeMapping oidToNameMapping = (NpgsqlBackendTypeMapping) BackendTypeMappingCache[conn.ServerVersion];
if (oidToNameMapping != null)
{
return oidToNameMapping;
}
// Not in cache, create a new one.
oidToNameMapping = new NpgsqlBackendTypeMapping();
// Create a list of all natively supported postgresql data types.
NpgsqlBackendTypeInfo[] TypeInfoList = new NpgsqlBackendTypeInfo[]
{
new NpgsqlBackendTypeInfo(0, "unknown", NpgsqlDbType.Text, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "refcursor", NpgsqlDbType.Refcursor, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "char", NpgsqlDbType.Char, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "bpchar", NpgsqlDbType.Text, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "varchar", NpgsqlDbType.Varchar, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "text", NpgsqlDbType.Text, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "name", NpgsqlDbType.Text, DbType.String, typeof(String),
null),
new NpgsqlBackendTypeInfo(0, "bytea", NpgsqlDbType.Bytea, DbType.Binary, typeof(Byte[]),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToBinary)),
new NpgsqlBackendTypeInfo(0, "bit", NpgsqlDbType.Bit, DbType.Boolean, typeof(Boolean),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToBit)),
new NpgsqlBackendTypeInfo(0, "bool", NpgsqlDbType.Boolean, DbType.Boolean, typeof(Boolean),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToBoolean)),
new NpgsqlBackendTypeInfo(0, "int2", NpgsqlDbType.Smallint, DbType.Int16, typeof(Int16),
null),
new NpgsqlBackendTypeInfo(0, "int4", NpgsqlDbType.Integer, DbType.Int32, typeof(Int32),
null),
new NpgsqlBackendTypeInfo(0, "int8", NpgsqlDbType.Bigint, DbType.Int64, typeof(Int64),
null),
new NpgsqlBackendTypeInfo(0, "oid", NpgsqlDbType.Bigint, DbType.Int64, typeof(Int64),
null),
new NpgsqlBackendTypeInfo(0, "float4", NpgsqlDbType.Real, DbType.Single, typeof(Single),
null),
new NpgsqlBackendTypeInfo(0, "float8", NpgsqlDbType.Double, DbType.Double, typeof(Double),
null),
new NpgsqlBackendTypeInfo(0, "numeric", NpgsqlDbType.Numeric, DbType.Decimal, typeof(Decimal),
null),
new NpgsqlBackendTypeInfo(0, "inet", NpgsqlDbType.Inet, DbType.Object, typeof(NpgsqlInet), new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToInet)),
new NpgsqlBackendTypeInfo(0, "money", NpgsqlDbType.Money, DbType.Decimal, typeof(Decimal),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToMoney)),
new NpgsqlBackendTypeInfo(0, "date", NpgsqlDbType.Date, DbType.Date, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDate)),
new NpgsqlBackendTypeInfo(0, "time", NpgsqlDbType.Time, DbType.Time, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToTime)),
new NpgsqlBackendTypeInfo(0, "timetz", NpgsqlDbType.Time, DbType.Time, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToTime)),
new NpgsqlBackendTypeInfo(0, "timestamp", NpgsqlDbType.Timestamp, DbType.DateTime, typeof(DateTime),
new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDateTime)),
//.........这里部分代码省略.........
示例3: ArrayBinaryToArray
/// <summary>
/// Creates an n-dimensional System.Array from PG binary representation.
/// This function reads the array header and sets up an n-dimensional System.Array object to hold its data.
/// PopulateArrayFromBinaryArray() is then called to carry out array population.
/// </summary>
public object ArrayBinaryToArray(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int32 fieldValueSize, Int32 TypeModifier)
{
// Sanity check.
if (BackendData.Length < 4)
{
throw new Exception("Insuffient backend data to describe dimension count in binary array header");
}
// Offset 0 holds an integer dscribing the number of dimensions in the array.
int nDims = PGUtil.ReadInt32(BackendData, 0);
// Sanity check.
if (nDims < 0)
{
throw new Exception("Invalid array dimension count encountered in binary array header");
}
// {PG handles 0-dimension arrays, but .net does not. Return a 0-size 1-dimensional array.
if (nDims == 0)
{
return Array.CreateInstance(_elementConverter.GetFrameworkType(TypeModifier), 0);
}
int dimOffset;
// Offset 12 begins an array of {int,int} objects, of length nDims.
int dataOffset = 12;
// Sanity check.
if (BackendData.Length < dataOffset + nDims * 8)
{
throw new Exception("Insuffient backend data to describe all expected dimensions in binary array header");
}
int[] dimLengths;
int[] dimLBounds;
dimLengths = new int[nDims];
dimLBounds = new int[nDims];
// Populate array dimension lengths and lower bounds.
for (dimOffset = 0 ; dimOffset < nDims ; dimOffset++)
{
dimLengths[dimOffset] = PGUtil.ReadInt32(BackendData, dataOffset);
dataOffset += 4;
// Lower bounds is 1-based in SQL, 0-based in .NET.
dimLBounds[dimOffset] = PGUtil.ReadInt32(BackendData, dataOffset) - 1;
dataOffset += 4;
}
Array dst;
int[] dstOffsets;
dst = Array.CreateInstance(_elementConverter.GetFrameworkType(TypeModifier), dimLengths, dimLBounds);
dstOffsets = new int[nDims];
// Right after the dimension descriptors begins array data.
// Populate the new array.
PopulateArrayFromBinaryArray(TypeInfo, BackendData, fieldValueSize, TypeModifier, ref dataOffset, dimLengths, dimLBounds, 0, dst, dstOffsets);
return dst;
}
示例4: ArrayTextToArray
/// <summary>
/// Creates an array from pg text representation.
/// </summary>
public object ArrayTextToArray(NpgsqlBackendTypeInfo TypeInfo, byte[] bBackendData, Int16 TypeSize, Int32 TypeModifier)
{
string BackendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);
//first create an arraylist, then convert it to an array.
ArrayList arrayList = ToArrayList(TypeInfo, BackendData, TypeSize, TypeModifier);
return ToArray(arrayList, _elementConverter.GetType(TypeModifier));
}
示例5: TryGetTypeInfo
internal bool TryGetTypeInfo(int fieldIndex, out NpgsqlBackendTypeInfo backendTypeInfo)
{
if (CurrentDescription == null)
{
throw new IndexOutOfRangeException(); //Essentially, all indices are out of range.
}
return (backendTypeInfo = CurrentDescription[fieldIndex].TypeInfo) != null;
}
示例6: TextBinaryToString
/// <summary>
/// Convert UTF8 encoded text a string.
/// </summary>
internal static Object TextBinaryToString(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int32 fieldValueSize, Int32 TypeModifier)
{
return BackendEncoding.UTF8Encoding.GetString(BackendData);
}
示例7: ToGuid
internal static Object ToGuid(NpgsqlBackendTypeInfo TypeInfo, byte[] bBackendData, Int16 TypeSize, Int32 TypeModifier)
{
string BackendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);
return new Guid(BackendData);
}
示例8: ToPolygon
/// <summary>
/// Polygon.
/// </summary>
internal static Object ToPolygon(NpgsqlBackendTypeInfo TypeInfo, byte[] bBackendData, Int16 TypeSize,
Int32 TypeModifier)
{
string BackendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);
Match m = pathpolygonRegex.Match(BackendData);
List<NpgsqlPoint> points = new List<NpgsqlPoint>();
while (m.Success)
{
// Here we have to do a little hack, because as of 2004-08-11 mono cvs version, the last group is returned with
// a trailling ')' only when the last character of the string is a ')' which is the case for closed paths
// returned by backend. This gives parsing exception when converting to single.
// I still don't know if this is a bug in mono or in my regular expression.
// Check if there is this character and remove it.
String group2 = m.Groups[2].ToString();
if (group2.EndsWith(")"))
{
group2 = group2.Remove(group2.Length - 1, 1);
}
points.Add(
new NpgsqlPoint(Single.Parse(m.Groups[1].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat),
Single.Parse(group2, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat)));
m = m.NextMatch();
}
return new NpgsqlPolygon(points);
}
示例9: ToArray
/// <summary>
/// Creates an array from pg representation.
/// </summary>
public object ToArray(NpgsqlBackendTypeInfo TypeInfo, String BackendData, Int16 TypeSize, Int32 TypeModifier)
{
//first create an arraylist, then convert it to an array.
return ToArray(ToArrayList(TypeInfo, BackendData, TypeSize, TypeModifier), _elementConverter.Type);
}
示例10: SingleCharBinaryToChar
/// <summary>
/// Convert a "char" to .NET char.
/// </summary>
internal static Object SingleCharBinaryToChar(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int32 fieldValueSize, Int32 TypeModifier)
{
return (char)BackendData[0];
}
示例11: TryGetValue
public bool TryGetValue(int oid, out NpgsqlBackendTypeInfo value)
{
return OIDIndex.TryGetValue(oid, out value);
}
示例12: SingleCharTextToChar
/// <summary>
/// Convert a "char" to .NET char.
/// </summary>
internal static Object SingleCharTextToChar(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int16 TypeSize, Int32 TypeModifier)
{
return BackendData.Length > 0 ? (char)BackendData[0] : (char)0;
}
示例13: ToBitBinary
/// <summary>
/// Convert a postgresql bit to a System.Boolean if length is 1, else a BitString.
/// </summary>
internal static Object ToBitBinary(NpgsqlBackendTypeInfo TypeInfo, byte[] BackendData, Int32 fieldValueSize,
Int32 TypeModifier)
{
BitString bs = new BitString(BackendData);
return TypeInfo.NpgsqlDbType == NpgsqlDbType.Bit && TypeModifier == 1 ? (object)bs[0] : bs;
}
示例14: ConvertBackendBytesToSystemType
// CHECKME
// Not sure what to do with this one. I don't believe we ever ask for a binary
// formatting, so this shouldn't even be used right now.
// At some point this will need to be merged into the type converter system somehow?
public static Object ConvertBackendBytesToSystemType(NpgsqlBackendTypeInfo TypeInfo, Byte[] data, Encoding encoding, Int32 fieldValueSize, Int32 typeModifier)
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ConvertBackendBytesToStytemType");
// We are never guaranteed to know about every possible data type the server can send us.
// When we encounter an unknown type, we punt and return the data without modification.
if (TypeInfo == null)
return data;
switch (TypeInfo.NpgsqlDbType)
{
case NpgsqlDbType.Bytea:
return data;
/*case NpgsqlDbType.Boolean:
return BitConverter.ToBoolean(data, 0);
case NpgsqlDbType.DateTime:
return DateTime.MinValue.AddTicks(IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 0)));
case NpgsqlDbType.Int16:
return IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 0));
case NpgsqlDbType.Int32:
return IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 0));
case NpgsqlDbType.Int64:
return IPAddress.NetworkToHostOrder(BitConverter.ToInt64(data, 0));
case NpgsqlDbType.String:
case NpgsqlDbType.AnsiString:
case NpgsqlDbType.StringFixedLength:
return encoding.GetString(data, 0, fieldValueSize);*/
default:
throw new InvalidCastException("Type not supported in binary format");
}
return null;
}
示例15: ToMoney
/// <summary>
/// Convert a postgresql money to a System.Decimal.
/// </summary>
internal static Object ToMoney(NpgsqlBackendTypeInfo TypeInfo, byte[] bBackendData, Int16 TypeSize, Int32 TypeModifier)
{
string BackendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);
// Will vary according to currency symbol, position of symbol and decimal and thousands separators, but will
// alwasy be two-decimal precision number using Arabic (0-9) digits, so we can extract just those digits and
// divide by 100.
return Convert.ToDecimal(EXCLUDE_DIGITS.Replace(BackendData, string.Empty), CultureInfo.InvariantCulture) / 100m;
}