示例#1
0
 public override NpgsqlTypeHandler <PostgisGeometry> Create(PostgresType postgresType, NpgsqlConnector conn)
 => new LegacyPostgisHandler(postgresType);
示例#2
0
 internal TupleEnumerator(ReplicationTuple tupleEnumerable, NpgsqlConnector connector)
 {
     _tupleEnumerable = tupleEnumerable;
     _readBuffer      = connector.ReadBuffer;
     _value           = new(connector);
 }
示例#3
0
 /// <inheritdoc />
 public override NpgsqlTypeHandler <string> Create(PostgresType pgType, NpgsqlConnector conn)
 => new TextHandler(pgType, conn);
 public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn)
 => new THandler
 {
     PostgresType = pgType
 };
示例#5
0
 public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn)
 => (NpgsqlTypeHandler)Activator.CreateInstance(_handlerType, pgType) !;
示例#6
0
 public override TypeHandlerResolver Create(NpgsqlConnector connector)
 => new CitextToStringTypeHandlerResolver(connector);
 public override TypeHandlerResolver Create(NpgsqlConnector connector)
 => new JsonNetTypeHandlerResolver(connector, _byType, _settings);
示例#8
0
 public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn)
 => new OIDVectorHandler(pgType, conn.TypeMapper.DatabaseInfo.ByName["oid"]
 public override TypeHandlerResolver Create(NpgsqlConnector connector)
 => new NodaTimeTypeHandlerResolver(connector);
示例#10
0
 internal InsertMessage(NpgsqlConnector connector)
 => _tupleEnumerable = new(connector);
示例#11
0
 public abstract TypeHandlerResolver Create(NpgsqlConnector connector);
示例#12
0
 /// <inheritdoc />
 protected internal JsonPathHandler(PostgresType postgresType, NpgsqlConnector connector)
     : base(postgresType) => _textHandler = new TextHandler(postgresType, connector);
示例#13
0
 internal NoTransactionDatabaseInfo(NpgsqlConnector conn) : base(conn)
 {
 }
示例#14
0
 internal FullDeleteMessage(NpgsqlConnector connector)
 => _tupleEnumerable = new(connector);
示例#15
0
 public override TypeHandlerResolver Create(NpgsqlConnector connector)
 => new MyInt32TypeHandlerResolver(connector, this);
        ///<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)),

                    new NpgsqlBackendTypeInfo(0, "timestamptz", NpgsqlDbType.Timestamp, DbType.DateTime, typeof(DateTime),
                                              new ConvertBackendToNativeHandler(BasicBackendToNativeTypeConverter.ToDateTime)),


                    new NpgsqlBackendTypeInfo(0, "point", NpgsqlDbType.Point, DbType.Object, typeof(NpgsqlPoint),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToPoint)),

                    new NpgsqlBackendTypeInfo(0, "lseg", NpgsqlDbType.LSeg, DbType.Object, typeof(NpgsqlLSeg),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToLSeg)),

                    new NpgsqlBackendTypeInfo(0, "path", NpgsqlDbType.Path, DbType.Object, typeof(NpgsqlPath),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToPath)),

                    new NpgsqlBackendTypeInfo(0, "box", NpgsqlDbType.Box, DbType.Object, typeof(NpgsqlBox),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToBox)),

                    new NpgsqlBackendTypeInfo(0, "circle", NpgsqlDbType.Circle, DbType.Object, typeof(NpgsqlCircle),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToCircle)),

                    new NpgsqlBackendTypeInfo(0, "polygon", NpgsqlDbType.Polygon, DbType.Object, typeof(NpgsqlPolygon),
                                              new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToPolygon)),
                };

                // Attempt to map each type info in the list to an OID on the backend and
                // add each mapped type to the new type mapping object.
                LoadTypesMappings(conn, oidToNameMapping, TypeInfoList);

                // Add this mapping to the per-server-version cache so we don't have to
                // do these expensive queries on every connection startup.
                BackendTypeMappingCache.Add(conn.ServerVersion, oidToNameMapping);

                return(oidToNameMapping);
            }
        }
示例#17
0
 public MyInt32TypeHandlerResolver(NpgsqlConnector connector, MyInt32TypeHandlerResolverFactory factory)
 => _handler = new MyInt32Handler(connector.DatabaseInfo.GetPostgresTypeByName("integer"), factory);
示例#18
0
 /// <inheritdoc />
 public override NpgsqlTypeHandler <TimeSpan> Create(PostgresType postgresType, NpgsqlConnector conn)
 => conn.DatabaseInfo.HasIntegerDateTimes      // Check for the legacy floating point timestamps feature
         ? new TimeHandler(postgresType)
         : throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
