forked from Emill/Npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeHandlerRegistry.cs
More file actions
executable file
·647 lines (546 loc) · 25.8 KB
/
TypeHandlerRegistry.cs
File metadata and controls
executable file
·647 lines (546 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using Npgsql.Logging;
using Npgsql.TypeHandlers;
using NpgsqlTypes;
using System.Diagnostics.Contracts;
namespace Npgsql
{
internal class TypeHandlerRegistry
{
#region Members
internal NpgsqlConnector Connector { get; private set; }
internal TypeHandler UnrecognizedTypeHandler { get; private set; }
readonly Dictionary<uint, TypeHandler> _oidIndex;
readonly Dictionary<DbType, TypeHandler> _byDbType;
readonly Dictionary<NpgsqlDbType, TypeHandler> _byNpgsqlDbType;
readonly Dictionary<Type, TypeHandler> _byType;
Dictionary<Type, TypeHandler> _byEnumTypeAsArray;
List<BackendType> _backendTypes;
static internal readonly Dictionary<string, TypeAndMapping> HandlerTypes;
static readonly Dictionary<NpgsqlDbType, DbType> NpgsqlDbTypeToDbType;
static readonly Dictionary<DbType, NpgsqlDbType> DbTypeToNpgsqlDbType;
static readonly Dictionary<Type, NpgsqlDbType> TypeToNpgsqlDbType;
static readonly Dictionary<Type, DbType> TypeToDbType;
/// <summary>
/// Caches, for each connection string, the results of the backend type query in the form of a list of type
/// info structs keyed by the PG name.
/// Repeated connections to the same connection string reuse the query results and avoid an additional
/// roundtrip at open-time.
/// </summary>
static readonly ConcurrentDictionary<string, List<BackendType>> BackendTypeCache = new ConcurrentDictionary<string, List<BackendType>>();
static ConcurrentDictionary<string, TypeHandler> _globalEnumRegistrations;
static readonly NpgsqlLogger Log = NpgsqlLogManager.GetCurrentClassLogger();
#endregion
#region Initialization and Loading
static internal void Setup(NpgsqlConnector connector)
{
connector.TypeHandlerRegistry = new TypeHandlerRegistry(connector);
List<BackendType> types;
if (!BackendTypeCache.TryGetValue(connector.ConnectionString, out types)) {
types = BackendTypeCache[connector.ConnectionString] = LoadBackendTypes(connector);
}
connector.TypeHandlerRegistry.RegisterTypes(types);
}
TypeHandlerRegistry(NpgsqlConnector connector)
{
Connector = connector;
UnrecognizedTypeHandler = new UnrecognizedTypeHandler();
_oidIndex = new Dictionary<uint, TypeHandler>();
_byDbType = new Dictionary<DbType, TypeHandler>();
_byNpgsqlDbType = new Dictionary<NpgsqlDbType, TypeHandler>();
_byType = new Dictionary<Type, TypeHandler>();
_byType[typeof(DBNull)] = UnrecognizedTypeHandler;
_byNpgsqlDbType[NpgsqlDbType.Unknown] = UnrecognizedTypeHandler;
}
static List<BackendType> LoadBackendTypes(NpgsqlConnector connector)
{
var byOID = new Dictionary<uint, BackendType>();
// Select all types (base, array which is also base, enum, range).
// Note that arrays are distinguished from primitive types through them having typreceive=array_recv.
// Order by primitives first, container later.
// For arrays and ranges, join in the element OID and type (to filter out arrays of unhandled
// types).
var query =
@"SELECT a.typname, a.oid, " +
@"CASE WHEN a.typreceive::TEXT='array_recv' THEN 'a' ELSE a.typtype END AS type, " +
@"CASE " +
@"WHEN a.typreceive::TEXT='array_recv' THEN a.typelem " +
(connector.SupportsRangeTypes ? @"WHEN a.typtype='r' THEN rngsubtype " : "")+
@"ELSE 0 " +
@"END AS elemoid, " +
@"CASE WHEN a.typreceive::TEXT='array_recv' OR a.typtype='r' THEN 1 ELSE 0 END AS ord " +
@"FROM pg_type AS a " +
@"LEFT OUTER JOIN pg_type AS b ON (b.oid = a.typelem) " +
(connector.SupportsRangeTypes ? @"LEFT OUTER JOIN pg_range ON (pg_range.rngtypid = a.oid) " : "") +
@"WHERE a.typtype IN ('b', 'r', 'e') AND (b.typtype IS NULL OR b.typtype IN ('b', 'r', 'e'))" +
@"ORDER BY ord";
var types = new List<BackendType>();
using (var command = new NpgsqlCommand(query, connector.Connection))
{
command.AllResultTypesAreUnknown = true;
using (var dr = command.ExecuteReader(CommandBehavior.SequentialAccess))
{
while (dr.Read())
{
var backendType = new BackendType
{
Name = dr.GetString(0),
OID = Convert.ToUInt32(dr[1])
};
Contract.Assume(backendType.Name != null);
Contract.Assume(backendType.OID != 0);
uint elementOID;
var typeChar = dr.GetString(2)[0];
switch (typeChar)
{
case 'b': // Normal base type
backendType.Type = BackendTypeType.Base;
break;
case 'a': // Array
backendType.Type = BackendTypeType.Array;
elementOID = Convert.ToUInt32(dr[3]);
Contract.Assume(elementOID > 0);
if (!byOID.TryGetValue(elementOID, out backendType.Element)) {
Log.Error(string.Format("Array type '{0}' refers to unknown element with OID {1}, skipping", backendType.Name, elementOID), connector.Id);
continue;
}
backendType.Element.Array = backendType;
break;
case 'e': // Enum
backendType.Type = BackendTypeType.Enum;
break;
case 'r': // Range
backendType.Type = BackendTypeType.Range;
elementOID = Convert.ToUInt32(dr[3]);
Contract.Assume(elementOID > 0);
if (!byOID.TryGetValue(elementOID, out backendType.Element)) {
Log.Error(String.Format("Range type '{0}' refers to unknown subtype with OID {1}, skipping", backendType.Name, elementOID), connector.Id);
continue;
}
break;
default:
throw new ArgumentOutOfRangeException(String.Format("Unknown typtype for type '{0}' in pg_type: {1}", backendType.Name, typeChar));
}
types.Add(backendType);
byOID[backendType.OID] = backendType;
}
}
}
/*foreach (var notFound in _typeHandlers.Where(t => t.Oid == -1)) {
_log.WarnFormat("Could not find type {0} in pg_type", notFound.PgNames[0]);
}*/
return types;
}
void RegisterTypes(List<BackendType> backendTypes)
{
foreach (var backendType in backendTypes)
{
switch (backendType.Type) {
case BackendTypeType.Base:
RegisterBaseType(backendType);
continue;
case BackendTypeType.Array:
RegisterArrayType(backendType);
continue;
case BackendTypeType.Range:
RegisterRangeType(backendType);
continue;
case BackendTypeType.Enum:
TypeHandler handler;
if (_globalEnumRegistrations != null && _globalEnumRegistrations.TryGetValue(backendType.Name, out handler)) {
ActivateEnumType(handler, backendType);
}
continue;
default:
Log.Error("Unknown type of type encountered, skipping: " + backendType, Connector.Id);
continue;
}
}
_backendTypes = backendTypes;
}
void RegisterBaseType(BackendType backendType)
{
TypeAndMapping typeAndMapping;
if (!HandlerTypes.TryGetValue(backendType.Name, out typeAndMapping)) {
// Backend type not supported by Npgsql
return;
}
var handlerType = typeAndMapping.HandlerType;
var mapping = typeAndMapping.Mapping;
// Instantiate the type handler. If it has a constructor that accepts an NpgsqlConnector, use that to allow
// the handler to make connector-specific adjustments. Otherwise (the normal case), use the default constructor.
var handler = (TypeHandler)(
handlerType.GetConstructor(new[] { typeof(TypeHandlerRegistry) }) != null
? Activator.CreateInstance(handlerType, this)
: Activator.CreateInstance(handlerType)
);
handler.OID = backendType.OID;
_oidIndex[backendType.OID] = handler;
handler.PgName = backendType.Name;
if (mapping.NpgsqlDbType.HasValue)
{
var npgsqlDbType = mapping.NpgsqlDbType.Value;
if (_byNpgsqlDbType.ContainsKey(npgsqlDbType))
throw new Exception(String.Format("Two type handlers registered on same NpgsqlDbType {0}: {1} and {2}",
npgsqlDbType, _byNpgsqlDbType[npgsqlDbType].GetType().Name, handlerType.Name));
_byNpgsqlDbType[npgsqlDbType] = handler;
handler.NpgsqlDbType = npgsqlDbType;
}
foreach (var dbType in mapping.DbTypes)
{
if (_byDbType.ContainsKey(dbType))
throw new Exception(String.Format("Two type handlers registered on same DbType {0}: {1} and {2}",
dbType, _byDbType[dbType].GetType().Name, handlerType.Name));
_byDbType[dbType] = handler;
}
foreach (var type in mapping.Types)
{
if (_byType.ContainsKey(type))
throw new Exception(String.Format("Two type handlers registered on same .NET type {0}: {1} and {2}",
type, _byType[type].GetType().Name, handlerType.Name));
_byType[type] = handler;
}
}
#endregion
#region Array
void RegisterArrayType(BackendType backendType)
{
Contract.Requires(backendType.Element != null);
TypeHandler elementHandler;
if (!_oidIndex.TryGetValue(backendType.Element.OID, out elementHandler)) {
// Array type referring to an unhandled element type
return;
}
ArrayHandler arrayHandler;
var asBitStringHandler = elementHandler as BitStringHandler;
if (asBitStringHandler != null) {
// BitString requires a special array handler which returns bool or BitArray
arrayHandler = new BitStringArrayHandler(asBitStringHandler);
} else if (elementHandler is ITypeHandlerWithPsv) {
var arrayHandlerType = typeof(ArrayHandlerWithPsv<,>).MakeGenericType(elementHandler.GetFieldType(), elementHandler.GetProviderSpecificFieldType());
arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler);
} else {
var arrayHandlerType = typeof(ArrayHandler<>).MakeGenericType(elementHandler.GetFieldType());
arrayHandler = (ArrayHandler)Activator.CreateInstance(arrayHandlerType, elementHandler);
}
arrayHandler.PgName = "array";
arrayHandler.OID = backendType.OID;
_oidIndex[backendType.OID] = arrayHandler;
if (elementHandler is IEnumHandler)
{
if (_byEnumTypeAsArray == null) {
_byEnumTypeAsArray = new Dictionary<Type, TypeHandler>();
}
var enumType = elementHandler.GetType().GetGenericArguments()[0];
Contract.Assert(enumType.GetTypeInfo().IsEnum);
_byEnumTypeAsArray[enumType] = arrayHandler;
}
else
{
_byNpgsqlDbType[NpgsqlDbType.Array | elementHandler.NpgsqlDbType] = arrayHandler;
}
}
#endregion
#region Range
void RegisterRangeType(BackendType backendType)
{
Contract.Requires(backendType.Element != null);
TypeHandler elementHandler;
if (!_oidIndex.TryGetValue(backendType.Element.OID, out elementHandler))
{
// Range type referring to an unhandled element type
return;
}
var rangeHandlerType = typeof(RangeHandler<>).MakeGenericType(elementHandler.GetFieldType());
var handler = (TypeHandler)Activator.CreateInstance(rangeHandlerType, elementHandler, backendType.Name);
handler.PgName = backendType.Name;
handler.NpgsqlDbType = NpgsqlDbType.Range | elementHandler.NpgsqlDbType;
handler.OID = backendType.OID;
_oidIndex[backendType.OID] = handler;
_byNpgsqlDbType.Add(handler.NpgsqlDbType, handler);
}
#endregion
#region Enum
internal void RegisterEnumType<TEnum>(string pgName) where TEnum : struct
{
var backendTypeInfo = _backendTypes.FirstOrDefault(t => t.Name == pgName);
if (backendTypeInfo == null) {
throw new Exception(String.Format("An enum with the name {0} was not found in the database", pgName));
}
var handler = new EnumHandler<TEnum>();
ActivateEnumType(handler, backendTypeInfo);
}
internal static void RegisterEnumTypeGlobally<TEnum>(string pgName) where TEnum : struct
{
if (_globalEnumRegistrations == null) {
_globalEnumRegistrations = new ConcurrentDictionary<string, TypeHandler>();
}
_globalEnumRegistrations[pgName] = new EnumHandler<TEnum>();
}
void ActivateEnumType(TypeHandler handler, BackendType backendType)
{
handler.PgName = backendType.Name;
handler.OID = backendType.OID;
handler.NpgsqlDbType = NpgsqlDbType.Enum;
_oidIndex[backendType.OID] = handler;
_byType[handler.GetFieldType()] = handler;
if (backendType.Array != null) {
RegisterArrayType(backendType.Array);
}
}
#endregion
#region Lookups
/// <summary>
/// Looks up a type handler by its Postgresql type's OID.
/// </summary>
/// <param name="oid">A Postgresql type OID</param>
/// <returns>A type handler that can be used to encode and decode values.</returns>
internal TypeHandler this[uint oid]
{
get
{
TypeHandler result;
if (!_oidIndex.TryGetValue(oid, out result)) {
result = UnrecognizedTypeHandler;
}
return result;
}
set { _oidIndex[oid] = value; }
}
internal TypeHandler this[NpgsqlDbType npgsqlDbType, Type enumType = null]
{
get
{
TypeHandler handler;
if (_byNpgsqlDbType.TryGetValue(npgsqlDbType, out handler)) {
return handler;
}
if (npgsqlDbType == NpgsqlDbType.Enum)
{
if (enumType == null) {
throw new InvalidCastException("Either specify EnumType along with NpgsqlDbType.Enum, or leave both empty to infer from Value");
}
if (!_byType.TryGetValue(enumType, out handler)) {
throw new NotSupportedException("This enum type is not supported (have you registered it in Npsql and set the EnumType property of NpgsqlParameter?)");
}
return handler;
}
if (npgsqlDbType == (NpgsqlDbType.Enum | NpgsqlDbType.Array))
{
if (enumType == null) {
throw new InvalidCastException("Either specify EnumType along with NpgsqlDbType.Enum, or leave both empty to infer from Value");
}
if (_byEnumTypeAsArray != null && _byEnumTypeAsArray.TryGetValue(enumType, out handler)) {
return handler;
}
throw new NotSupportedException("This enum array type is not supported (have you registered it in Npsql and set the EnumType property of NpgsqlParameter?)");
}
throw new NotSupportedException("This NpgsqlDbType isn't supported in Npgsql yet: " + npgsqlDbType);
}
}
internal TypeHandler this[DbType dbType]
{
get
{
Contract.Ensures(Contract.Result<TypeHandler>() != null);
TypeHandler handler;
if (!_byDbType.TryGetValue(dbType, out handler)) {
throw new NotSupportedException("This DbType is not supported in Npgsql: " + dbType);
}
return handler;
}
}
internal TypeHandler this[object value]
{
get
{
Contract.Requires(value != null);
Contract.Ensures(Contract.Result<TypeHandler>() != null);
if (value is DateTime)
{
return ((DateTime) value).Kind == DateTimeKind.Utc
? this[NpgsqlDbType.TimestampTZ]
: this[NpgsqlDbType.Timestamp];
}
if (value is NpgsqlDateTime) {
return ((NpgsqlDateTime)value).Kind == DateTimeKind.Utc
? this[NpgsqlDbType.TimestampTZ]
: this[NpgsqlDbType.Timestamp];
}
return this[value.GetType()];
}
}
internal TypeHandler this[Type type]
{
get
{
Contract.Ensures(Contract.Result<TypeHandler>() != null);
TypeHandler handler;
if (_byType.TryGetValue(type, out handler)) {
return handler;
}
if (type.IsArray)
{
var elementType = type.GetElementType();
if (elementType.GetTypeInfo().IsEnum) {
if (_byEnumTypeAsArray != null && _byEnumTypeAsArray.TryGetValue(elementType, out handler)) {
return handler;
}
throw new Exception("Enums must be registered with Npgsql via Connection.RegisterEnumType or RegisterEnumTypeGlobally");
}
if (!_byType.TryGetValue(elementType, out handler)) {
throw new NotSupportedException("This .NET type is not supported in Npgsql or your PostgreSQL: " + type);
}
return this[NpgsqlDbType.Array | handler.NpgsqlDbType];
}
var typeInfo = type.GetTypeInfo();
if (typeof(IList).IsAssignableFrom(type))
{
if (typeInfo.IsGenericType)
{
if (!_byType.TryGetValue(type.GetGenericArguments()[0], out handler)) {
throw new NotSupportedException("This .NET type is not supported in Npgsql or your PostgreSQL: " + type);
}
return this[NpgsqlDbType.Array | handler.NpgsqlDbType];
}
throw new NotSupportedException("Non-generic IList is a supported parameter, but the NpgsqlDbType parameter must be set on the parameter");
}
if (typeInfo.IsEnum) {
throw new Exception("Enums must be registered with Npgsql via Connection.RegisterEnumType or RegisterEnumTypeGlobally");
}
if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(NpgsqlRange<>))
{
if (!_byType.TryGetValue(type.GetGenericArguments()[0], out handler)) {
throw new NotSupportedException("This .NET range type is not supported in your PostgreSQL: " + type);
}
return this[NpgsqlDbType.Range | handler.NpgsqlDbType];
}
throw new NotSupportedException("This .NET type is not supported in Npgsql or your PostgreSQL: " + type);
}
}
internal static NpgsqlDbType ToNpgsqlDbType(DbType dbType)
{
return DbTypeToNpgsqlDbType[dbType];
}
internal static NpgsqlDbType ToNpgsqlDbType(Type type)
{
NpgsqlDbType npgsqlDbType;
if (TypeToNpgsqlDbType.TryGetValue(type, out npgsqlDbType)) {
return npgsqlDbType;
}
if (type.IsArray)
{
if (type == typeof(byte[])) {
return NpgsqlDbType.Bytea;
}
return NpgsqlDbType.Array | ToNpgsqlDbType(type.GetElementType());
}
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum) {
return NpgsqlDbType.Enum;
}
if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(NpgsqlRange<>)) {
return NpgsqlDbType.Range | ToNpgsqlDbType(type.GetGenericArguments()[0]);
}
if (type == typeof(DBNull))
{
return NpgsqlDbType.Unknown;
}
throw new NotSupportedException("Can't infer NpgsqlDbType for type " + type);
}
internal static DbType ToDbType(Type type)
{
DbType dbType;
return TypeToDbType.TryGetValue(type, out dbType) ? dbType : DbType.Object;
}
internal static DbType ToDbType(NpgsqlDbType npgsqlDbType)
{
DbType dbType;
return NpgsqlDbTypeToDbType.TryGetValue(npgsqlDbType, out dbType) ? dbType : DbType.Object;
}
#endregion
#region Type Handler Discovery
static TypeHandlerRegistry()
{
HandlerTypes = new Dictionary<string, TypeAndMapping>();
NpgsqlDbTypeToDbType = new Dictionary<NpgsqlDbType, DbType>();
DbTypeToNpgsqlDbType = new Dictionary<DbType, NpgsqlDbType>();
TypeToNpgsqlDbType = new Dictionary<Type, NpgsqlDbType>();
TypeToDbType = new Dictionary<Type, DbType>();
foreach (var t in Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(TypeHandler))))
{
var mappings = t.GetCustomAttributes(typeof(TypeMappingAttribute), false);
if (!mappings.Any())
continue;
foreach (TypeMappingAttribute m in mappings)
{
if (HandlerTypes.ContainsKey(m.PgName)) {
throw new Exception("Two type handlers registered on same PostgreSQL type name: " + m.PgName);
}
HandlerTypes[m.PgName] = new TypeAndMapping { HandlerType=t, Mapping=m };
if (!m.NpgsqlDbType.HasValue) {
continue;
}
var npgsqlDbType = m.NpgsqlDbType.Value;
var inferredDbType = m.InferredDbType;
if (inferredDbType != null) {
NpgsqlDbTypeToDbType[npgsqlDbType] = inferredDbType.Value;
}
foreach (var dbType in m.DbTypes) {
DbTypeToNpgsqlDbType[dbType] = npgsqlDbType;
}
foreach (var type in m.Types)
{
TypeToNpgsqlDbType[type] = npgsqlDbType;
if (inferredDbType != null) {
TypeToDbType[type] = inferredDbType.Value;
}
}
}
}
}
#endregion
#region Misc
static internal void ClearBackendTypeCache()
{
BackendTypeCache.Clear();
}
#endregion
#region Debugging / Testing
#if DEBUG
internal Dictionary<uint, TypeHandler> OIDIndex { get { return _oidIndex; } }
#endif
#endregion
}
class BackendType
{
internal string Name;
internal uint OID;
internal BackendTypeType Type;
internal BackendType Element;
internal BackendType Array;
}
struct TypeAndMapping
{
internal Type HandlerType;
internal TypeMappingAttribute Mapping;
}
/// <summary>
/// Specifies the type of a type, as represented in the PostgreSQL typtype column of the pg_type table.
/// See http://www.postgresql.org/docs/current/static/catalog-pg-type.html
/// </summary>
enum BackendTypeType
{
Base,
Array,
Range,
Enum,
Pseudo
}
}