예제 #1
0
파일: msgin.cs 프로젝트: JordanChin/Ingres
 /*
 ** Name: readSqlData
 **
 ** Description:
 **	Reads a SqlLongChar data value from the current input message.
 **	Only a single stream data value may be active at a given time.
 **	Attempting to read another stream data value will result in
 **	the closure of the preceding stream.
 **
 **	A SqlLongChar data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by zero or more segments
 **	which are then followed by and end-of-segments indicator.  Each
 **	segment is composed of a two byte integer length (non-zero)
 **	followed by a character byte array of the indicated length.
 **	The end-of-segments indicator is a two byte integer with value
 **	zero.
 **
 **	Only the SQL data/NULL indicator is read by this method.  If
 **	the SqlLongChar value is non-NULL, an InputStream is provided
 **	for reading the segmented data stream.  The InputStream also
 **	implements the SqlStream StreamSource interface for providing
 **	notification of stream closure events.
 **
 ** Input:
 **	None.
 **
 ** Output:
 **	value	SQL data value.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	22-Sep-03 (gordy)
 **	    Created.
 */
 public void readSqlData( SqlLongChar value )
 {
     if ( readSqlDataIndicator() )	// Read data indicator byte.
         value.set( new ByteSegIS( this, trace, in_msg_id ) );
     else
         value.setNull();		// NULL data value.
     return;
 }
