示例#1
0
        set(DateTime value, TimeZone tz)
        {
            //DateTime does not have a null state
            //if (value == null)
            //{
            //    setNull();
            //    return;
            //}

            setNotNull();
            nanos = 0;

            if (value.Kind == DateTimeKind.Utc)              // if UTC, normalize to LOCAL
            {
                value = value.ToLocalTime();
            }

            switch (dbms_type)
            {
            case DBMS_TYPE_TS:
                /*
                ** DAS parses local time using GMT.
                */
                this.value = SqlDates.formatTimestamp(value, true);
                break;

            case DBMS_TYPE_TSWO:
                /*
                ** Format as local time using requested or default timezone.
                */
                this.value = (tz != null) ? SqlDates.formatTimestamp(value, tz)
                                                                  : SqlDates.formatTimestamp(value, false);
                break;

            case DBMS_TYPE_TSTZ:
                /*
                ** Format as local time using requested or default timezone.
                */
                this.value = (tz != null) ? SqlDates.formatTimestamp(value, tz)
                                                                  : SqlDates.formatTimestamp(value, false);

                /*
                ** Get the TZ offset of the target value in the requested
                ** or default timezone.
                */
                timezone = (tz != null) ? SqlDates.formatTZ(tz, value)
                                                                : SqlDates.formatTZ(value);
                break;
            }

            return;
        }         // set
示例#2
0
        setTime(DateTime value, TimeZone tz)
        {
            // DateTime is never null
            //if ( value == null )
            //setNull();
            //else
            {
                /*
                ** The time is stored in GMT.  Timezones are not applied to
                ** Ingres times since they are also stored in GMT.  OpenSQL
                ** times are assumed to be in the client TZ, so timezones
                ** can be applied to store values for specific timezones.
                */
                if (osql_dates && tz != null)
                {
                    /*
                    ** First retrieve the time in the desired TZ.
                    */
                    String str = SqlDates.formatTime(value, tz);

                    /*
                    ** The local TZ will be applied, either by the driver or
                    ** the gateway, during subsequent processing.  We use the
                    ** local TZ to save the desired value so as to cancel the
                    ** future application of the local TZ.
                    */
                    value = SqlDates.parseTime(str, false);
                }

                /*
                ** Produce the correct time value for the current connection.
                **
                ** Ingres only partially supports time only values and adds
                ** the current date to such values.  JDBC specifies that the
                ** date portion for time values should be set to the date
                ** epoch 1970-01-01.  When the current date has a different
                ** daylight savings offset than the epoch, a one hour offset
                ** can occur because of the different GMT offsets applied by
                ** Java and Ingres.  Due to these problems, format the time
                ** as a timestamp to ensure consistent processing.  Note that
                ** formatTimestamp() takes a java.util.Date parameter of which
                ** java.sql.Time is a sub-class.
                */
                setNotNull();
                this.value = SqlDates.formatTimestamp(value, use_gmt);
                interval   = false;
            }

            return;
        }         // setTime
示例#3
0
 setTimestamp(DateTime value, TimeZone tz)
 {
     // DateTime is never null
     //if (value == null)
     //    setNull();
     //else
     if (tz != null)
     {
         setString(SqlDates.formatTimestamp(value, tz));
     }
     else
     {
         setString(SqlDates.formatTimestamp(value, false));
     }
     return;
 }         // setTimestamp
示例#4
0
        getString()
        {
            /*
            ** Do conversion to validate format.
            ** Format using local default TZ for local time.
            ** Nano-seconds must be manually formatted.
            */
            String str = SqlDates.formatTimestamp(get(null), false);

            if (nanos > 0)
            {
                str += SqlDates.formatFrac(nanos);
            }

            return(str);
        }         // getString
示例#5
0
        setTimestamp(DateTime value, TimeZone tz)
        {
            // DateTime is never null
            //if ( value == null )
            //setNull();
            //else
            {
                /*
                ** The timestamp is stored in GMT.  Timezones are not applied to
                ** Ingres timestamps since they are also stored in GMT.  OpenSQL
                ** timestamps are assumed to be in the client TZ, so timezones
                ** can be applied to store values for specific timezones.
                */
                if (osql_dates && tz != null)
                {
                    /*
                    ** First retrieve the timestamp for the desired TZ.
                    */
                    String str = SqlDates.formatTimestamp(value, tz);

                    /*
                    ** The local TZ will be applied, either by the driver or
                    ** the gateway, during subsequent processing.  We use the
                    ** local TZ to save the desired value to cancel the future
                    ** application.
                    */
                    value = SqlDates.parseTimestamp(str, false);
                }

                setNotNull();
                this.value = SqlDates.formatTimestamp(value, use_gmt);
                interval   = false;
            }

            return;
        }         // setTimestamp
