/// <inheritdoc /> protected ArrayHandler(PostgresType arrayPostgresType, NpgsqlTypeHandler elementHandler, ArrayNullabilityMode arrayNullabilityMode, int lowerBound = 1) : base(arrayPostgresType) { LowerBound = lowerBound; ElementHandler = elementHandler; ArrayNullabilityMode = arrayNullabilityMode; }
internal NodaTimeTypeHandlerResolver(NpgsqlConnector connector) { _databaseInfo = connector.DatabaseInfo; _timestampHandler = LegacyTimestampBehavior ? new LegacyTimestampHandler(PgType("timestamp without time zone")) : new TimestampHandler(PgType("timestamp without time zone")); _timestampTzHandler = LegacyTimestampBehavior ? new LegacyTimestampTzHandler(PgType("timestamp with time zone")) : new TimestampTzHandler(PgType("timestamp with time zone")); _dateHandler = new DateHandler(PgType("date")); _timeHandler = new TimeHandler(PgType("time without time zone")); _timeTzHandler = new TimeTzHandler(PgType("time with time zone")); _intervalHandler = new IntervalHandler(PgType("interval")); // Note that the range handlers are absent on some pseudo-PostgreSQL databases (e.g. CockroachDB), and multirange types // were only introduced in PG14. So we resolve these lazily. _arrayNullabilityMode = connector.Settings.ArrayNullabilityMode; }
// BitString requires a special array handler which returns bool or BitArray /// <inheritdoc /> public override ArrayHandler CreateArrayHandler(PostgresArrayType backendType, ArrayNullabilityMode arrayNullabilityMode) => new BitStringArrayHandler(backendType, this, arrayNullabilityMode);
/// <inheritdoc /> public BitStringArrayHandler(PostgresType postgresType, BitStringHandler elementHandler, ArrayNullabilityMode arrayNullabilityMode) : base(postgresType, elementHandler, arrayNullabilityMode) { }
public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler <ArrayHandler <uint> >(pgArrayType, this, arrayNullabilityMode);
/// <inheeritdoc /> public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandlerWithPsv <TDefault, TPsv>(pgArrayType, this, arrayNullabilityMode);
public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler <ArrayHandler <uint> >(arrayBackendType, this, arrayNullabilityMode);
public async Task ValueTypeArrayNullabilities(ArrayNullabilityMode mode) { using var pool = CreateTempPool(new NpgsqlConnectionStringBuilder(ConnectionString) { ArrayNullabilityMode = mode }, out var connectionString); await using var conn = await OpenConnectionAsync(connectionString); await using var cmd = new NpgsqlCommand("SELECT onedim, twodim FROM (VALUES" + "('{1, 2, 3, 4}'::int[],'{{1, 2},{3, 4}}'::int[][])," + "('{5, NULL, 6, 7}'::int[],'{{5, NULL},{6, 7}}'::int[][])" + ") AS x(onedim,twodim)", conn); await using var reader = await cmd.ExecuteReaderAsync(); switch (mode) { case ArrayNullabilityMode.Never: reader.Read(); var value = reader.GetValue(0); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int[]))); Assert.That(value, Is.EqualTo(new [] { 1, 2, 3, 4 })); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(reader.GetValue(1).GetType(), Is.EqualTo(typeof(int[, ]))); Assert.That(reader.GetValue(1), Is.EqualTo(new [, ] { { 1, 2 }, { 3, 4 } })); reader.Read(); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(() => reader.GetValue(0), Throws.Exception.TypeOf <InvalidOperationException>()); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(() => reader.GetValue(1), Throws.Exception.TypeOf <InvalidOperationException>()); break; case ArrayNullabilityMode.Always: reader.Read(); value = reader.GetValue(0); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[]))); Assert.That(value, Is.EqualTo(new int?[] { 1, 2, 3, 4 })); value = reader.GetValue(1); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[, ]))); Assert.That(value, Is.EqualTo(new int?[, ] { { 1, 2 }, { 3, 4 } })); reader.Read(); value = reader.GetValue(0); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[]))); Assert.That(value, Is.EqualTo(new int?[] { 5, null, 6, 7 })); value = reader.GetValue(1); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[, ]))); Assert.That(value, Is.EqualTo(new int?[, ] { { 5, null }, { 6, 7 } })); break; case ArrayNullabilityMode.PerInstance: reader.Read(); value = reader.GetValue(0); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int[]))); Assert.That(value, Is.EqualTo(new [] { 1, 2, 3, 4 })); value = reader.GetValue(1); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int[, ]))); Assert.That(value, Is.EqualTo(new [, ] { { 1, 2 }, { 3, 4 } })); reader.Read(); value = reader.GetValue(0); Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[]))); Assert.That(value, Is.EqualTo(new int?[] { 5, null, 6, 7 })); value = reader.GetValue(1); Assert.That(reader.GetFieldType(1), Is.EqualTo(typeof(Array))); Assert.That(value.GetType(), Is.EqualTo(typeof(int?[, ]))); Assert.That(value, Is.EqualTo(new int?[, ] { { 5, null }, { 6, 7 } })); break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } }
/// <inheritdoc /> public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode) => throw new NotSupportedException();
/// <inheritdoc /> public override ArrayHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler <NpgsqlRange <TElement> >(pgArrayType, this, arrayNullabilityMode);
/// <inheritdoc /> public override ArrayHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler <TDefault>(pgArrayType, this, arrayNullabilityMode);
/// <inheeritdoc /> public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandlerWithPsv <TDefault, TPsv>(arrayBackendType, this, arrayNullabilityMode);
// BitString requires a special array handler which returns bool or BitArray /// <inheritdoc /> public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode) => new BitStringArrayHandler(pgArrayType, this, arrayNullabilityMode);