Beispiel #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
Beispiel #2
0
        }         // get

        /*
        ** Name: get
        **
        ** Description:
        **	Generate an SqlEx exception from an ErrInfo constant
        **	and another SqlEx exception.  The existing SqlEx
        **	exception is chained to the SqlEx exception created
        **	from the error information.
        **
        ** Input:
        **	err	    ErrInfo constant.
        **	ex	    Associated exception,
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	SqlEx	    The new exception object.
        **
        ** History:
        **	20-Apr-00 (gordy)
        **	    Created.
        **	11-Sep-02 (gordy)
        **	    Renamed class to remove specific product reference.
        */

        public static SqlEx get(ErrInfo err, SqlEx ex)
        {
            SqlEx ex_list = get(err);

            ex_list.setNextException(ex);
            return(ex_list);
        }         // get
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
0
        getShort()
        {
            short value;

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

            return(value);
        }         // getShort
Beispiel #10
0
        getLong()
        {
            long value;

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

            return(value);
        }         // getLong
Beispiel #11
0
        getDouble()
        {
            double value;

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

            return(value);
        }         // getDouble
Beispiel #12
0
        getDecimal()
        {
            Decimal value;

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

            return(value);
        }         // getDecimal
Beispiel #13
0
        getByte()
        {
            byte value;

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

            return(value);
        }         // getByte
Beispiel #14
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
Beispiel #15
0
        getInt()
        {
            int value;

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

            return(value);
        }         // getInt
Beispiel #16
0
        getFloat()
        {
            float value;

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

            return(value);
        }         // getFloat
Beispiel #17
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
Beispiel #18
0
 cnvtIS2Rdr(InputStream stream)
 {
     try
     {
         return(charSet.getISR(stream));
     }
     catch (Exception ex)                                // Should not happen!
     {
         throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex);
     }
 } // cnvtIS2Rdr
Beispiel #19
0
        trace(ITrace itrace)
        {
            SqlEx ex = this;

            //			for( SqlEx ex = this; ex != null; ex = (SqlEx)ex.getNextException() )
            {
                //				itrace.write( "Exception: " + ex.getSQLState() + ", 0x" +
                //					Integer.toHexString( ex.getErrorCode() ) );
                itrace.write("  Message: " + ex.Message);
            }
            return;
        }
Beispiel #20
0
 checkAccess()
 {
     lock (this)
     {
         if (active)
         {
             throw SqlEx.get(ERR_GC401C_BLOB_DONE);
         }
         active = true;
     }
     return;
 }         // checkAccess
Beispiel #21
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
Beispiel #22
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
Beispiel #23
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
Beispiel #24
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
Beispiel #25
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
Beispiel #26
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
Beispiel #27
0
        getBinary()
        {
            checkAccess();

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

            if (stream is InputStream)
            {
                return((InputStream)stream);
            }
            else
            {
                throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
            }
        }         // getBinary
Beispiel #28
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
Beispiel #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
Beispiel #30
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
Beispiel #31
0
 /*
 ** Name: get
 **
 ** Description:
 **	Generate an SqlEx exception from an message, SQLState,
 **	and a native code.  The general exception is
 **	converted into an SqlEx exception and chained to the
 **	SqlEx exception created from the error information.
 **
 ** Input:
 **	err	    ErrInfo constant
 **	ex	    Associated exception.
 **
 ** Ouptut:
 **	None.
 **
 ** Returns:
 **	SqlEx	    The new exception object.
 **
 ** History:
 **	09-Dec-03 (thoda04)
 **	    Created.
 */
 public static SqlEx get( SqlEx ex, Exception exAddition )
 {
     ex.setNextException( exAddition );
     return ex;
 }
Beispiel #32
0
 /*
 ** Name: get
 **
 ** Description:
 **	Generate an SqlEx exception from an ErrInfo constant
 **	and another SqlEx exception.  The existing SqlEx
 **	exception is chained to the SqlEx exception created
 **	from the error information.
 **
 ** Input:
 **	err	    ErrInfo constant.
 **	ex	    Associated exception,
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	SqlEx	    The new exception object.
 **
 ** History:
 **	20-Apr-00 (gordy)
 **	    Created.
 **	11-Sep-02 (gordy)
 **	    Renamed class to remove specific product reference.
 */
 public static SqlEx get( ErrInfo err, SqlEx ex )
 {
     SqlEx ex_list = get( err );
     ex_list.setNextException( ex );
     return( ex_list );
 }