Ejemplo n.º 1
0
 getString()
 {
     /*
     ** Do conversion to check for valid format.
     */
     return(SqlDates.formatDate(get(null), false));
 }         // getString
Ejemplo n.º 2
0
        getDate(TimeZone tz)
        {
            String str = getString().Trim();

            return((tz == null) ? SqlDates.parseDate(str, false)
                                : SqlDates.parseDate(str, tz));
        }         // getDate
Ejemplo n.º 3
0
 getTime(TimeZone tz)
 {
     /*
     ** Strip date component by re-formatting as time value.
     */
     return(SqlDates.parseTime(SqlDates.formatTime(get(tz), false), false));
 }         // getTime
Ejemplo n.º 4
0
        getTimestamp(TimeZone tz)
        {
            String str = getString().Trim();

            return((tz == null) ? SqlDates.parseTimestamp(str, false)
                                : SqlDates.parseTimestamp(str, tz));
        }
Ejemplo n.º 5
0
 getTime(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
             value.Length == SqlDates.D_FMT.Length)                      // Date only
         {
             /*
             ** There is no time component, so create a time 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.getEpochTime()
                                         : SqlDates.parseTime(SqlDates.T_EPOCH, tz));
         }
         else if (value.Length == SqlDates.TS_FMT.Length)                        // Timestamp
         {
             /*
             ** Remove the date component but retain correct time:
             **
             ** 1.  Convert to GMT timestamp using TZ for current connection.
             ** 2.  Re-format as time only using local TZ to get local time.
             ** 3.  Generate Time value using requested/local TZ.
             */
             DateTime ts  = SqlDates.parseTimestamp(value, use_gmt);
             String   str = SqlDates.formatTime(ts, false);
             return((osql_dates && tz != null)
                                         ? SqlDates.parseTime(str, tz)
                                         : SqlDates.parseTime(str, false));
         }
         else                                                                    // Interval
         {
             /*
             ** Can't support intervals with Time 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;
     }
 }         // getTime
Ejemplo n.º 6
0
 get(TimeZone tz)
 {
     /*
     ** Dates should be independent of TZ, but JDBC date values
     ** are stored in UTC.  Use the TZ provided to ensure the
     ** resulting UTC value represents the date in the desired
     ** TZ.  Otherwise, the local default TZ is used.
     */
     return((tz != null) ? SqlDates.parseDate(value, tz)
                                   : SqlDates.parseDate(value, false));
 } // get
Ejemplo n.º 7
0
        set(DateTime value, TimeZone tz)
        {
            // DateTime does not have a null
            //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_TIME:
                /*
                ** DAS parses local time using GMT.
                */
                this.value = SqlDates.formatTime(value, true);
                break;

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

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

                /*
                ** Java applies TZ and DST of 'epoch' date: 1970-01-01.
                ** Ingres applies TZ and DST of todays date, so use
                ** current date to determine explicit TZ offset.
                */
                long millis = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                timezone = (tz != null) ? SqlDates.formatTZ(tz, millis)
                                                                : SqlDates.formatTZ(millis);
                break;
            }

            return;
        }         // set
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
        getString()
        {
            /*
            ** Format using local default TZ for local time.
            ** Nano-seconds must be manually formatted.
            */
            String str = SqlDates.formatTime(get(null), false);

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

            return(str);
        }         // getString
Ejemplo n.º 11
0
        get()
        {
            String value = this.value;

            if (nanos > 0)
            {
                value += SqlDates.formatFrac(nanos);
            }
            if (dbms_type == DBMS_TYPE_TMTZ)
            {
                value += timezone;
            }

            return(value);
        }         // get
Ejemplo n.º 12
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
Ejemplo n.º 13
0
        set(DateTime value, TimeZone tz)
        {
            // DateTime structure can never be null
            //if (value == null)
            //{
            //    setNull();
            //    return;
            //}

            /*
            ** Dates should be independent of TZ, but JDBC date values
            ** are stored in UTC.  Use the TZ provided to ensure the
            ** formatted value represents the date in the desired TZ.
            ** Otherwise, the local default TZ is used.
            */
            setNotNull();
            this.value = (tz != null) ? SqlDates.formatDate(value, tz)
                                                  : SqlDates.formatDate(value, false);

            return;
        }         // set
Ejemplo n.º 14
0
        get(TimeZone tz)
        {
            DateTime time;

            switch (dbms_type)
            {
            case DBMS_TYPE_TIME:
                time = SqlDates.parseTime(value, true);
                time = time.ToLocalTime();
                break;

            case DBMS_TYPE_TMWO:
                /*
                ** Interpret as local time using requested or default timezone.
                */
                time = (tz != null) ? SqlDates.parseTime(value, tz)
                                                        : SqlDates.parseTime(value, false);
                break;

            case DBMS_TYPE_TMTZ:
                /*
                ** TIME WITH TIMEZONE values are local with
                ** explicit timezone offset.
                */
                time = SqlDates.parseTime(value, SqlDates.getTZ(timezone));
                time = time.ToLocalTime();
                break;

            default:       // should never happen since constructor checked
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }              // end switch

            if (nanos > 0)
            {
                TimeSpan span = new TimeSpan(nanos / 100L); // one tick = 100 nanos
                time += span;                               // add the nanos back in
            }

            return(time);
        }         // get
Ejemplo n.º 15
0
        set(String value)
        {
            if (value == null)
            {
                setNull();
            }
            else
            {
                /*
                ** Separate explicit timezone.
                */
                if (dbms_type == DBMS_TYPE_TMTZ)
                {
                    if (value.Length <
                        (SqlDates.T_FMT.Length + SqlDates.TZ_FMT.Length))
                    {
                        throw SqlEx.get(ERR_GC401B_INVALID_DATE);
                    }

                    int offset = value.Length - SqlDates.TZ_FMT.Length;
                    timezone = value.Substring(offset);
                    value    = value.Substring(0, offset);
                }

                /*
                ** Separate fractional seconds.
                */
                if (value.Length > SqlDates.T_FMT.Length)
                {
                    nanos = SqlDates.parseFrac(
                        value.Substring(SqlDates.T_FMT.Length));
                    value = value.Substring(0, SqlDates.T_FMT.Length);
                }

                setNotNull();
                this.value = value;
            }

            return;
        }         // set
Ejemplo n.º 16
0
        get(TimeZone tz)
        {
            DateTime ts;

            switch (dbms_type)
            {
            case DBMS_TYPE_TS:
                /*
                ** DAS formats local time using GMT.
                */
                ts = SqlDates.parseTimestamp(value, true);
                break;

            case DBMS_TYPE_TSWO:
                /*
                ** Interpret as local time in requested or default timezone.
                */
                ts = (tz != null) ? SqlDates.parseTimestamp(value, tz)
                                                          : SqlDates.parseTimestamp(value, false);
                break;

            case DBMS_TYPE_TSTZ:
                /*
                ** Apply explicit timezone.
                */
                ts = SqlDates.parseTimestamp(value, SqlDates.getTZ(timezone));
                break;

            default:                      // should never happen since constructor checked
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }

//			ts.setNanos(nanos);
            if (nanos > 0)
            {
                TimeSpan span = new TimeSpan(nanos / 100L); // one tick = 100 nanos
                ts += span;                                 // add the nanos back in
            }
            return(ts);
        }         // get
Ejemplo n.º 17
0
        setDate(DateTime value, TimeZone tz)
        {
            // DateTime is never null
            //    if ( value == null )
            //	setNull();
            //    else
            {
                /*
                ** The date is stored in GMT such as to have a 0 time for
                ** the local TZ.  Ingres dates are not associated with a
                ** TZ.  Gateways add a 0 time to dates which is assumed to
                ** be in the client TZ.  Timezones can be applied in both
                ** cases to get the actual date in the desired TZ.  Other-
                ** wise, the date in the local TZ is used.
                */
                setNotNull();
                interval   = false;
                this.value = (tz != null) ? SqlDates.formatDate(value, tz)
                                                                : SqlDates.formatDate(value, false);
            }

            return;
        }         // setDate
Ejemplo n.º 18
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
Ejemplo n.º 19
0
 setTimestamp(DateTime ts, TimeZone tz)
 {
     set(ts, tz);
     nanos = SqlDates.getNanos(ts);
     return;
 }         // setTimestamp
Ejemplo n.º 20
0
 getTimestamp(TimeZone tz)
 {
     return((tz == null) ? SqlDates.parseTimestamp(value.Trim(), false)
                         : SqlDates.parseTimestamp(value.Trim(), tz));
 }
Ejemplo n.º 21
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
Ejemplo n.º 22
0
 getDate(TimeZone tz)
 {
     return((tz == null) ? SqlDates.parseDate(value.Trim(), false)
                         : SqlDates.parseDate(value.Trim(), tz));
 }         // getDate
Ejemplo n.º 23
0
 getDate(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
         {
             /*
             ** Ingres permits zero length date literals or 'empty'
             ** dates.  Since does not have any corresponding
             ** date/time concept, we use the date epoch.  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.getEpochDate()
                                         : SqlDates.parseDate(SqlDates.D_EPOCH, tz));
         }
         else if (value.Length == SqlDates.D_FMT.Length)                         // Date only
         {
             /*
             ** The date is stored in GMT such as to have a 0 time for
             ** the target TZ (requested/local).
             */
             return((tz == null) ? SqlDates.parseDate(value, false)
                                         : SqlDates.parseDate(value, tz));
         }
         else if (value.Length == SqlDates.TS_FMT.Length)                        // Timestamp
         {
             /*
             ** Remove the time component but retain correct date:
             **
             ** 1.  Convert to GMT Timestamp using TZ for current connection.
             ** 2.  Format as date only using local TZ to get local date.
             ** 3.  Generate Date value using requested/local timezone.
             */
             DateTime date = SqlDates.parseTimestamp(value, use_gmt);
             String   str  = SqlDates.formatDate(date, false);
             return((osql_dates && tz != null)
                                         ? SqlDates.parseDate(str, tz)
                                         : SqlDates.parseDate(str, false));
         }
         else                    // Interval
         {
             /*
             ** Can't support intervals with Date 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;
     }
 }         // getDate
Ejemplo n.º 24
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