Пример #1
0
        get()
        {
            Object stream = getStream();

//			Reader rdr;

            if (stream == null)
            {
                return(null);
            }
            else
            if (stream is InputStream)
            {
                return(cnvtIS2Rdr((InputStream)stream));
            }
            else
            if (stream is Reader)
            {
                return((Reader)stream);
            }
            else
            {
                throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
            }
        }         // get
Пример #2
0
        setString(String value)
        {
            if (value == null)
            {
                setNull();
            }
            else
            {
                Decimal temp;

                try
                {
                    temp = DecimalParseInvariant(value);
                }
                catch (FormatException /* ex */)
                { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

//				this.value = checkPrecision(temp);
                this.value = temp;
                setNotNull();
            }

            truncated = false;
            return;
        }         // setString
Пример #3
0
        parseOffset(String tzOffset)
        {
            /*
            ** Validate offset format.
            */
            if (
                tzOffset.Length != TZ_FMT.Length ||
                (tzOffset[0] != '+' && tzOffset[0] != '-') ||
                !Char.IsDigit(tzOffset[1]) ||
                !Char.IsDigit(tzOffset[2]) ||
                tzOffset[3] != ':' ||
                !Char.IsDigit(tzOffset[4]) ||
                !Char.IsDigit(tzOffset[5])
                )
            {
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }

            int hours =
                Convert.ToInt32(tzOffset[1] - '0') * 10 +
                Convert.ToInt32(tzOffset[2] - '0');
            int minutes =
                Convert.ToInt32(tzOffset[4] - '0') * 10 +
                Convert.ToInt32(tzOffset[5] - '0');
            int offset = hours * 60 + minutes;

            if (tzOffset[0] == '-')
            {
                offset = -offset;
            }

            return(offset);
        }         // parseOffset
Пример #4
0
        setStream(Object stream)
        {
            lock (this)
            {
                if (stream == null)
                {
                    setNull();
                }
                else
                {
                    if (
                        !(stream is InputStream) &&
                        !(stream is Reader)
                        )
                    {
                        throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
                    }

                    setNotNull();
                    active      = false;
                    this.stream = stream;

                    if (stream is IStreamSource)              // (ByteSegIS and Ucs2SegRdr)
                    {
                        ((IStreamSource)stream).addStreamListener(listener, this);
                    }
                }
            }

            return;
        }         // set
Пример #5
0
        strm2str(Reader inReader, int limit)
        {
            char[]        cb = new char[8192];
            StringBuilder sb = new StringBuilder();
            int           len;

            try
            {
                while ((limit < 0 || sb.Length < limit) &&
                       (len = inReader.read(cb, 0, cb.Length)) >= 0)
                {
                    if (limit >= 0)
                    {
                        len = Math.Min(len, limit - sb.Length);
                    }
                    if (len > 0)
                    {
                        sb.Append(cb, 0, len);
                    }
                }
            }
            catch (IOException)
            {
                throw SqlEx.get(ERR_GC4007_BLOB_IO);
            }
            finally
            {
                try { inReader.close(); }
                catch (IOException) {}
            }

            return(sb.ToString());
        } // strm2str
Пример #6
0
        get(OutputStream os)
        {
            Object stream = getStream();

            if (stream != null)
            {
                if (stream is InputStream)
                {
                    copyIs2Os((InputStream)stream, os);
                }
                else if (stream is Reader)
                {
                    OutputStreamWriter wtr;

                    try { wtr = charSet.getOSW(os); }
                    catch (Exception /* ex */)                          // Should not happen!
                    { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); }

                    copyRdr2Wtr((Reader)stream, wtr);
                }
                else
                {
                    throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
                }
            }
            return;
        }         // get