示例#6
0
        getTimestamp(TimeZone tz)
        {
            /*
            ** Ingres dates are overloaded with 'empty' date,
            ** date only, timestamp and interval values.  The
            ** first three types are handled explicitly below.
            ** Intervals will either cause an exception while
            ** attempting to parse the value or as the default
            ** action for an unrecognized format.
            */
            try
            {
                if (value.Length == 0)                                                  // Empty date
                {
                    /*
                    ** Create a timstamp EPOCH value.  If no timezone is
                    ** provided, we can return the local epoch constant.
                    ** Otherwise, the epoch value for the requested
                    ** timezone must be generated.
                    */
                    return((tz == null) ? SqlDates.getEpochTimestamp()
                                                : SqlDates.parseTimestamp(SqlDates.TS_EPOCH, tz));
                }
                else if (value.Length == SqlDates.D_FMT.Length)                         // Date only
                {
                    /*
                    ** There is no time component, so convert to timestamp with
                    ** a 0 time component for the requested/local timezone.
                    */
                    DateTime date = (tz == null)
                                                ? SqlDates.parseDate(value, false)
                                                : SqlDates.parseDate(value, tz);
                    return(date);
                }
                else if (value.Length == SqlDates.TS_FMT.Length)                        // Timestamp
                {
                    /*
                    ** Convert to GMT timestamp using TZ for current connection.
                    */
                    DateTime ts = SqlDates.parseTimestamp(value, use_gmt);

                    if (osql_dates && tz != null)
                    {
                        /*
                        ** Effectively, we need to apply time difference
                        ** between local and requested timezones.  First,
                        ** apply local TZ to get local timestamp.  Then
                        ** apply requested TZ to get desired GMT value.
                        */
                        String str = SqlDates.formatTimestamp(ts, false);
                        ts = SqlDates.parseTimestamp(str, tz);
                    }

                    return(ts);
                }
                else                                                                    // Interval
                {
                    /*
                    ** Can't support intervals with Timestamp objects.
                    */
                    throw SqlEx.get(ERR_GC401B_INVALID_DATE);
                }
            }
            catch (SqlEx ex)
            {
                /*
                ** Any parsing error is assumed to be caused by an interval.
                */
                interval = true;
                throw ex;
            }
        }         // getTimestamp
示例#7
0
        getString()
        {
            String str;

            /*
            ** Ingres dates are overloaded with 'empty' date,
            ** date only, timestamp and interval values.  The
            ** raw data string is returned for empty dates and
            ** intervals.  Date only values and timestamps are
            ** parsed/formatted to validate and set timezone.
            ** Intervals will cause an exception if an attempt
            ** is made to parse the value or will be detected
            ** by a mis-match in expected string lengths.
            */
            try
            {
                if (value.Length == 0)                                                  // Empty date
                {
                    /*
                    ** Return the empty date string.
                    */
                    str = value;
                }
                else if (value.Length == SqlDates.D_FMT.Length)                         // Date only
                {
                    /*
                    ** Do conversion to check for valid format (in
                    ** case this is an interval).  Ingres dates are
                    ** indepedent of timezone, so use local TZ.
                    */
                    DateTime dt = SqlDates.parseDate(value, false);
                    str = SqlDates.formatDate(dt, false);
                }
                else if (value.Length == SqlDates.TS_FMT.Length)                        // Timestamp
                {
                    /*
                    ** Convert to GMT using TZ for current connection
                    ** and then to local time using local TZ.
                    */
                    DateTime ts = SqlDates.parseTimestamp(value, use_gmt);
                    str = SqlDates.formatTimestamp(ts, false);
                }
                else                                                                    // Interval
                {
                    /*
                    ** Return the interval string and produce a warning.
                    */
                    interval = true;
                    str      = value;
                }
            }
            catch (SqlEx)
            {
                /*
                ** Any parsing error is assumed to be caused by an interval.
                */
                interval = true;
                str      = value;
            }

            return(str);
        }         // getString