Skip to content

Allow mapping C# byte to PostgreSQL smallint #1766

Closed

Description

@roji

PostgreSQL does not have a byte datatype, except for internalchar which is supposed to be internal-only.

Add support for reading and writing smallint as CLR byte. Consider whether this should simply be a standard capability or a plugin.

Originally requested in #1612.

Activity

  1. added this to the milestone on Jan 3, 2018
  2. self-assigned this
    on Jan 3, 2018
  3. Shkarlatov commented on Jan 5, 2018

    @Shkarlatov

    I believe that this should be a standard feature. In plugins you only need to specify the customs types.

  4. YohDeadfall commented on Mar 14, 2018

    @YohDeadfall
    Contributor

    I think that it should be out of the box too since it's a standard CLR type. Could I take the issue, @roji?

  5. roji commented on Mar 14, 2018

    @roji
    MemberAuthor

    Looking at this again I agree that it makes sense to allow this mapping built-in rather than by a plugin.

    Go ahead @YohDeadfall, this should be trivial.

  6. assigned and unassigned on Mar 14, 2018
  7. YohDeadfall commented on Mar 14, 2018

    @YohDeadfall
    Contributor

    Wow! It was really trivial because we already have it for a few years.

    [TypeMapping("int2", NpgsqlDbType.Smallint, new[] { DbType.Int16, DbType.Byte, DbType.SByte }, new[] { typeof(short), typeof(byte), typeof(sbyte) }, DbType.Int16)]
    class Int16Handler : NpgsqlSimpleTypeHandler<short>,
    INpgsqlSimpleTypeHandler<byte>, INpgsqlSimpleTypeHandler<sbyte>, INpgsqlSimpleTypeHandler<int>, INpgsqlSimpleTypeHandler<long>,
    INpgsqlSimpleTypeHandler<float>, INpgsqlSimpleTypeHandler<double>, INpgsqlSimpleTypeHandler<decimal>,
    INpgsqlSimpleTypeHandler<string>
    {
    #region Read
    public override short Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
    => buf.ReadInt16();
    byte INpgsqlSimpleTypeHandler<byte>.Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
    => checked((byte)Read(buf, len, fieldDescription));
    sbyte INpgsqlSimpleTypeHandler<sbyte>.Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
    => checked((sbyte)Read(buf, len, fieldDescription));

  8. roji commented on Mar 14, 2018

    @roji
    MemberAuthor

    Oops, that's embarrassing :) I must have totally forgotten about this...

    Well, that was the easiest issue resolution ever. I'll go make sure this is also supported at the EF Core level.

  9. removed this from the 4.0 milestone on Mar 14, 2018
  10. Brar commented on Mar 14, 2018

    @Brar
    Member

    Haha, I was actually wondering what you're talking about since it couldn't possibly be a feature that is implemented and documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions