Exemple #1
0
 /// <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;
    }
Exemple #3
0
 // 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);
Exemple #4
0
 /// <inheritdoc />
 public BitStringArrayHandler(PostgresType postgresType, BitStringHandler elementHandler, ArrayNullabilityMode arrayNullabilityMode)
     : base(postgresType, elementHandler, arrayNullabilityMode)
 {
 }
Exemple #5
0
 public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
 => new ArrayHandler <ArrayHandler <uint> >(pgArrayType, this, arrayNullabilityMode);
Exemple #6
0
 /// <inheeritdoc />
 public override NpgsqlTypeHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
 => new ArrayHandlerWithPsv <TDefault, TPsv>(pgArrayType, this, arrayNullabilityMode);
Exemple #7
0
 public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode)
 => new ArrayHandler <ArrayHandler <uint> >(arrayBackendType, this, arrayNullabilityMode);
Exemple #8
0
        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);
            }
        }
Exemple #9
0
 /// <inheritdoc />
 public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode)
 => throw new NotSupportedException();
Exemple #10
0
 /// <inheritdoc />
 public override ArrayHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
 => new ArrayHandler <NpgsqlRange <TElement> >(pgArrayType, this, arrayNullabilityMode);
Exemple #11
0
 /// <inheritdoc />
 public override ArrayHandler CreateArrayHandler(PostgresArrayType pgArrayType, ArrayNullabilityMode arrayNullabilityMode)
 => new ArrayHandler <TDefault>(pgArrayType, this, arrayNullabilityMode);
Exemple #12
0
 /// <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);