Exemplo n.º 1
0
		internal static object JavaResultSetToClrWrapper(CallableStatement results,int columnIndex,JavaSqlTypes javaSqlType,int maxLength ,ResultSetMetaData resultsMetaData)
		{
			object returnValue = null;	
			sbyte[] sbyteArray;
			long milliseconds;
			long ticks;
			string s;
			columnIndex++; //jdbc style
			switch (javaSqlType) {
				case JavaSqlTypes.ARRAY :
					returnValue = results.getArray(columnIndex);
					break;
				case JavaSqlTypes.BIGINT :
					returnValue = results.getLong(columnIndex);
					break;
				case JavaSqlTypes.BINARY :
				case JavaSqlTypes.VARBINARY :
				case JavaSqlTypes.LONGVARBINARY :
					// FIXME : comsider using maxLength
					sbyteArray = results.getBytes(columnIndex);
					if (sbyteArray != null) {
						returnValue = vmw.common.TypeUtils.ToByteArray(sbyteArray);
					}
					break;
				case JavaSqlTypes.BIT :
					returnValue = results.getBoolean(columnIndex);
					break;
				case JavaSqlTypes.BLOB :
					// FIXME : comsider using maxLength
					java.sql.Blob blob = results.getBlob(columnIndex);
					if (blob != null) {
						InputStream input = blob.getBinaryStream();					
						if (input == null) {
							returnValue = new byte[0];
						}
						else {
							long length = blob.length();
							byte[] byteValue = new byte[length];
							sbyte[] sbyteValue = vmw.common.TypeUtils.ToSByteArray(byteValue);
							input.read(sbyteValue);
							returnValue = byteValue;
						}
					}
					break;	
				case JavaSqlTypes.CHAR :						
					if (resultsMetaData != null && "uniqueidentifier".Equals(resultsMetaData.getColumnTypeName(columnIndex))) {
						returnValue = new Guid(results.getString(columnIndex));
					}
					else {
						// Oracle Jdbc driver returns extra trailing 0 chars for NCHAR columns, so we threat this at parameter.Size level
						s = results.getString(columnIndex);
						if ((s != null) && (maxLength < s.Length)) {
							s = s.Substring(0,maxLength);
						}
						returnValue = s;
					}
					break;
				case JavaSqlTypes.CLOB :
					// FIXME : comsider using maxLength
					java.sql.Clob clob = results.getClob(columnIndex);
					if (clob != null) {
						java.io.Reader reader = clob.getCharacterStream();					
						if (reader == null) {
							returnValue = String.Empty;
						}
						else {
							long length = clob.length();
							char[] charValue = new char[length];
							reader.read(charValue);
							returnValue = new string(charValue);
						}
					}
					break;		
				case JavaSqlTypes.TIME :
					Time t = results.getTime(columnIndex);
					if (t != null) {
						returnValue = new TimeSpan(JavaTimeToClrTicks(t));
					}
					break;	
				case JavaSqlTypes.DATE :
					Date d = results.getDate(columnIndex);
					if (d != null) {
						returnValue = new DateTime(JavaDateToClrTicks(d));
					}
					break;
				case JavaSqlTypes.TIMESTAMP :				
					Timestamp ts = results.getTimestamp(columnIndex);
					if (ts != null) {
						returnValue = new DateTime(JavaTimestampToClrTicks(ts));
					}
					break;		
				case JavaSqlTypes.DECIMAL :
				case JavaSqlTypes.NUMERIC :
					// java.sql.Types.NUMERIC (2), columnTypeName NUMBER, columnClassName java.math.BigDecimal 
					// therefore we rely on scale
					if (resultsMetaData != null &&  resultsMetaData.getScale(columnIndex) == -127) {
						// Oracle db type FLOAT
						returnValue = results.getDouble(columnIndex);
					}
					else {
						java.math.BigDecimal bigDecimal = results.getBigDecimal(columnIndex);
						if (bigDecimal != null) {
							returnValue = vmw.common.PrimitiveTypeUtils.BigDecimalToDecimal(bigDecimal);
						}
					}
					break;		
				case JavaSqlTypes.DISTINCT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.DOUBLE :
					returnValue = results.getDouble(columnIndex);
					break;
				case JavaSqlTypes.FLOAT :
					//float f = results.getFloat(columnIndex);
					returnValue = results.getDouble(columnIndex);
					break;
				case JavaSqlTypes.INTEGER :
					returnValue = results.getInt(columnIndex);
					break;
				case JavaSqlTypes.JAVA_OBJECT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.LONGVARCHAR :
					returnValue = results.getString(columnIndex);
					break;
				case JavaSqlTypes.NULL :
					returnValue = DBNull.Value;
					break;
				case JavaSqlTypes.OTHER :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.REAL :
					returnValue = results.getFloat(columnIndex);
					break;
				case JavaSqlTypes.REF :
					returnValue = results.getRef(columnIndex);
					break;
				case JavaSqlTypes.SMALLINT :
					returnValue = results.getShort(columnIndex);
					break;
				case JavaSqlTypes.STRUCT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.TINYINT :
					returnValue = Convert.ToByte(results.getByte(columnIndex));
					break;
				case JavaSqlTypes.VARCHAR :
					s = results.getString(columnIndex);
					if ((s != null) && (maxLength < s.Length)) {
						s = s.Substring(0,maxLength);
					}
					returnValue = s;
					break;
				default :
					returnValue = results.getObject(columnIndex);
					break;
			}
				
			if (results.wasNull() || results == null) {
				return DBNull.Value;
			}                
			return  returnValue;
		}