Пример #7
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
Пример #8
0
        getLong()
        {
            long value;

            try { value = Int64.Parse(getString(length)); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getLong
Пример #9
0
        getDecimal()
        {
            Decimal value;

            try { value = DecimalParseInvariant(getString()); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getDecimal
Пример #10
0
        getDouble()
        {
            double value;

            try { value = Double.Parse(getString(length)); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getDouble
Пример #11
0
 getString(int limit)
 {
     if (limit > length)
     {
         limit = length;
     }
     try { return(charSet.getString(value, 0, limit)); }
     catch (Exception ex)
     { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex); }
 }         // getString
Пример #12
0
        getInt()
        {
            int value;

            try { value = Int32.Parse(getString()); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getInt
Пример #13
0
        getFloat()
        {
            float value;

            try { value = Single.Parse(getString()); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getFloat
Пример #14
0
        getShort()
        {
            short value;

            try { value = Int16.Parse(getString(length)); }
            catch (FormatException /* ex */)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getShort
Пример #15
0
        getByte()
        {
            byte value;

            try { value = Byte.Parse(getString()); }
            catch (FormatException)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

            return(value);
        }         // getByte
Пример #16
0
        setString(String value)
        {
            if (value == null)
            {
                setNull();
            }
            else
            {
                byte[] ba;

                try { ba = charSet.getBytes(value); }
                catch (Exception ex)
                { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex); }

                /*
                ** Normally, ensure() would be used to size the internal
                ** array, possibly allocating a new array.  The problem
                ** is that a new array is already going to be allocated
                ** for Unicode conversion.  Rather than use ensure, which
                ** at best will do nothing and at worst will allocate an
                ** additional array, we simply use the longer of internal
                ** of conversion array.
                */
                if (ba.Length > this.value.Length)
                {
                    /*
                    ** First determine the length of the new string
                    ** (apply limit if applicable).
                    */
                    int length = ba.Length;
                    if (limit >= 0 && length > limit)
                    {
                        length = limit;
                    }

                    /*
                    ** Now replace the internal buffer with the new string.
                    */
                    setNotNull();
                    this.value  = ba;
                    this.length = length;
                }
                else
                {
                    /*
                    ** Since the converted string will fit in the current
                    ** internal buffer, we can just use standard access
                    ** methods to save the string.
                    */
                    clear();
                    put(ba);
                }
            }
            return;
        }         // setString
Пример #17
0
 cnvtIS2Rdr(InputStream stream)
 {
     try
     {
         return(charSet.getISR(stream));
     }
     catch (Exception ex)                                // Should not happen!
     {
         throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex);
     }
 } // cnvtIS2Rdr
Пример #18
0
 checkAccess()
 {
     lock (this)
     {
         if (active)
         {
             throw SqlEx.get(ERR_GC401C_BLOB_DONE);
         }
         active = true;
     }
     return;
 }         // checkAccess
Пример #19
0
        setDouble(double value)
        {
            Decimal temp;

            try { temp = Convert.ToDecimal(value); }
            catch (FormatException /* ex */)
            { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

//			this.value = checkPrecision(temp);
            this.value = temp;
            setNotNull();
            truncated = false;
            return;
        }         // setDouble
Пример #20
0
        SqlInterval(short dbms_type)
            : base(true)
        {
            switch (dbms_type)
            {
            case DBMS_TYPE_INTYM:
            case DBMS_TYPE_INTDS:
                this.dbms_type = dbms_type;
                break;

            default:                            /* Should not happen! */
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }
        }         // SqlInterval
Пример #21
0
        getAsciiStream()
        {
            byte[] bytes;

            try
            {
                System.Text.Encoding ASCIIEncoding = System.Text.Encoding.ASCII;
                bytes = ASCIIEncoding.GetBytes(value);
            }
            catch (Exception)                           // Should not happen!
            { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); }

            return(new ByteArrayInputStream(bytes));
        }         // getAsciiStream
Пример #22
0
        getUnicode(String str)
        {
            byte[] bytes;

            try
            {
                System.Text.Encoding UTF8Encoding = System.Text.Encoding.UTF8;
                bytes = UTF8Encoding.GetBytes(str);
            }
            catch (Exception)                           // Should not happen!
            { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); }

            return(new ByteArrayInputStream(bytes));
        }         // getUnicode
Пример #23
0
        SqlTime(short dbms_type)
            : base(true)
        {
            switch (dbms_type)
            {
            case DBMS_TYPE_TIME:
            case DBMS_TYPE_TMWO:
            case DBMS_TYPE_TMTZ:
                this.dbms_type = dbms_type;
                break;

            default:                            /* Should not happen! */
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }
        }         // SqlTime
Пример #24
0
 setString(String _value)
 {
     if (_value == null)
     {
         setNull();
     }
     else
     {
         setNotNull();
         try { this.Value = BooleanParse(_value); }
         catch (FormatException /* ex */)
         { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }
     }
     return;
 }         // setString
Пример #25
0
        getBinary()
        {
            checkAccess();

            if (stream == null)
            {
                return(null);
            }

            if (stream is InputStream)
            {
                return((InputStream)stream);
            }
            else
            {
                throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
            }
        }         // getBinary
Пример #26
0
        parseDate(String str, TimeZone tz)
        {
            DateTime date;

            if (str.Length != D_FMT.Length)
            {
                throw SqlEx.get(ERR_GC401B_INVALID_DATE);
            }

            lock (df_d_val)
            {
                df_d_val.setTimeZone(tz);
                try { date = df_d_val.parse(str); }
                catch (Exception)
                { throw SqlEx.get(ERR_GC401B_INVALID_DATE); }
            }

            return(date.Date);
        }         // parseDate
Пример #27
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
Пример #28
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
Пример #29
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
Пример #30
0
        setString(String value)
        {
            if (value == null)
            {
                setNull();
            }
            else
            {
                DateTime date;

                /*
                ** Validate format by converting to DateTime.
                */
                try { date = DateTime.Parse(value); }
                catch (Exception /* ignore */)
                { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); }

                setDate(date, null);
            }

            return;
        }         // setString