Ejemplo n.º 1
0
        private object GetValue(ParamDsc descriptor, Charset charset)
        {
            DbField field = new DbField();

            if (descriptor.Type == dtype_null)
            {
                return(null);
            }
            if (descriptor.Type == IscCodes.dtype_byte)
            {
                return(null);
            }

            DbDataType dbType = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType);

            field.DataType     = (short)TypeHelper.GetFbType(dbType, true);
            field.NumericScale = descriptor.Scale;
            field.SubType      = descriptor.SubType;

            byte[] data = GetBytes(descriptor, field.DataType);

            field.SetValue(data);

            return(field.Value);
        }
Ejemplo n.º 2
0
        public object MarshalNativeToManaged(Charset charset, IntPtr pNativeData)
        {
            // Obtain ParamDsc information
            ParamDsc descriptor = (ParamDsc)Marshal.PtrToStructure(pNativeData, typeof(ParamDsc));

            return(GetValue(descriptor, charset));
        }
Ejemplo n.º 3
0
        public IntPtr MarshalManagedToNative(ParamDsc descriptor)
        {
            int    size = Marshal.SizeOf(descriptor);
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(descriptor, ptr, true);

            return(ptr);
        }
Ejemplo n.º 4
0
        public IntPtr MarshalManagedToNative(Charset charset, object value)
        {
            DbField    field      = new DbField();
            ParamDsc   descriptor = BuildDescriptor(charset, value);
            DbDataType type       = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType);

            field.DataType      = (short)TypeHelper.GetFbType(type, true);
            field.SubType       = descriptor.SubType;
            field.DbValue.Value = value;
            field.Length        = descriptor.Length;

            byte[] buffer = field.DbValue.GetBytes();

            descriptor.Data = Marshal.AllocHGlobal(buffer.Length);
            Marshal.Copy(buffer, 0, descriptor.Data, buffer.Length);

            return(MarshalManagedToNative(descriptor));
        }
Ejemplo n.º 5
0
        private ParamDsc BuildDescriptor(Charset charset, object value)
        {
            ParamDsc descriptor = new ParamDsc();

            if (value == null || value == DBNull.Value)
            {
                descriptor.Flags |= IscCodes.DSC_null;
            }
            else
            {
                SetDscType(ref descriptor, value);
            }

            if (descriptor.Type == IscCodes.dtype_cstring || descriptor.Type == IscCodes.dtype_varying)
            {
                descriptor.SubType = (short)charset.Identifier;
            }

            return(descriptor);
        }