예제 #2
0
파일: msgout.cs 프로젝트: JordanChin/Ingres
 /*
 ** Name: write
 **
 ** Description:
 **	Write a SqlLongChar data value to the current input message.
 **	The byte stream is retrieved and segmented for output by an
 **	instance of the local inner class ByteSegOS.
 **
 **	A SqlLongChar data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by zero or more segments
 **	which are then followed by and end-of-segments indicator.  Each
 **	segment is composed of a two byte integer length (non-zero)
 **	followed by a character byte array of the indicated length.
 **	The end-of-segments indicator is a two byte integer with value
 **	zero.
 **
 ** Input:
 **	value	SQL data value.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public void write(SqlLongChar value)
 {
     if (writeSqlDataIndicator(value))	// Data indicator byte.
     {
     //				if (segOS == null) segOS = new ByteSegOS();
         if (segOS == null)
             segOS = new ByteSegOS(this, outBuff, trace);
         segOS.begin(out_msg_id);		// begin a new BLOB.
         try { value.get(segOS); }		// Write stream to output.
         finally { segOS.end(); }		// End-of-segments.
     }
     return;
 }
예제 #3
0
        /*
        ** Name: allocateRowBuffer
        **
        ** Description:
        **	Allocate the column data array for a row and populate
        **	the array with a SqlData object for each column based
        **	on the column data type.
        **
        ** Input:
        **	rsmd		Row-set Meta-data.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	SqlData[]	Column data array.
        **
        ** History:
        **	14-May-99 (gordy)
        **	    Created.
        **	10-May-01 (gordy)
        **	    The character datatypes (CHAR, VARCHAR, LONGVARCHAR) may now
        **	    be sent as UCS2 character arrays in addition to the existing
        **	    Ingres Character Set strings.  The DBMS datatype is used to
        **	    distinguish the transport format.
        **	31-Oct-02 (gordy)
        **	    Adapted for generic GCF driver.
        **	 4-Aug-03 (gordy)
        **	    Extracted from readData() to separate row and column processing.
        **	22-Sep-03 (gordy)
        **	    Changed to use SQL Data objects to hold column values.
        **	 6-Jan-04 (thoda04)
        **	    Added BigInt support.
        **	16-Jun-06 (gordy)
        **	    ANSI Date/Time data type support.
        **	 7-Dec-09 (gordy, ported by thoda04)
        **	    Support BOOLEAN columns.
        */
        private SqlData[] allocateRowBuffer( AdvanRSMD rsmd )
        {
            SqlData[] row = new SqlData[ rsmd.count ];

            for( int col = 0; col < rsmd.count; col++ )
            {
                switch( rsmd.desc[ col ].sql_type )
                {
                    case ProviderType.DBNull :	row[ col ] = new SqlNull();	break;
                    case ProviderType.TinyInt :	row[ col ] = new SqlTinyInt();	break;
                    case ProviderType.SmallInt:	row[ col ] = new SqlSmallInt();	break;
                    case ProviderType.Integer :	row[ col ] = new SqlInt();	break;
                    case ProviderType.BigInt:  	row[ col ] = new SqlBigInt();	break;
                    case ProviderType.Single :	row[ col ] = new SqlReal();	break;
                    case ProviderType.Double :	row[ col ] = new SqlDouble();	break;
                    case ProviderType.Numeric:
                    case ProviderType.Decimal :	row[ col ] = new SqlDecimal();	break;
                    case ProviderType.Boolean :	row[ col ] = new SqlBool();   	break;

                    case ProviderType.Date :	row[col] = new SqlDate(); break;

                    case ProviderType.Time:
                        row[col] = new SqlTime(rsmd.desc[col].dbms_type);
                        break;

                    case ProviderType.Interval:
                    case ProviderType.IntervalDayToSecond:
                    case ProviderType.IntervalYearToMonth:
                        row[col] = new SqlInterval(rsmd.desc[col].dbms_type);
                        break;

                    case ProviderType.DateTime:
                        switch (rsmd.desc[col].dbms_type)
                        {
                            case DBMS_TYPE_IDATE:
                                row[col] = new IngresDate(conn.osql_dates,
                                                 conn.timeValuesInGMT());
                                break;

                            default:
                                row[col] = new SqlTimestamp(rsmd.desc[col].dbms_type);
                                break;
                        }
                        break;

                    case ProviderType.Binary :
                        row[ col ] = new SqlByte( rsmd.desc[ col ].length );
                        break;

                    case ProviderType.VarBinary :
                        row[ col ] = new SqlVarByte( rsmd.desc[ col ].length );
                        break;

                    case ProviderType.Char :
                        if ( rsmd.desc[ col ].dbms_type != DBMS_TYPE_NCHAR )
                            row[ col ] = new SqlChar( msg.getCharSet(),
                                rsmd.desc[ col ].length );
                        else
                            row[ col ] = new SqlNChar(rsmd.desc[col].length / 2 );
                        break;

                    case ProviderType.VarChar :
                        if ( rsmd.desc[ col ].dbms_type != DBMS_TYPE_NVARCHAR )
                            row[col] = new SqlVarChar(msg.getCharSet(),
                                rsmd.desc[col].length );
                        else
                            row[col] = new SqlNVarChar( rsmd.desc[col].length / 2 );
                        break;

                    case ProviderType.LongVarBinary :
                        row[ col ] = new SqlLongByte( (SqlStream.IStreamListener)this );
                        break;

                    case ProviderType.LongVarChar :
                        if ( rsmd.desc[ col ].dbms_type != DBMS_TYPE_LONG_NCHAR )
                            row[ col ] = new SqlLongChar( msg.getCharSet(),
                                (SqlStream.IStreamListener)this );
                        else
                            row[ col ] = new SqlLongNChar(
                                (SqlStream.IStreamListener)this );
                        break;

                    default :
                        if ( trace.enabled( 1 ) )
                            trace.write( tr_id + ": unexpected SQL type " +
                                rsmd.desc[ col ].sql_type );
                        throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR );
                }
            }

            return( row );
        }
