Beispiel #1
0
        public void CreateMetaData()
        {
            var meta = SqlTinyInt.GetTypeHandler().CreateMetaData("Test");

            Assert.AreEqual(SqlDbType.TinyInt, meta.SqlDbType);
            Assert.AreEqual("Test", meta.Name);
        }
Beispiel #2
0
        public void Length()
        {
            var type = new SqlTinyInt(CompressionContext.NoCompression);

            Assert.Throws <ArgumentException>(() => type.GetValue(new byte[0]));
            Assert.Throws <ArgumentException>(() => type.GetValue(new byte[2]));
        }
Beispiel #3
0
        public void GetRawValue()
        {
            SqlType type = new SqlTinyInt(5, ParameterDirection.Input);
            Assert.AreEqual((byte)5, type.GetRawValue());

            type = new SqlTinyInt(null, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Beispiel #4
0
        public void GetParameter()
        {
            SqlType type = new SqlTinyInt(5, ParameterDirection.Input);
            TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.TinyInt, (byte)5);

            type = new SqlTinyInt(null, ParameterDirection.Input);
            TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.TinyInt, DBNull.Value);
        }
Beispiel #5
0
        public void GetRawValue()
        {
            SqlType type = new SqlTinyInt(5, ParameterDirection.Input);

            Assert.AreEqual((byte)5, type.GetRawValue());

            type = new SqlTinyInt(null, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Beispiel #6
0
        public void GetParameter()
        {
            SqlType type = new SqlTinyInt(5, ParameterDirection.Input);

            TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.TinyInt, (byte)5);

            type = new SqlTinyInt(null, ParameterDirection.Input);
            TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.TinyInt, DBNull.Value);
        }
Beispiel #7
0
        public void GetValue()
        {
            var type = new SqlTinyInt(CompressionContext.NoCompression);

            byte[] input;

            input = new byte[] { 0xd9 };
            Assert.AreEqual(0xd9, Convert.ToByte(type.GetValue(input)));

            input = new byte[] { 0xf9 };
            Assert.AreEqual(0xf9, Convert.ToByte(type.GetValue(input)));

            input = new byte[] { 0xa4 };
            Assert.AreEqual(0xa4, Convert.ToByte(type.GetValue(input)));
        }
Beispiel #8
0
 /*
 ** Name: readSqlData
 **
 ** Description:
 **	Reads a SqlTinyInt data value from the current input message.
 **
 **	A SqlTinyInt data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by a one byte integer.
 **
 ** Input:
 **	None.
 **
 ** Output:
 **	value	SQL data value.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	22-Sep-03 (gordy)
 **	    Created.
 */
 public void readSqlData( SqlTinyInt value )
 {
     if ( readSqlDataIndicator() )	// Read data indicator byte.
         value.set( readByte() );	// Read data value.
     else
         value.setNull();		// NULL data value.
     return;
 }
Beispiel #9
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 );
        }
Beispiel #10
0
 /*
 ** Name: write
 **
 ** Description:
 **	Write a SqlTinyInt data value to the current input message.
 **
 **	A SqlTinyInt data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by a one byte integer.
 **
 ** Input:
 **	value	SQL data value.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public void write(SqlTinyInt value)
 {
     if (writeSqlDataIndicator(value)) write(value.get());
     return;
 }
Beispiel #11
0
        /*
        ** Name: getStorage
        **
        ** Description:
        **	Allocates storage for SQL data values base on the SQL type
        **	and optional alternate storage format.  The class of the
        **	object returned is defined in the class description.
        **
        ** Input:
        **	sqlType		SQL type.
        **	alt		True for alternate storage format.
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	SqlData		SQL data value.
        **
        ** History:
        **	 1-Dec-03 (gordy)
        **	    Created.
        **	19-Jun-06 (gordy)
        **	    ANSI Date/Time data type support.  IngresDate is now
        **	    the alternate storage for DATE/TIME/TIMESTAMP and
        **	    SqlDate/SqlTime/SqlTimestamp are the primary storage.
        **	 3-Mar-10 (thoda04)  SIR 123368
        **	    Added support for IngresType.IngresDate parameter data type.
        */
        /// <summary>
        /// Allocates storage for SQL data values base on the SQL type
        /// and optional alternate storage format.  The class of the
        /// object returned is defined in the class description.
        /// </summary>
        /// <param name="sqlType">SQL type.</param>
        /// <param name="alt">True for alternate storage format.</param>
        /// <returns>SQL data value.</returns>
        private SqlData getStorage(ProviderType sqlType, bool alt)
        {
            SqlData sqlData;

            switch (sqlType)
            {
                case ProviderType.DBNull: sqlData = new SqlNull(); break;
                case ProviderType.TinyInt: sqlData = new SqlTinyInt(); break;
                case ProviderType.SmallInt: sqlData = new SqlSmallInt(); break;
                case ProviderType.Integer: sqlData = new SqlInt(); break;
                case ProviderType.Real: sqlData = new SqlReal(); break;
                case ProviderType.Double: sqlData = new SqlDouble(); break;
                case ProviderType.Binary: sqlData = new SqlByte(); break;
                case ProviderType.VarBinary: sqlData = new SqlVarByte(); break;
                case ProviderType.LongVarBinary: sqlData = new SqlLongByte(); break;

                case ProviderType.Boolean:
                    sqlData = alt ? (SqlData)(new SqlTinyInt())
                              : (SqlData)(new SqlBool());
                    break;

                case ProviderType.BigInt:
                    sqlData = alt ? (SqlData)(new SqlDouble())
                              : (SqlData)(new SqlBigInt());
                    break;

                case ProviderType.Decimal:
                    sqlData = alt ? (SqlData)(new SqlDouble())
                              : (SqlData)(new SqlDecimal());
                    break;

                case ProviderType.Char:
                    sqlData = alt ? (SqlData)(new SqlChar(msg.getCharSet()))
                              : (SqlData)(new SqlNChar());
                    break;

                case ProviderType.VarChar:
                    sqlData = alt ? (SqlData)(new SqlVarChar(msg.getCharSet()))
                              : (SqlData)(new SqlNVarChar());
                    break;

                case ProviderType.LongVarChar:
                    sqlData = alt ? (SqlData)(new SqlLongChar(msg.getCharSet()))
                              : (SqlData)(new SqlLongNChar());
                    break;

                case ProviderType.Date:
                    sqlData = alt ? (SqlData)(new IngresDate(conn.osql_dates,
                                          conn.timeValuesInGMT()))
                              : (SqlData)(new SqlDate());
                    break;

                case ProviderType.Time:
                    sqlData = alt ? (SqlData)(new IngresDate(conn.osql_dates,
                                          conn.timeValuesInGMT()))
                              : (SqlData)(new SqlTime(
                            conn.osql_dates ? DBMS_TYPE_TMWO : DBMS_TYPE_TMTZ));
                    break;

                case ProviderType.DateTime:
                case ProviderType.IngresDate:
                    sqlData = alt ? (SqlData)(new IngresDate(conn.osql_dates,
                                          conn.timeValuesInGMT()))
                              : (SqlData)(new SqlTimestamp(
                            conn.osql_dates ? DBMS_TYPE_TSWO : DBMS_TYPE_TSTZ));
                    break;

                default:
                    throw SqlEx.get(ERR_GC401A_CONVERSION_ERR);
            }

            return (sqlData);
        }
Beispiel #12
0
 public void GetTypeHandler()
 {
     Assert.IsInstanceOf <SqlTypeHandler>(SqlTinyInt.GetTypeHandler());
 }