Exemplo n.º 2
0
        internal static Type JavaSqlTypeToClrType(int sqlTypeValue)
        {
            JavaSqlTypes sqlType = (JavaSqlTypes)sqlTypeValue;

            switch (sqlType)
            {
            case JavaSqlTypes.ARRAY: return(typeof(java.sql.Array));

            case JavaSqlTypes.BIGINT: return(DbTypes.TypeOfInt64);

            case JavaSqlTypes.BINARY: return(DbTypes.TypeOfByteArray);

            case JavaSqlTypes.BIT: return(DbTypes.TypeOfBoolean);

            case JavaSqlTypes.BLOB: return(DbTypes.TypeOfByteArray);

            case JavaSqlTypes.BOOLEAN: return(DbTypes.TypeOfBoolean);

            case JavaSqlTypes.CHAR: return(DbTypes.TypeOfString);

            case JavaSqlTypes.CLOB: return(DbTypes.TypeOfString);

//				case JavaSqlTypes.DATALINK :
            case JavaSqlTypes.DATE: return(DbTypes.TypeOfDateTime);

            case JavaSqlTypes.DECIMAL: return(DbTypes.TypeOfDecimal);

//				case JavaSqlTypes.DISTINCT :
            case JavaSqlTypes.DOUBLE: return(DbTypes.TypeOfDouble);

            case JavaSqlTypes.FLOAT: return(DbTypes.TypeOfDouble);

            case JavaSqlTypes.INTEGER: return(DbTypes.TypeOfInt32);

//				case JavaSqlTypes.JAVA_OBJECT :
            case JavaSqlTypes.LONGVARBINARY: return(DbTypes.TypeOfByteArray);

            case JavaSqlTypes.LONGVARCHAR: return(DbTypes.TypeOfString);

            case JavaSqlTypes.NULL: return(null);

            case JavaSqlTypes.NUMERIC: return(DbTypes.TypeOfDecimal);

//				case JavaSqlTypes.OTHER :
            case JavaSqlTypes.REAL: return(DbTypes.TypeOfSingle);

            case JavaSqlTypes.REF: return(typeof(java.sql.Ref));

            case JavaSqlTypes.SMALLINT: return(DbTypes.TypeOfInt16);

            case JavaSqlTypes.STRUCT: return(typeof(java.sql.Struct));

            case JavaSqlTypes.TIME: return(DbTypes.TypeOfTimespan);

            case JavaSqlTypes.TIMESTAMP: return(DbTypes.TypeOfDateTime);

            case JavaSqlTypes.TINYINT: return(DbTypes.TypeOfByte);

            case JavaSqlTypes.VARBINARY: return(DbTypes.TypeOfByteArray);

            case JavaSqlTypes.VARCHAR: return(DbTypes.TypeOfString);

            default: return(DbTypes.TypeOfObject);
            }
        }