Ejemplo n.º 6
0
        private byte[] GetBytes(ParamDsc descriptor, int type)
        {
            if (descriptor.Length == 0 || descriptor.Data == IntPtr.Zero)
            {
                return(null);
            }

            byte[] buffer = new byte[descriptor.Length];

            switch (type & ~1)
            {
            case IscCodes.SQL_VARYING:
                buffer = new byte[Marshal.ReadInt16(descriptor.Data)];
                IntPtr tmp = GetIntPtr(descriptor.Data, 2);
                Marshal.Copy(tmp, buffer, 0, buffer.Length);
                return(buffer);

            case IscCodes.SQL_TEXT:
            case IscCodes.SQL_SHORT:
            case IscCodes.SQL_LONG:
            case IscCodes.SQL_FLOAT:
            case IscCodes.SQL_DOUBLE:
            case IscCodes.SQL_D_FLOAT:
            case IscCodes.SQL_QUAD:
            case IscCodes.SQL_INT64:
            case IscCodes.SQL_BLOB:
            case IscCodes.SQL_ARRAY:
            case IscCodes.SQL_TIMESTAMP:
            case IscCodes.SQL_TYPE_TIME:
            case IscCodes.SQL_TYPE_DATE:
                Marshal.Copy(descriptor.Data, buffer, 0, buffer.Length);
                return(buffer);

            default:
                throw new NotSupportedException("Unknown data type");
            }
        }
        private void SetDscType(ref ParamDsc descriptor, object value)
        {
            TypeCode code = Type.GetTypeCode(value.GetType());

            switch (code)
            {
                case TypeCode.Object:
                    descriptor.Type = IscCodes.dtype_blob;
                    descriptor.SubType = 0;
                    break;

                case TypeCode.Char:
                    descriptor.Type = IscCodes.dtype_cstring;
                    descriptor.Length = (short)value.ToString().Length;
                    break;

                case TypeCode.String:
                    descriptor.Type = IscCodes.dtype_varying;
                    descriptor.Length = (short)value.ToString().Length;
                    break;

                case TypeCode.Boolean:
                case TypeCode.Byte:
                case TypeCode.SByte:
                    descriptor.Type = IscCodes.dtype_byte;
                    descriptor.Length = 1;
                    break;

                case TypeCode.Int16:
                case TypeCode.UInt16:
                    descriptor.Type = IscCodes.dtype_short;
                    descriptor.Length = 2;
                    break;

                case TypeCode.Int32:
                case TypeCode.UInt32:
                    descriptor.Type = IscCodes.dtype_long;
                    descriptor.Length = 4;
                    break;

                case TypeCode.Int64:
                case TypeCode.UInt64:
                    descriptor.Type = IscCodes.dtype_int64;
                    descriptor.Length = 8;
                    break;

                case TypeCode.Single:
                    descriptor.Type = IscCodes.dtype_real;
                    descriptor.Length = 4;
                    break;

                case TypeCode.Double:
                case TypeCode.Decimal:
                    descriptor.Type = IscCodes.dtype_double;
                    descriptor.Length = 8;
                    break;

                case TypeCode.DateTime:
                    descriptor.Type = IscCodes.dtype_timestamp;
                    descriptor.Length = 8;
                    break;
            }
        }
        private ParamDsc BuildDescriptor(Charset charset, object value)
        {
            ParamDsc descriptor = new ParamDsc();

            if (value == null || value == DBNull.Value)
            {
                descriptor.Flags |= IscCodes.DSC_null;
            }
            else
            {
                this.SetDscType(ref descriptor, value);
            }

            if (descriptor.Type == IscCodes.dtype_cstring || descriptor.Type == IscCodes.dtype_varying)
            {
                descriptor.SubType = (short)charset.Identifier;
            }

            return descriptor;
        }
        private byte[] GetBytes(ParamDsc descriptor, int type)
        {
            if (descriptor.Length == 0 || descriptor.Data == IntPtr.Zero)
            {
                return null;
            }

            byte[] buffer = new byte[descriptor.Length];

            switch (type & ~1)
            {
                case IscCodes.SQL_VARYING:
                    buffer = new byte[Marshal.ReadInt16(descriptor.Data)];
                    IntPtr tmp = this.GetIntPtr(descriptor.Data, 2);
                    Marshal.Copy(tmp, buffer, 0, buffer.Length);
                    return buffer;

                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_SHORT:
                case IscCodes.SQL_LONG:
                case IscCodes.SQL_FLOAT:
                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                case IscCodes.SQL_TIMESTAMP:
                case IscCodes.SQL_TYPE_TIME:
                case IscCodes.SQL_TYPE_DATE:
                    Marshal.Copy(descriptor.Data, buffer, 0, buffer.Length);
                    return buffer;

                default:
                    throw new NotSupportedException("Unknown data type");
            }
        }
        private object GetValue(ParamDsc descriptor, Charset charset)
        {
            DbField field = new DbField();

            if (descriptor.Type == dtype_null)
            {
                return null;
            }
            if (descriptor.Type == IscCodes.dtype_byte)
            {
                return null;
            }

            DbDataType dbType = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType);

            field.DataType      = (short)TypeHelper.GetFbType(dbType, true);
            field.NumericScale  = descriptor.Scale;
            field.SubType       = descriptor.SubType;

            byte[] data = this.GetBytes(descriptor, field.DataType);

            field.SetValue(data);

            return field.Value;
        }
        public IntPtr MarshalManagedToNative(ParamDsc descriptor)
        {
            int size = Marshal.SizeOf(descriptor);
            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(descriptor, ptr, true);

            return ptr;
        }
Ejemplo n.º 12
0
        private void SetDscType(ref ParamDsc descriptor, object value)
        {
            TypeCode code = Type.GetTypeCode(value.GetType());

            switch (code)
            {
            case TypeCode.Object:
                descriptor.Type    = IscCodes.dtype_blob;
                descriptor.SubType = 0;
                break;

            case TypeCode.Char:
                descriptor.Type   = IscCodes.dtype_cstring;
                descriptor.Length = (short)value.ToString().Length;
                break;

            case TypeCode.String:
                descriptor.Type   = IscCodes.dtype_varying;
                descriptor.Length = (short)value.ToString().Length;
                break;

            case TypeCode.Boolean:
            case TypeCode.Byte:
            case TypeCode.SByte:
                descriptor.Type   = IscCodes.dtype_byte;
                descriptor.Length = 1;
                break;

            case TypeCode.Int16:
            case TypeCode.UInt16:
                descriptor.Type   = IscCodes.dtype_short;
                descriptor.Length = 2;
                break;

            case TypeCode.Int32:
            case TypeCode.UInt32:
                descriptor.Type   = IscCodes.dtype_long;
                descriptor.Length = 4;
                break;

            case TypeCode.Int64:
            case TypeCode.UInt64:
                descriptor.Type   = IscCodes.dtype_int64;
                descriptor.Length = 8;
                break;

            case TypeCode.Single:
                descriptor.Type   = IscCodes.dtype_real;
                descriptor.Length = 4;
                break;

            case TypeCode.Double:
            case TypeCode.Decimal:
                descriptor.Type   = IscCodes.dtype_double;
                descriptor.Length = 8;
                break;

            case TypeCode.DateTime:
                descriptor.Type   = IscCodes.dtype_timestamp;
                descriptor.Length = 8;
                break;
            }
        }