internal ParseMessage Populate(QueryDetails queryDetails, TypeHandlerRegistry typeHandlerRegistry) { _state = State.WroteNothing; ParameterTypeOIDs.Clear(); Query = queryDetails.Sql; Statement = queryDetails.PreparedStatementName ?? ""; foreach (var inputParam in queryDetails.InputParameters) { inputParam.ResolveHandler(typeHandlerRegistry); ParameterTypeOIDs.Add(inputParam.Handler.OID); } return this; }
internal ParseMessage Populate(NpgsqlStatement statement, TypeHandlerRegistry typeHandlerRegistry) { _state = State.WroteNothing; ParameterTypeOIDs.Clear(); Query = statement.SQL; Statement = statement.PreparedStatementName ?? ""; foreach (var inputParam in statement.InputParameters) { inputParam.ResolveHandler(typeHandlerRegistry); ParameterTypeOIDs.Add(inputParam.Handler.OID); } return this; }
internal BindMessage Populate(TypeHandlerRegistry typeHandlerRegistry, List<NpgsqlParameter> inputParameters, string portal="", string statement="") { Contract.Requires(typeHandlerRegistry != null); Contract.Requires(inputParameters != null && inputParameters.All(p => p.IsInputDirection)); Contract.Requires(portal != null); Contract.Requires(statement != null); AllResultTypesAreUnknown = false; UnknownResultTypeList = null; Portal = portal; Statement = statement; InputParameters = inputParameters; _state = State.WroteNothing; _paramIndex = 0; _wroteParamLen = false; return this; }
internal RowDescriptionMessage Load(NpgsqlBuffer buf, TypeHandlerRegistry typeHandlerRegistry) { _fields.Clear(); _nameIndex.Clear(); _caseInsensitiveNameIndex.Clear(); var numFields = buf.ReadInt16(); for (var i = 0; i != numFields; ++i) { // TODO: Recycle var field = new FieldDescription { Name = buf.ReadNullTerminatedString(), TableOID = buf.ReadUInt32(), ColumnAttributeNumber = buf.ReadInt16(), OID = buf.ReadUInt32(), TypeSize = buf.ReadInt16(), TypeModifier = buf.ReadInt32(), FormatCode = (FormatCode)buf.ReadInt16() }; // If we get the exact unknown type in return, it was a literal string written in the query string field.Handler = typeHandlerRegistry[field.OID]; _fields.Add(field); if (!_nameIndex.ContainsKey(field.Name)) { _nameIndex.Add(field.Name, i); if (!_caseInsensitiveNameIndex.ContainsKey(field.Name)) { _caseInsensitiveNameIndex.Add(field.Name, i); } } } return(this); }
/// <summary> /// Instantiate the type handler. If it has a constructor that accepts a TypeHandlerRegistry, use that to allow /// the handler to make connector-specific adjustments. Otherwise (the normal case), use the default constructor. /// </summary> /// <param name="registry"></param> /// <returns></returns> TypeHandler InstantiateHandler(TypeHandlerRegistry registry) { Debug.Assert(HandlerType != null); if (_ctorWithRegistry == null && _ctorWithoutRegistry == null) { var ctors = HandlerType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); _ctorWithRegistry = ( from c in ctors let p = c.GetParameters() where p.Length == 2 && p[0].ParameterType == typeof(PostgresType) && p[1].ParameterType == typeof(TypeHandlerRegistry) select c ).FirstOrDefault(); if (_ctorWithRegistry == null) { _ctorWithoutRegistry = ( from c in ctors let p = c.GetParameters() where p.Length == 1 && p[0].ParameterType == typeof(PostgresType) select c ).FirstOrDefault(); if (_ctorWithoutRegistry == null) { throw new Exception($"Type handler type {HandlerType.Name} does not have an appropriate constructor"); } } } if (_ctorWithRegistry != null) { return((TypeHandler)_ctorWithRegistry.Invoke(new object[] { this, registry })); } Debug.Assert(_ctorWithoutRegistry != null); return((TypeHandler)_ctorWithoutRegistry.Invoke(new object[] { this })); }
NpgsqlDbColumn LoadColumnDefinition(NpgsqlDataReader reader, TypeHandlerRegistry registry) { // Note: we don't set ColumnName and BaseColumnName. These should always contain the // column alias rather than the table column name (i.e. in case of "SELECT foo AS foo_alias"). // It will be set later. var column = new NpgsqlDbColumn { AllowDBNull = !reader.GetBoolean(reader.GetOrdinal("attnotnull")), BaseCatalogName = _connection.Database, BaseSchemaName = reader.GetString(reader.GetOrdinal("nspname")), BaseServerName = _connection.Host, BaseTableName = reader.GetString(reader.GetOrdinal("relname")), ColumnOrdinal = reader.GetInt32(reader.GetOrdinal("attnum")) - 1, ColumnAttributeNumber = (short)(reader.GetInt16(reader.GetOrdinal("attnum")) - 1), IsKey = reader.GetBoolean(reader.GetOrdinal("isprimarykey")), IsReadOnly = !reader.GetBoolean(reader.GetOrdinal("is_updatable")), IsUnique = reader.GetBoolean(reader.GetOrdinal("isunique")), DataTypeName = reader.GetString(reader.GetOrdinal("typname")), TableOID = reader.GetFieldValue <uint>(reader.GetOrdinal("attrelid")), TypeOID = reader.GetFieldValue <uint>(reader.GetOrdinal("typoid")) }; column.PostgresType = registry.PostgresTypes.ByOID[column.TypeOID]; var defaultValueOrdinal = reader.GetOrdinal("default"); column.DefaultValue = reader.IsDBNull(defaultValueOrdinal) ? null : reader.GetString(defaultValueOrdinal); column.IsAutoIncrement = reader.GetBoolean(reader.GetOrdinal("isidentity")) || column.DefaultValue != null && column.DefaultValue.StartsWith("nextval("); ColumnPostConfig(column, reader.GetInt32(reader.GetOrdinal("typmod"))); return(column); }
internal void Bind(TypeHandlerRegistry registry) { ResolveHandler(registry); Contract.Assert(Handler != null); FormatCode = Handler.PreferTextWrite ? FormatCode.Text : FormatCode.Binary; IsBound = true; }
internal void Activate(TypeHandlerRegistry registry, IEnumHandlerFactory handlerFactory) => Activate(registry, handlerFactory.Create(this));
public TimeStampTzHandler(TypeHandlerRegistry registry) : base(registry) { }
internal void ResolveHandler(TypeHandlerRegistry registry) { if (Handler != null) { return; } if (_npgsqlDbType.HasValue) { Handler = registry[_npgsqlDbType.Value, SpecificType]; } else if (_dbType.HasValue) { Handler = registry[_dbType.Value]; } else if (_value != null) { Handler = registry[_value]; } else { throw new InvalidOperationException($"Parameter '{ParameterName}' must have its value set"); } }
internal void Activate(TypeHandlerRegistry registry, ICompositeHandlerFactory factory) => Activate(registry, factory.Create(this, RawFields, registry));
internal UnrecognizedTypeHandler(TypeHandlerRegistry registry) : base(UnrecognizedBackendType, registry) { }
internal TextHandler(IBackendType backendType, TypeHandlerRegistry registry) : base(backendType) { _encoding = registry.Connector.TextEncoding; }
internal void ResolveHandler(TypeHandlerRegistry registry) { if (Handler != null) { return; } if (_npgsqlDbType.HasValue) { Handler = registry[_npgsqlDbType.Value, EnumType]; } else if (_dbType.HasValue) { Handler = registry[_dbType.Value]; } else if (_value != null) { Handler = registry[_value]; } else { Handler = registry[NpgsqlDbType.Text]; } }
internal CompositeHandler(PostgresType postgresType, INpgsqlNameTranslator nameTranslator, List <RawCompositeField> rawFields, TypeHandlerRegistry registry) : base(postgresType) { _nameTranslator = nameTranslator; // At this point the composite handler nows about the fields, but hasn't yet resolved the // type OIDs to their type handlers. This is done only very late upon first usage of the handler, // allowing composite types to be registered and activated in any order regardless of dependencies. _rawFields = rawFields; _registry = registry; }
public ICompositeHandler Create(PostgresType backendType, List <RawCompositeField> rawFields, TypeHandlerRegistry registry) => new CompositeHandler <T>(backendType, _nameTranslator, rawFields, registry);
public RecordHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType) { _registry = registry; }
internal abstract TypeHandler Activate(TypeHandlerRegistry registry);
internal UnrecognizedTypeHandler(TypeHandlerRegistry registry) : base(UnrecognizedBackendType, registry) {}
internal HstoreHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType) { _textHandler = new TextHandler(postgresType, registry); }
internal void ResolveHandler(TypeHandlerRegistry registry) { if (Handler != null) { return; } if (_npgsqlDbType.HasValue) { Handler = registry[_npgsqlDbType.Value, EnumType]; } else if (_dbType.HasValue) { Handler = registry[_dbType.Value]; } else if (!IsNull) { Handler = registry[_value]; } else { Handler = registry.UnrecognizedTypeHandler; } }
internal override TypeHandler Activate(TypeHandlerRegistry registry) { // Composites need to be mapped by the user with an explicit mapping call (MapComposite or MapCompositeGlobally). // If we're here the enum hasn't been mapped to a CLR type and we should activate it as text. throw new Exception($"Composite PostgreSQL type {Name} must be mapped before use"); }
public ICompositeHandler Create(IBackendType backendType, TypeHandlerRegistry registry) => new CompositeHandler <T>(backendType, _nameTranslator, registry);
public DateHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType) { _convertInfinityDateTime = registry.Connector.ConvertInfinityDateTime; }
public TimeStampTzHandler(IBackendType backendType, TypeHandlerRegistry registry) : base(backendType, registry) { }
public RecordHandler(IBackendType backendType, TypeHandlerRegistry registry) : base(backendType) { _registry = registry; }
public DateHandler(TypeHandlerRegistry registry) { _convertInfinityDateTime = registry.Connector.ConvertInfinityDateTime; }
public TimeStampTzHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType, registry) { }
internal JsonbHandler(IBackendType backendType, TypeHandlerRegistry registry) : base(backendType) { _textHandler = new TextHandler(backendType, registry); }
internal CompositeHandler(IBackendType backendType, INpgsqlNameTranslator nameTranslator, TypeHandlerRegistry registry) : base(backendType) { _nameTranslator = nameTranslator; _registry = registry; }
public TimeHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType) { // Check for the legacy floating point timestamps feature, defaulting to integer timestamps _integerFormat = !registry.Connector.BackendParams.TryGetValue("integer_datetimes", out var s) || s == "on"; }
public TimeHandler(TypeHandlerRegistry registry) { _integerFormat = registry.Connector.BackendParams["integer_datetimes"] == "on"; }
internal JsonbHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType, registry) { }
public TimeStampHandler(TypeHandlerRegistry registry) { _integerFormat = registry.Connector.BackendParams["integer_datetimes"] == "on"; _convertInfinityDateTime = registry.Connector.ConvertInfinityDateTime; }
#pragma warning restore CA2222 // Do not decrease inherited member visibility internal override TypeHandler Activate(TypeHandlerRegistry registry) { throw new NotSupportedException("Cannot activate the unknown type"); }
internal void ResolveHandler(TypeHandlerRegistry registry) { if (Handler != null) { return; } if (_npgsqlDbType.HasValue) { Handler = registry[_npgsqlDbType.Value, EnumType]; } else if (_dbType.HasValue) { Handler = registry[_dbType.Value]; } else if (_value != null) { Handler = registry[_value]; } else { throw new InvalidOperationException(string.Format("Parameter '{0}' must have its value set", ParameterName)); } }
internal ParseMessage Populate(string sql, string statementName, List <NpgsqlParameter> inputParameters, TypeHandlerRegistry typeHandlerRegistry) { ParameterTypeOIDs.Clear(); Query = sql; Statement = statementName; foreach (var inputParam in inputParameters) { inputParam.ResolveHandler(typeHandlerRegistry); ParameterTypeOIDs.Add(inputParam.Handler.PostgresType.OID); } return(this); }
internal TextHandler(PostgresType postgresType, TypeHandlerRegistry registry) : base(postgresType) { _encoding = registry.Connector.TextEncoding; }
public DateHandler(IBackendType backendType, TypeHandlerRegistry registry) : base(backendType) { _convertInfinityDateTime = registry.Connector.ConvertInfinityDateTime; }