Exemplo n.º 1
0
        public void GetRawValue()
        {
            SqlType type = new SqlNChar("ру́сский", 10, ParameterDirection.Input);
            Assert.AreEqual("ру́сский", type.GetRawValue());

            type = new SqlNChar(null, 10, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Exemplo n.º 2
0
        public void CreateMetaData()
        {
            Assert.Throws<TypeCannotBeUsedAsAClrTypeException>(() => SqlNChar.GetTypeHandler().CreateMetaData("Test"));

            SqlTypeHandler col = new SqlNChar("ру́сский", null, ParameterDirection.Input);
            Assert.Throws<TypePropertiesMustBeSetExplicitlyException>(() => col.CreateMetaData("Test"));

            col = new SqlNChar("ру́сский", 10, ParameterDirection.Input);
            var meta = col.CreateMetaData("Test");
            Assert.AreEqual(SqlDbType.NChar, meta.SqlDbType);
            Assert.AreEqual(10, meta.MaxLength);
            Assert.AreEqual("Test", meta.Name);
        }
Exemplo n.º 3
0
        protected override string GetColumnCreationMethod(SqlColumn column)
        {
            var type = column.Types[Version];

            return(type.SqlTypeInfo switch
            {
                SqlChar _ => $"{nameof(Generic1Columns.AddChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}",
                SqlNChar _ => $"{nameof(Generic1Columns.AddNChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlVarChar _ => $"{nameof(Generic1Columns.AddVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlNVarChar _ => $"{nameof(Generic1Columns.AddNVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlFloatSmall _ => $"{nameof(Generic1Columns.AddFloatSmall)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlFloatLarge _ => $"{nameof(Generic1Columns.AddFloatLarge)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlBit _ => $"{nameof(Generic1Columns.AddBit)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlByte _ => $"{nameof(Generic1Columns.AddByte)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt16 _ => $"{nameof(Generic1Columns.AddInt16)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt32 _ => $"{nameof(Generic1Columns.AddInt32)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt64 _ => $"{nameof(Generic1Columns.AddInt64)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlNumber _ => $"{nameof(Generic1Columns.AddNumber)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.Scale?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlDate _ => $"{nameof(Generic1Columns.AddDate)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlTime _ => $"{nameof(Generic1Columns.AddTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlDateTime _ => $"{nameof(Generic1Columns.AddDateTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                _ => throw new NotImplementedException($"Unmapped type: {type.SqlTypeInfo}"),
            });
Exemplo n.º 4
0
 /*
 ** Name: readSqlData
 **
 ** Description:
 **	Reads a SqlNChar data value from the current input message.
 **	Uses the ICharArray interface to load the SqlNChar data value.
 **
 **	A SqlNChar data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by a UCS2 (two byte
 **	integer) array whose length is detemined by the fixed size
 **	of the SqlNChar data value (the ICharArray valuelimit()).
 **
 ** Input:
 **	None.
 **
 ** Output:
 **	value	SQL data value.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	22-Sep-03 (gordy)
 **	    Created.
 */
 public void readSqlData( SqlNChar value )
 {
     if ( ! readSqlDataIndicator() )	// Read data indicator byte.
         value.setNull();		// NULL data value.
     else
     {					// Read data value.
         int length = value.valuelimit();	// Fixed length from meta-data.
         value.clear();
         value.ensureCapacity( length );
         readUCS2( (ICharArray)value, length );
     }
     return;
 }
Exemplo n.º 5
0
 public void CreateParamFromValue()
 {
     Assert.Throws <TypeCannotBeUsedAsAClrTypeException>(() => SqlNChar.GetTypeHandler().CreateParamFromValue("Test", null));
 }
Exemplo n.º 6
0
 public void GetTypeHandler()
 {
     Assert.IsInstanceOf <SqlTypeHandler>(SqlNChar.GetTypeHandler());
 }
Exemplo n.º 7
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 );
        }
Exemplo n.º 8
0
 /*
 ** Name: write
 **
 ** Description:
 **	Write a SqlNChar data value to the current input message.
 **	Uses the CharArray interface to send the SqlNChar data value.
 **
 **	A SqlNChar data value is composed of a data indicator byte
 **	which, if not NULL, may be followed by a UCS2 (two byte
 **	integer) array whose length is detemined by the length of
 **	the SqlNChar data value.
 **
 ** Input:
 **	value	SQL data value.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public void write(SqlNChar value)
 {
     if (writeSqlDataIndicator(value)) writeUCS2((ICharArray)value);
     return;
 }
Exemplo n.º 9
0
 /*
 ** Name: set
 **
 ** Description:
 **	Assign a new data value as a copy of a SqlNChar data
 **	value.  The data value will be NULL if the input value
 **	is null, otherwise non-NULL.
 **
 ** Input:
 **	data	SqlNChar data value to copy.
 **
 ** Output:
 **	None.
 **
 ** Returns:
 **	void.
 **
 ** History:
 **	 1-Dec-03 (gordy)
 **	    Created.
 */
 public void set(SqlNChar data)
 {
     if (data.isNull())
         setNull();
     else
     {
         /*
         ** The character data is stored in a character array.
         ** A character stream will produce the desired output.
         ** Note that we need to follow the SqlNChar convention
         ** and extend the data to the optional limit.
         */
         data.extend();
         setStream(getCharacter(data.value, data.length));
     }
     return;
 }