コード例 #1
0
 ZonedDateTime INpgsqlSimpleTypeHandler <ZonedDateTime> .Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     try
     {
         if (_integerFormat)
         {
             var value = buf.ReadInt64();
             if (value == long.MaxValue || value == long.MinValue)
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
         else
         {
             var value = buf.ReadDouble();
             if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
     }
     catch (DateTimeZoneNotFoundException e)
     {
         throw new NpgsqlSafeReadException(e);
     }
 }
コード例 #2
0
ファイル: TimestampTzHandler.cs プロジェクト: zhnc/npgsql
 ZonedDateTime INpgsqlSimpleTypeHandler <ZonedDateTime> .Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     try
     {
         if (_integerFormat)
         {
             var value = buf.ReadInt64();
             if (value == long.MaxValue || value == long.MinValue)
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
         else
         {
             var value = buf.ReadDouble();
             if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
             {
                 throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
             }
             return(TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]));
         }
     }
     catch (TimeZoneNotFoundException) when(string.Equals(buf.Connection.Timezone, "localtime", StringComparison.OrdinalIgnoreCase))
     {
         throw new NpgsqlSafeReadException(
                   new TimeZoneNotFoundException(
                       "The special PostgreSQL timezone 'localtime' is not supported when reading values of type 'timestamp with time zone'. " +
                       "Please specify a real timezone in 'postgresql.conf' on the server, or set the 'PGTZ' environment variable on the client."));
     }
     catch (TimeZoneNotFoundException e)
     {
         throw new NpgsqlSafeReadException(e);
     }
 }
コード例 #3
0
 public override void Write(Instant value, NpgsqlWriteBuffer buf, NpgsqlParameter parameter)
 {
     if (_integerFormat)
     {
         TimestampHandler.WriteInteger(value, buf);
     }
     else
     {
         TimestampHandler.WriteDouble(value, buf);
     }
 }
コード例 #4
0
        public override Instant Read(NpgsqlReadBuffer buf, int len, FieldDescription?fieldDescription = null)
        {
            var value = buf.ReadInt64();

            if (_convertInfinityDateTime)
            {
                if (value == long.MaxValue)
                {
                    return(Instant.MaxValue);
                }
                if (value == long.MinValue)
                {
                    return(Instant.MinValue);
                }
            }
            return(TimestampHandler.Decode(value));
        }
コード例 #5
0
        public override void Write(Instant value, NpgsqlWriteBuffer buf, NpgsqlParameter?parameter)
        {
            if (_convertInfinityDateTime)
            {
                if (value == Instant.MaxValue)
                {
                    buf.WriteInt64(long.MaxValue);
                    return;
                }

                if (value == Instant.MinValue)
                {
                    buf.WriteInt64(long.MinValue);
                    return;
                }
            }
            TimestampHandler.WriteInteger(value, buf);
        }
コード例 #6
0
 public override Instant Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
 {
     if (_integerFormat)
     {
         var value = buf.ReadInt64();
         if (value == long.MaxValue || value == long.MinValue)
         {
             throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
         }
         return(TimestampHandler.Decode(value));
     }
     else
     {
         var value = buf.ReadDouble();
         if (double.IsPositiveInfinity(value) || double.IsNegativeInfinity(value))
         {
             throw new NpgsqlSafeReadException(new NotSupportedException("Infinity values not supported for timestamp with time zone"));
         }
         return(TimestampHandler.Decode(value));
     }
 }