Exemplo n.º 3
0
        internal static object JavaResultSetToClrWrapper(CallableStatement results, int columnIndex, JavaSqlTypes javaSqlType, int maxLength, ResultSetMetaData resultsMetaData)
        {
            object returnValue = null;

            sbyte[] sbyteArray;
            long    milliseconds;
            long    ticks;
            string  s;

            columnIndex++;             //jdbc style
            switch (javaSqlType)
            {
            case JavaSqlTypes.ARRAY:
                returnValue = results.getArray(columnIndex);
                break;

            case JavaSqlTypes.BIGINT:
                returnValue = results.getLong(columnIndex);
                break;

            case JavaSqlTypes.BINARY:
            case JavaSqlTypes.VARBINARY:
            case JavaSqlTypes.LONGVARBINARY:
                // FIXME : comsider using maxLength
                sbyteArray = results.getBytes(columnIndex);
                if (sbyteArray != null)
                {
                    returnValue = vmw.common.TypeUtils.ToByteArray(sbyteArray);
                }
                break;

            case JavaSqlTypes.BIT:
                returnValue = results.getBoolean(columnIndex);
                break;

            case JavaSqlTypes.BLOB:
                // FIXME : comsider using maxLength
                java.sql.Blob blob = results.getBlob(columnIndex);
                if (blob != null)
                {
                    InputStream input = blob.getBinaryStream();
                    if (input == null)
                    {
                        returnValue = new byte[0];
                    }
                    else
                    {
                        long    length     = blob.length();
                        byte[]  byteValue  = new byte[length];
                        sbyte[] sbyteValue = vmw.common.TypeUtils.ToSByteArray(byteValue);
                        input.read(sbyteValue);
                        returnValue = byteValue;
                    }
                }
                break;

            case JavaSqlTypes.CHAR:
                if (resultsMetaData != null && "uniqueidentifier".Equals(resultsMetaData.getColumnTypeName(columnIndex)))
                {
                    returnValue = new Guid(results.getString(columnIndex));
                }
                else
                {
                    // Oracle Jdbc driver returns extra trailing 0 chars for NCHAR columns, so we threat this at parameter.Size level
                    s = results.getString(columnIndex);
                    if ((s != null) && (maxLength < s.Length))
                    {
                        s = s.Substring(0, maxLength);
                    }
                    returnValue = s;
                }
                break;

            case JavaSqlTypes.CLOB:
                // FIXME : comsider using maxLength
                java.sql.Clob clob = results.getClob(columnIndex);
                if (clob != null)
                {
                    java.io.Reader reader = clob.getCharacterStream();
                    if (reader == null)
                    {
                        returnValue = String.Empty;
                    }
                    else
                    {
                        long   length    = clob.length();
                        char[] charValue = new char[length];
                        reader.read(charValue);
                        returnValue = new string(charValue);
                    }
                }
                break;

            case JavaSqlTypes.TIME:
                Time t = results.getTime(columnIndex);
                if (t != null)
                {
                    returnValue = new TimeSpan(JavaTimeToClrTicks(t));
                }
                break;

            case JavaSqlTypes.DATE:
                Date d = results.getDate(columnIndex);
                if (d != null)
                {
                    returnValue = new DateTime(JavaDateToClrTicks(d));
                }
                break;

            case JavaSqlTypes.TIMESTAMP:
                Timestamp ts = results.getTimestamp(columnIndex);
                if (ts != null)
                {
                    returnValue = new DateTime(JavaTimestampToClrTicks(ts));
                }
                break;

            case JavaSqlTypes.DECIMAL:
            case JavaSqlTypes.NUMERIC:
                // java.sql.Types.NUMERIC (2), columnTypeName NUMBER, columnClassName java.math.BigDecimal
                // therefore we rely on scale
                if (resultsMetaData != null && resultsMetaData.getScale(columnIndex) == -127)
                {
                    // Oracle db type FLOAT
                    returnValue = results.getDouble(columnIndex);
                }
                else
                {
                    java.math.BigDecimal bigDecimal = results.getBigDecimal(columnIndex);
                    if (bigDecimal != null)
                    {
                        returnValue = vmw.common.PrimitiveTypeUtils.BigDecimalToDecimal(bigDecimal);
                    }
                }
                break;

            case JavaSqlTypes.DISTINCT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.DOUBLE:
                returnValue = results.getDouble(columnIndex);
                break;

            case JavaSqlTypes.FLOAT:
                //float f = results.getFloat(columnIndex);
                returnValue = results.getDouble(columnIndex);
                break;

            case JavaSqlTypes.INTEGER:
                returnValue = results.getInt(columnIndex);
                break;

            case JavaSqlTypes.JAVA_OBJECT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.LONGVARCHAR:
                returnValue = results.getString(columnIndex);
                break;

            case JavaSqlTypes.NULL:
                returnValue = DBNull.Value;
                break;

            case JavaSqlTypes.OTHER:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.REAL:
                returnValue = results.getFloat(columnIndex);
                break;

            case JavaSqlTypes.REF:
                returnValue = results.getRef(columnIndex);
                break;

            case JavaSqlTypes.SMALLINT:
                returnValue = results.getShort(columnIndex);
                break;

            case JavaSqlTypes.STRUCT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.TINYINT:
                returnValue = Convert.ToByte(results.getByte(columnIndex));
                break;

            case JavaSqlTypes.VARCHAR:
                s = results.getString(columnIndex);
                if ((s != null) && (maxLength < s.Length))
                {
                    s = s.Substring(0, maxLength);
                }
                returnValue = s;
                break;

            default:
                returnValue = results.getObject(columnIndex);
                break;
            }

            if (results.wasNull() || results == null)
            {
                return(DBNull.Value);
            }
            return(returnValue);
        }
        protected override void SetSchemaType(DataRow schemaRow, ResultSetMetaData metaData, int columnIndex)
        {
            JavaSqlTypes columnType = (JavaSqlTypes)metaData.getColumnType(columnIndex);

            switch (columnType)
            {
            case JavaSqlTypes.BINARY_FLOAT:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfFloat;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.BINARY_DOUBLE:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfDouble;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.ROWID:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfString;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.CURSOR:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfDouble;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPNS:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPTZ:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPLTZ:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.INTERVALYM:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfUInt32;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.INTERVALDS:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            default:
                base.SetSchemaType(schemaRow, metaData, columnIndex);
                break;
            }
        }