예제 #1
0
 /*
 ** Name: setCharacterStream
 **
 ** Description:
 **	Assign a character stream as the data value.
 **	The data value will be NULL if the input
 **	value is null, otherwise non-NULL.
 **
 ** Input:
 **	value	Character stream (may be null).
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public override void setCharacterStream(Reader value)
 {
     setStream(value);
     return;
 }
예제 #2
0
        /*
        ** Name: strm2str
        **
        ** Description:
        **	Read a character input stream and convert to a string object.
        **	The stream is closed.
        **
        ** Input:
        **	in	Character input stream.
        **	limit	Maximum size of result, negative for no limit
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	String	The stream as a string.
        **
        ** History:
        **	12-Sep-03 (gordy)
        **	    Created.
        */
        private static String 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() );
        }
예제 #3
0
 /*
 ** Name: set
 **
 ** Description:
 **	Assign a new data value.  The data value will be NULL if
 **	the input value is null, otherwise non-NULL.  The input
 **	stream may optionally implement the SqlStream.IStreamSource
 **	interface.
 **
 ** Input:
 **	stream		The new data value.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	12-Sep-03 (gordy)
 **	    Created.
 */
 public void set( Reader stream )
 {
     setStream( (Object)stream );
     return;
 }
예제 #4
0
 public void updateCharacterStream( String name, Reader inReader, int length )
 {
     updateCharacterStream( columnByName( name ), inReader, length );
 }
예제 #5
0
 public virtual void setCharacterStream(Reader value)
 {
     throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
 }
예제 #6
0
 public void updateCharacterStream( int index, Reader inReader, int length )
 {
     if ( trace.enabled() )  trace.log( title + ".updateCharacterStream(" +
                                 index + "," + length + ")" );
 }
예제 #7
0
        /*
        ** Name: setCharacterStream
        **
        ** Description:
        **	Set parameter to a character stream.  If the parameter has not
        **	been initialized for a specific SQL type, the LONGVARCHAR type
        **	will be used.
        **
        ** Input:
        **	index	Parameter index.
        **	value	Character stream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        public void setCharacterStream( int index, Reader value )
        {
            Param param = check( index );

            lock( param )
            {
                if (param.value == null) set(param, ProviderType.LongVarChar,
                    useAltStorage(ProviderType.LongVarChar));

            param.value.setCharacterStream( value );
            param.flags |= (ushort)(PS_FLG_SET | dflt_flags);
            }

            return;
        }
예제 #8
0
        /*
        ** Name: setCharacterStream
        **
        ** Description:
        **	Set parameter to a character stream.
        **
        ** Input:
        **	paramIndex	Parameter index.
        **	reader		Character stream.
        **	length		Length of stream in bytes.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 2-Nov-00 (gordy)
        **	    Created.
        **	 8-Jan-01 (gordy)
        **	    Stream classes moved to ParamSet.
        **	 1-Jun-01 (gordy)
        **	    No longer need wrapper class for Reader.
        **	19-Feb-03 (gordy)
        **	    Check for alternate storage format.
        **	 1-Nov-03 (gordy)
        **	    ParamSet functionality extended.
        **	14-Sep-05 (gordy)
        **	    If stream is short enough, save as VARCHAR.
        */
        public void setCharacterStream( int paramIndex, Reader reader, int length )
        {
            if ( trace.enabled() )  trace.log( title + ".setCharacterStream( " +
                                        paramIndex + ", " + length + " )" );

            /*
            ** Check length to see if can be sent as VARCHAR.
            ** Ingres won't coerce CLOB to VARCHAR, but will
            ** coerce VARCHAR to CLOB, so VARCHAR is preferred.
            */
            if ( length >= 0  &&  length <= (conn.ucs2_supported ? conn.max_nvch_len
                                     : conn.max_vchr_len) )
            {
            char[]  chars = new char[ length ];

            if ( length > 0 )
                try
                {
                int	len = reader.read( chars );

                if ( len != length )
                {
                    /*
                    ** Character array limits read so any difference
                    ** must be a truncation.
                    */
                    if ( trace.enabled( 1 ) )
                    trace.write( tr_id + ".setCharacterStream: read only " +
                             len + " of " + length + " characters!" );
                    setWarning( DataTruncation( paramIndex, true,
                                    false, length, len ) );
                }
                }
                catch( IOException )
                { throw SqlEx.get( ERR_GC4007_BLOB_IO ); }

            paramIndex = paramMap( paramIndex );
            paramSet.init( paramIndex, ProviderType.VarChar );
            paramSet.setString( paramIndex, new String( chars ) );
            }
            else
            {
            paramIndex = paramMap( paramIndex );
            paramSet.init( paramIndex, ProviderType.LongVarChar );
            paramSet.setCharacterStream( paramIndex, reader );
            }

            return;
        }
예제 #9
0
            /*
            ** Name: Rdr2IS
            **
            ** Description:
            **	Class constructor.
            **
            ** Input:
            **	rdr		Reader.
            **	charSet		Character-set name.
            **
            ** Output:
            **	None.
            **
            ** Returns:
            **	None.
            **
            ** History:
            **	12-Sep-03 (gordy)
            **	    Created.
            */
            public Rdr2IS( Reader rdr, String charSet )
                : base(InputStream.InputStreamNull)
            {
                this.rdr = rdr;
                encoder = CharSet.forName( charSet ).newEncoder();
                encoder.onMalformedInput( CodingErrorAction.REPLACE );
                encoder.onUnmappableCharacter( CodingErrorAction.REPLACE );

                /*
                ** Initialize input/output buffers as empty so that
                ** the first read() request will proceed to fill them.
                ** The initial buffer state is clear() for reading,
                ** so simply flip() ready for writing.
                */
                inBuff.flip();
                outBuff.flip();
            }
예제 #10
0
        /*
        ** Name: coyRdr2Wtr
        **
        ** Description:
        **	Writes the contents of a Reader stream to a Writer stream.
        **	The Reader stream is closed.  The Writer stream is flushed
        **	but not closed.
        **
        ** Input:
        **	rdr	Reader stream.
        **	wtr	Writer stream.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        */
        protected void copyRdr2Wtr(Reader rdr, Writer wtr)
        {
            if (cbuff == null)
                lock (this)
                {
                    { if (cbuff == null)  cbuff = new char[4096]; }
                }

            try
            {
                lock (cbuff)
                {
                    for (int len = rdr.read(cbuff); len >= 0; len = rdr.read(cbuff))
                        wtr.write(cbuff, 0, len);
                }

                rdr.close();
                wtr.flush();
            }
            catch (Exception ex)
            {
                try { rdr.close(); }
                catch (Exception /* ignore */ ) { }
                try { wtr.flush(); }
                catch (Exception /* ignore */ ) { }
                throw SqlEx.get(ERR_GC4007_BLOB_IO, ex);
            }

            return;
        }