예제 #1
0
        // pos is 1-based!
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public byte[] getBytes(long pos, int length) throws SQLException
        public sbyte[] getBytes(long pos, int length)
        {
            if (pos <= 0)
            {
                throw new SQLException("Bad position: " + pos);
            }
            int ipos = (int)(pos & 0x7FFFFFFF);

            attribs_.StartOffset   = ipos - 1;
            attribs_.RequestedSize = length;
            attribs_.ReturnCurrentLengthIndicator = 0xF1;
            try
            {
                tempOutput_ = new MemoryStream();
                conn_.retrieveLOBData(attribs_, this);
                tempOutput_.Flush();
                tempOutput_.Close();
                return(tempOutput_.toByteArray());
            }
            catch (IOException io)
            {
                SQLException sql = new SQLException(io.ToString());
                sql.initCause(io);
                throw sql;
            }
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int setString(long pos, String str, int offset, int len) throws SQLException
        public virtual int setString(long pos, string str, int offset, int len)
        {
            if (pos <= 0)
            {
                throw new SQLException("Bad position: " + pos);
            }
            int ipos  = (int)(pos & 0x7FFFFFFF);
            int total = length_ - ipos + 1;

            if (total > len)
            {
                total = len;
            }
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] bytes = com.ibm.jtopenlite.Conv.stringToEBCDICByteArray(str, ccsid_);
                sbyte[] bytes = Conv.stringToEBCDICByteArray(str, ccsid_);
                Array.Copy(bytes, offset, data_, offset_ + ipos - 1, total);
                return(total);
            }
            catch (UnsupportedEncodingException uee)
            {
                SQLException sql = new SQLException(uee.ToString());
                sql.initCause(uee);
                throw sql;
            }
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public long length() throws SQLException
        public long length()
        {
            if (length_ == -1)
            {
                attribs_.StartOffset   = 0;
                attribs_.RequestedSize = 0;
                attribs_.ReturnCurrentLengthIndicator = 0xF1;
                try
                {
                    length_ = -1;
                    conn_.retrieveLOBData(attribs_, this);
                    if (length_ == -1)
                    {
                        throw new IOException("LOB length not retrieved.");
                    }
                }
                catch (IOException io)
                {
                    SQLException sql = new SQLException(io.ToString());
                    sql.initCause(io);
                    throw sql;
                }
            }
            return(length_);
        }
예제 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public long position(String patternString, long start) throws SQLException
        public virtual long position(string patternString, long start)
        {
            if (start <= 0)
            {
                throw new SQLException("Bad start: " + start);
            }
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] pattern = com.ibm.jtopenlite.Conv.stringToEBCDICByteArray(patternString, ccsid_);
                sbyte[] pattern = Conv.stringToEBCDICByteArray(patternString, ccsid_);
                for (int i = (int)(start & 0x7FFFFFFF) + offset_ - 1; i < offset_ + length_; ++i)
                {
                    bool match = true;
                    for (int j = 0; match && j < pattern.Length; ++j)
                    {
                        if (data_[i] != pattern[j])
                        {
                            match = false;
                        }
                    }
                    if (match)
                    {
                        return(i - offset_);
                    }
                }
                return(-1);
            }
            catch (UnsupportedEncodingException uee)
            {
                SQLException sql = new SQLException(uee.ToString());
                sql.initCause(uee);
                throw sql;
            }
        }
예제 #5
0
        // pos is 1-based!
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String getSubString(long pos, int length) throws SQLException
        public virtual string getSubString(long pos, int length)
        {
            if (pos <= 0)
            {
                throw new SQLException("Bad position: " + pos);
            }
            int ipos  = (int)(pos & 0x7FFFFFFF);
            int total = length_ - ipos + 1;

            if (total > length)
            {
                total = length;
            }
            sbyte[] data = new sbyte[total];
            Array.Copy(data_, offset_ + ipos - 1, data, 0, total);
            try
            {
                return(Conv.ebcdicByteArrayToString(data_, offset_ + ipos - 1, total, ccsid_));
            }
            catch (UnsupportedEncodingException uee)
            {
                SQLException sql = new SQLException(uee.ToString());
                sql.initCause(uee);
                throw sql;
            }
        }
예제 #6
0
        /// <summary>
        /// This is a ByteArrayInputStream wrapper around String.getBytes("ASCII").
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public InputStream getAsciiStream() throws SQLException
        public virtual Stream getAsciiStream()
        {
            try
            {
                return(new MemoryStream(Conv.ebcdicByteArrayToString(data_, offset_, length_, ccsid_).GetBytes(Encoding.ASCII)));
            }
            catch (UnsupportedEncodingException uee)
            {
                SQLException sql = new SQLException(uee.ToString());
                sql.initCause(uee);
                throw sql;
            }
        }
예제 #7
0
        /// <summary>
        /// This is a StringReader wrapper.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Reader getCharacterStream() throws SQLException
        public virtual Reader getCharacterStream()
        {
            try
            {
                return(new StringReader(Conv.ebcdicByteArrayToString(data_, offset_, length_, ccsid_)));
            }
            catch (UnsupportedEncodingException uee)
            {
                SQLException sql = new SQLException(uee.ToString());
                sql.initCause(uee);
                throw sql;
            }
        }
예제 #8
0
        internal static SQLException convertException(IOException io, int sqlCode, string sqlState)
        {
            SQLException sql = null;

            if (io is MessageException)
            {
                MessageException me       = (MessageException)io;
                Message[]        messages = me.Messages;
                string           reason   = messages[0].ToString();
                sql = new SQLException(reason, sqlState, sqlCode);
                sql.initCause(io);
            }
            else
            {
                string reason = io.ToString();
                sql = new SQLException(reason, sqlState, sqlCode);
                sql.initCause(io);
            }

            return(sql);
        }