예제 #4
0
        /*
        ** Name: sendData
        **
        ** Description:
        **	Send a DATA message for current set of parameters.
        **
        ** Input:
        **	eog	Is this message end-of-group?
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	void.
        **
        ** History:
        **	19-May-99 (gordy)
        **	    Created.
        **	29-Sep-99 (gordy)
        **	    Implemented support for BLOBs.
        **	12-Nov-99 (gordy)
        **	    Use configured date formatter.
        **	17-Dec-99 (gordy)
        **	    Conversion to BLOB now determined by DBMS max varchar len.
        **	 2-Feb-00 (gordy)
        **	    Send short streams as VARCHAR or VARBINARY.
        **	15-Nov-00 (gordy)
        **	    Extracted Param class to create a stand-alone Paramset class.
        **	 8-Jan-01 (gordy)
        **	    Parameter set passed as parameter to support batch processing.
        **	10-May-01 (gordy)
        **	    Support UCS2 as alternate format for character types.  Char
        **	    arrays fully supported as separate BINARY and VARBINARY types.
        **	 1-Jun-01 (gordy)
        **	    Removed conversion of BLOB to fixed length type for short lengths.
        **	20-Feb-02 (gordy)
        **	    Decimal not supported by gateways at proto level 0.  Send as float.
        **	 6-Sep-02 (gordy)
        **	    Use formatted length of CHAR and VARCHAR parameters rather than
        **	    character length.
        **	31-Oct-02 (gordy)
        **	    Adapted for generic GCF driver.
        **	19-Feb-03 (gordy)
        **	    Replaced BIT with BOOLEAN.  Skip unset parameters (default
        **	    procedure parameters).  ALT character parameters now stored
        **	    in communication format.
        **	26-Jun-03 (gordy)
        **	    Missed an ALT storage class.
        **	27-June-03 (wansh01)
        **	    Handle binary type with 0 length as varbinary.
        **	 1-Dec-03 (gordy)
        **	    Moved to ParamSet to support updatable result sets.
        **	23-Jan-04 (gordy)
        **	    Properly handle zero length NCHAR columns using emptyNVarChar.
        **	    Set NULL CHAR/BINARY columns to non-zero length to avoid coercion
        **	    (zero length values were being sent instead of mulls).
        **	15-Mar-04 (gordy)
        **	    BIGINT now supported.  BOOLEAN should always be in alternate
        **	    storage format (force to alternate until BOOLEAN supported).
        **	28-May-04 (gordy)
        **	    Add max column lengths for NCS columns.
        **	19-Jun-06 (gordy)
        **	    ANSI Date/Time data type support.  Ingres date is now
        **	    the alternate storage for DATE/TIME/TIMESTAMP and
        **	    SqlDate/SqlTime/SqlTimestamp are the primary storage.
        **	 7-Dec-09 (gordy, ported by thoda04)
        **	    Boolean now fully supported.
        **	 3-Mar-10 (thoda04)  SIR 123368
        **	    Added support for IngresType.IngresDate parameter data type.
        */
        public void sendData(bool eog)
        {
            lock (this)
            {
            msg.begin(MSG_DATA);

            for (int param = 0; param < param_cnt; param++)
            {
                if (paramArray[param] == null ||
                     (paramArray[param].flags & PS_FLG_SET) == 0)
                    continue;		// Skip unset params.

                SqlData value = paramArray[param].value;
                ProviderType type = paramArray[param].type;
                bool alt = ((paramArray[param].flags & PS_FLG_ALT) != 0);
                int length;

                switch (type)
                {
                    case ProviderType.DBNull: msg.write((SqlNull)value); break;
                    case ProviderType.TinyInt: msg.write((SqlTinyInt)value); break;
                    case ProviderType.SmallInt: msg.write((SqlSmallInt)value); break;
                    case ProviderType.Integer: msg.write((SqlInt)value); break;
                    case ProviderType.Real: msg.write((SqlReal)value); break;
                    case ProviderType.Double: msg.write((SqlDouble)value); break;

                    case ProviderType.Date:
                        if (alt)
                            msg.write((IngresDate)value);
                        else
                            msg.write((SqlDate)value);
                        break;

                    case ProviderType.Time:
                        if (alt)
                            msg.write((IngresDate)value);
                        else
                            msg.write((SqlTime)value);
                        break;

                    case ProviderType.IngresDate:
                    case ProviderType.DateTime:
                        if (alt)
                            msg.write((IngresDate)value);
                        else
                            msg.write((SqlTimestamp)value);
                        break;

                    case ProviderType.Boolean:
                        if (alt)
                            msg.write((SqlTinyInt)value);
                        else
                            msg.write((SqlBool)value);
                        break;

                    case ProviderType.BigInt:
                        if (alt)
                            msg.write((SqlDouble)value);
                        else
                            msg.write((SqlBigInt)value);
                        break;

                    case ProviderType.Decimal:
                        if (alt)
                            msg.write((SqlDouble)value);
                        else
                            msg.write((SqlDecimal)value);
                        break;

                    case ProviderType.Char:
                        /*
                        ** Determine length.  NULL values assume {n}char(1).
                        */
                        if (value.isNull())
                            length = 1;
                        else if (alt)
                            length = ((SqlChar)value).valuelength();
                        else
                            length = ((SqlNChar)value).valuelength();

                        /*
                        ** Zero length strings must be sent as VARCHAR.
                        ** Long strings are sent as BLOBs.  UCS2 used
                        ** when supported.
                        */
                        if (alt)
                        {
                            if (length <= 0)
                                msg.write(emptyVarChar);
                            else if (length <= conn.max_char_len)
                                msg.write((SqlChar)value);
                            else
                            {
                                if (tempLongChar == null)
                                    tempLongChar = new SqlLongChar(msg.getCharSet());
                                tempLongChar.set((SqlChar)value);
                                msg.write(tempLongChar);
                            }
                        }
                        else
                        {
                            if (length <= 0)
                                msg.write(emptyNVarChar);
                            else if (length <= conn.max_nchr_len)
                                msg.write((SqlNChar)value);
                            else
                            {
                                if (tempLongNChar == null)
                                    tempLongNChar = new SqlLongNChar();
                                tempLongNChar.set((SqlNChar)value);
                                msg.write(tempLongNChar);
                            }
                        }
                        break;

                    case ProviderType.VarChar:
                        /*
                        ** Determine length.  NULL values assume {n}varchar(1).
                        */
                        if (value.isNull())
                            length = 1;
                        else if (alt)
                            length = ((SqlVarChar)value).valuelength();
                        else
                            length = ((SqlNVarChar)value).valuelength();

                        /*
                        ** Long strings are sent as BLOBs.
                        ** UCS2 used when supported.
                        */
                        if (alt)
                        {
                            if (length <= conn.max_vchr_len)
                                msg.write((SqlVarChar)value);
                            else
                            {
                                if (tempLongChar == null)
                                    tempLongChar = new SqlLongChar(msg.getCharSet());
                                tempLongChar.set((SqlVarChar)value);
                                msg.write(tempLongChar);
                            }
                        }
                        else
                        {
                            if (length <= conn.max_nvch_len)
                                msg.write((SqlNVarChar)value);
                            else
                            {
                                if (tempLongNChar == null)
                                    tempLongNChar = new SqlLongNChar();
                                tempLongNChar.set((SqlNVarChar)value);
                                msg.write(tempLongNChar);
                            }
                        }
                        break;

                    case ProviderType.LongVarChar:
                        /*
                        ** UCS2 used when supported.
                        */
                        if (alt)
                            msg.write((SqlLongChar)value);
                        else
                            msg.write((SqlLongNChar)value);
                        break;

                    case ProviderType.Binary:
                        /*
                        ** Determine length.  NULL values assume byte(1).
                        */
                        length = value.isNull() ? 1 : ((SqlByte)value).valuelength();

                        /*
                        ** Long arrays are sent as BLOBs.  Zero length
                        ** arrays must be sent as VARBINARY.
                        **
                        */
                        if (length <= 0)
                            msg.write(emptyVarByte);
                        else if (length <= conn.max_byte_len)
                            msg.write((SqlByte)value);
                        else
                        {
                            if (tempLongByte == null) tempLongByte = new SqlLongByte();
                            tempLongByte.set((SqlByte)value);
                            msg.write(tempLongByte);
                        }
                        break;

                    case ProviderType.VarBinary:
                        /*
                        ** Determine length.  NULL values assume varbyte(1).
                        */
                        length = value.isNull() ? 1 : ((SqlVarByte)value).valuelength();

                        /*
                        ** Long arrays are sent as BLOBs.
                        */
                        if (length <= conn.max_vbyt_len)
                            msg.write((SqlVarByte)value);
                        else
                        {
                            if (tempLongByte == null) tempLongByte = new SqlLongByte();
                            tempLongByte.set((SqlVarByte)value);
                            msg.write(tempLongByte);
                        }
                        break;

                    case ProviderType.LongVarBinary:
                        msg.write((SqlLongByte)value);
                        break;
                }
            }

            msg.done(eog);
            return;
            }  // lock
        }