示例#19
0
 public CitextToStringTypeHandlerResolver(NpgsqlConnector connector)
 {
     _connector    = connector;
     _pgCitextType = connector.DatabaseInfo.GetPostgresTypeByName("citext");
 }
示例#20
0
 public MappingKey(NpgsqlConnector conn)
 {
     Version          = conn.ServerVersion;
     UseExtendedTypes = conn.UseExtendedTypes;
 }
示例#21
0
 /// <summary>
 /// Creates a type handler.
 /// </summary>
 public abstract NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn);
示例#22
0
 public override NpgsqlTypeHandler <object[]> Create(PostgresType pgType, NpgsqlConnector conn)
 => new RecordHandler(pgType, conn.TypeMapper);
示例#23
0
 // Check for the legacy floating point timestamps feature
 public override NpgsqlTypeHandler <LocalTime> Create(PostgresType postgresType, NpgsqlConnector conn)
 => conn.DatabaseInfo.HasIntegerDateTimes
         ? new TimeHandler(postgresType)
         : throw new NotSupportedException($"The deprecated floating-point date/time format is not supported by {nameof(Npgsql)}.");
示例#24
0
 internal ReplicationTuple(NpgsqlConnector connector)
     => (ReadBuffer, _tupleEnumerator) = (connector.ReadBuffer, new(this, connector));
示例#25
0
 /// <inheritdoc />
 public override NpgsqlTypeHandler <DateTime> Create(PostgresType postgresType, NpgsqlConnector conn)
 => new DateHandler(postgresType, conn.ConvertInfinityDateTime);
示例#26
0
 public override NpgsqlTypeHandler <string> Create(PostgresType postgresType, NpgsqlConnector conn)
 => new LTxtQueryHandler(postgresType, conn);
示例#27
0
        void BindType(NpgsqlTypeMapping mapping, NpgsqlConnector connector, bool externalCall)
        {
            // Binding can occur at two different times:
            // 1. When a user adds a mapping for a specific connection (and exception should bubble up to them)
            // 2. When binding the global mappings, in which case we want to log rather than throw
            // (i.e. missing database type for some unused defined binding shouldn't fail the connection)

            var pgName = mapping.PgTypeName;

            PostgresType?pgType;

            if (pgName.IndexOf('.') > -1)
            {
                DatabaseInfo.ByFullName.TryGetValue(pgName, out pgType);                    // Full type name with namespace
            }
            else if (DatabaseInfo.ByName.TryGetValue(pgName, out pgType) && pgType is null) // No dot, partial type name
            {
                // If the name was found but the value is null, that means that there are
                // two db types with the same name (different schemas).
                // Try to fall back to pg_catalog, otherwise fail.
                if (!DatabaseInfo.ByFullName.TryGetValue($"pg_catalog.{pgName}", out pgType))
                {
                    var msg = $"More than one PostgreSQL type was found with the name {mapping.PgTypeName}, please specify a full name including schema";
                    if (externalCall)
                    {
                        throw new ArgumentException(msg);
                    }
                    Log.Debug(msg);
                    return;
                }
            }

            if (pgType is null)
            {
                var msg = $"A PostgreSQL type with the name {mapping.PgTypeName} was not found in the database";
                if (externalCall)
                {
                    throw new ArgumentException(msg);
                }
                Log.Debug(msg);
                return;
            }
            if (pgType is PostgresDomainType)
            {
                var msg = "Cannot add a mapping to a PostgreSQL domain type";
                if (externalCall)
                {
                    throw new NotSupportedException(msg);
                }
                Log.Debug(msg);
                return;
            }

            var handler = mapping.TypeHandlerFactory.CreateNonGeneric(pgType, connector.Connection !);

            BindType(handler, pgType, mapping.NpgsqlDbType, mapping.DbTypes, mapping.ClrTypes);

            if (!externalCall)
            {
                return;
            }

            foreach (var domain in DatabaseInfo.DomainTypes)
            {
                if (domain.BaseType.OID == pgType.OID)
                {
                    _byOID[domain.OID] = handler;
                    if (domain.Array != null)
                    {
                        BindType(handler.CreateArrayHandler(domain.Array), domain.Array);
                    }
                }
            }
        }
示例#28
0
 protected internal LTxtQueryHandler(PostgresType postgresType, NpgsqlConnector connector)
     : base(postgresType, connector)
 {
 }
示例#29
0
 /// <inheritdoc />
 protected internal TextHandler(PostgresType postgresType, NpgsqlConnector connector)
     : this(postgresType, connector.TextEncoding)
 {
 }
示例#30
0
 internal UnknownTypeHandler(NpgsqlConnection connection) : base(connection)
 {
     _connector   = connection.Connector;
     PostgresType = UnknownBackendType.Instance;
 }