public static IntPtr MarshalManagedToNative(Charset charset, Descriptor descriptor)
		{
			// Set up XSQLDA structure
			var xsqlda = new XSQLDA
			{
				version = descriptor.Version,
				sqln = descriptor.Count,
				sqld = descriptor.ActualCount
			};

			var xsqlvar = new XSQLVAR[descriptor.Count];

			for (var i = 0; i < xsqlvar.Length; i++)
			{
				// Create a	new	XSQLVAR	structure and fill it
				xsqlvar[i] = new XSQLVAR
				{
					sqltype = descriptor[i].DataType,
					sqlscale = descriptor[i].NumericScale,
					sqlsubtype = descriptor[i].SubType,
					sqllen = descriptor[i].Length
				};


				// Create a	new	pointer	for	the	xsqlvar	data
				if (descriptor[i].HasDataType() && descriptor[i].DbDataType != DbDataType.Null)
				{
					var buffer = descriptor[i].DbValue.GetBytes();
					xsqlvar[i].sqldata = Marshal.AllocHGlobal(buffer.Length);
					Marshal.Copy(buffer, 0, xsqlvar[i].sqldata, buffer.Length);
				}
				else
				{
					xsqlvar[i].sqldata = Marshal.AllocHGlobal(0);
				}

				// Create a	new	pointer	for	the	sqlind value
				xsqlvar[i].sqlind = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(short)));
				Marshal.WriteInt16(xsqlvar[i].sqlind, descriptor[i].NullFlag);

				// Name
				xsqlvar[i].sqlname = GetStringBuffer(charset, descriptor[i].Name);
				xsqlvar[i].sqlname_length = (short)descriptor[i].Name.Length;

				// Relation	Name
				xsqlvar[i].relname = GetStringBuffer(charset, descriptor[i].Relation);
				xsqlvar[i].relname_length = (short)descriptor[i].Relation.Length;

				// Owner name
				xsqlvar[i].ownername = GetStringBuffer(charset, descriptor[i].Owner);
				xsqlvar[i].ownername_length = (short)descriptor[i].Owner.Length;

				// Alias name
				xsqlvar[i].aliasname = GetStringBuffer(charset, descriptor[i].Alias);
				xsqlvar[i].aliasname_length = (short)descriptor[i].Alias.Length;
			}

			return MarshalManagedToNative(xsqlda, xsqlvar);
		}
Ejemplo n.º 2
0
        public IntPtr MarshalManagedToNative(Charset charset, Descriptor descriptor)
        {
            // Set up XSQLDA structure
            XSQLDA xsqlda = new XSQLDA();

            xsqlda.version = descriptor.Version;
            xsqlda.sqln    = descriptor.Count;
            xsqlda.sqld    = descriptor.ActualCount;

            XSQLVAR[] xsqlvar = new XSQLVAR[descriptor.Count];

            for (int i = 0; i < xsqlvar.Length; i++)
            {
                // Create a	new	XSQLVAR	structure and fill it
                xsqlvar[i] = new XSQLVAR();

                xsqlvar[i].sqltype    = descriptor[i].DataType;
                xsqlvar[i].sqlscale   = descriptor[i].NumericScale;
                xsqlvar[i].sqlsubtype = descriptor[i].SubType;
                xsqlvar[i].sqllen     = descriptor[i].Length;

                // Create a	new	pointer	for	the	xsqlvar	data
                if (descriptor[i].HasDataType() && descriptor[i].DbDataType != DbDataType.Null)
                {
                    byte[] buffer = descriptor[i].DbValue.GetBytes();
                    xsqlvar[i].sqldata = Marshal.AllocHGlobal(buffer.Length);
                    Marshal.Copy(buffer, 0, xsqlvar[i].sqldata, buffer.Length);
                }
                else
                {
                    xsqlvar[i].sqldata = Marshal.AllocHGlobal(0);
                }

                // Create a	new	pointer	for	the	sqlind value
                xsqlvar[i].sqlind = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int16)));
                Marshal.WriteInt16(xsqlvar[i].sqlind, descriptor[i].NullFlag);

                // Name
                xsqlvar[i].sqlname        = this.GetStringBuffer(charset, descriptor[i].Name);
                xsqlvar[i].sqlname_length = (short)descriptor[i].Name.Length;

                // Relation	Name
                xsqlvar[i].relname        = this.GetStringBuffer(charset, descriptor[i].Relation);
                xsqlvar[i].relname_length = (short)descriptor[i].Relation.Length;

                // Owner name
                xsqlvar[i].ownername        = this.GetStringBuffer(charset, descriptor[i].Owner);
                xsqlvar[i].ownername_length = (short)descriptor[i].Owner.Length;

                // Alias name
                xsqlvar[i].aliasname        = this.GetStringBuffer(charset, descriptor[i].Alias);
                xsqlvar[i].aliasname_length = (short)descriptor[i].Alias.Length;
            }

            return(this.MarshalManagedToNative(xsqlda, xsqlvar));
        }
Ejemplo n.º 3
0
        public Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData, bool fetching)
        {
            // Obtain XSQLDA information
            XSQLDA xsqlda = new XSQLDA();

            xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

            // Create a	new	Descriptor
            Descriptor descriptor = new Descriptor(xsqlda.sqln);

            descriptor.ActualCount = xsqlda.sqld;

            // Obtain XSQLVAR members information

            XSQLVAR xsqlvar = new XSQLVAR();

            for (var i = 0; i < xsqlda.sqln; i++)
            {
                IntPtr ptr = this.GetIntPtr(pNativeData, this.ComputeLength(i));
                MarshalVAR(ptr, xsqlvar);

                // Map XSQLVAR information to Descriptor
                descriptor[i].DataType     = xsqlvar.sqltype;
                descriptor[i].NumericScale = xsqlvar.sqlscale;
                descriptor[i].SubType      = xsqlvar.sqlsubtype;
                descriptor[i].Length       = xsqlvar.sqllen;

                // Decode sqlind value
                if (xsqlvar.sqlind == IntPtr.Zero)
                {
                    descriptor[i].NullFlag = 0;
                }
                else
                {
                    descriptor[i].NullFlag = Marshal.ReadInt16(xsqlvar.sqlind);
                }

                // Set value
                if (fetching)
                {
                    if (descriptor[i].NullFlag != -1)
                    {
                        descriptor[i].SetValue(this.GetBytes(xsqlvar));
                    }
                }

                descriptor[i].Name     = GetString(charset, xsqlvar.sqlname, xsqlvar.sqlname_length);
                descriptor[i].Relation = GetString(charset, xsqlvar.relname, xsqlvar.relname_length);
                descriptor[i].Owner    = GetString(charset, xsqlvar.ownername, xsqlvar.ownername_length);
                descriptor[i].Alias    = GetString(charset, xsqlvar.aliasname, xsqlvar.aliasname_length);
            }

            return(descriptor);
        }
Ejemplo n.º 4
0
        public IntPtr MarshalManagedToNative(XSQLDA xsqlda, XSQLVAR[] xsqlvar)
        {
            int    size = this.ComputeLength(xsqlda.sqln);
            IntPtr ptr  = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(xsqlda, ptr, true);

            for (int i = 0; i < xsqlvar.Length; i++)
            {
                int offset = this.ComputeLength(i);
                Marshal.StructureToPtr(xsqlvar[i], this.GetIntPtr(ptr, offset), true);
            }

            return(ptr);
        }
		public void CleanUpNativeData(ref IntPtr pNativeData)
		{
			if (pNativeData != IntPtr.Zero)
			{
				// Obtain XSQLDA information
				XSQLDA xsqlda = new XSQLDA();

				xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

				// Destroy XSQLDA structure
				Marshal.DestroyStructure(pNativeData, typeof(XSQLDA));

				// Destroy XSQLVAR structures
				for (int i = 0; i < xsqlda.sqln; i++)
				{
					IntPtr ptr1 = this.GetIntPtr(pNativeData, this.ComputeLength(i));

					// Free	sqldata	and	sqlind pointers	if needed
					XSQLVAR sqlvar = (XSQLVAR)Marshal.PtrToStructure(ptr1, typeof(XSQLVAR));

					if (sqlvar.sqldata != IntPtr.Zero)
					{
						Marshal.FreeHGlobal(sqlvar.sqldata);
						sqlvar.sqldata = IntPtr.Zero;
					}
					if (sqlvar.sqlind != IntPtr.Zero)
					{
						Marshal.FreeHGlobal(sqlvar.sqlind);
						sqlvar.sqlind = IntPtr.Zero;
					}

					IntPtr ptr2 = this.GetIntPtr(pNativeData, this.ComputeLength(i));
					Marshal.DestroyStructure(ptr2, typeof(XSQLVAR));
				}

				// Free	pointer	memory
				Marshal.FreeHGlobal(pNativeData);

				pNativeData = IntPtr.Zero;
			}
		}
Ejemplo n.º 6
0
        public void CleanUpNativeData(ref IntPtr pNativeData)
        {
            if (pNativeData != IntPtr.Zero)
            {
                // Obtain XSQLDA information
                XSQLDA xsqlda = new XSQLDA();

                xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

                // Destroy XSQLDA structure
                Marshal.DestroyStructure(pNativeData, typeof(XSQLDA));

                // Destroy XSQLVAR structures
                for (int i = 0; i < xsqlda.sqln; i++)
                {
                    IntPtr ptr1 = this.GetIntPtr(pNativeData, this.ComputeLength(i));

                    // Free	sqldata	and	sqlind pointers	if needed
                    XSQLVAR sqlvar = (XSQLVAR)Marshal.PtrToStructure(ptr1, typeof(XSQLVAR));

                    if (sqlvar.sqldata != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqldata);
                        sqlvar.sqldata = IntPtr.Zero;
                    }
                    if (sqlvar.sqlind != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(sqlvar.sqlind);
                        sqlvar.sqlind = IntPtr.Zero;
                    }

                    IntPtr ptr2 = this.GetIntPtr(pNativeData, this.ComputeLength(i));
                    Marshal.DestroyStructure(ptr2, typeof(XSQLVAR));
                }

                // Free	pointer	memory
                Marshal.FreeHGlobal(pNativeData);

                pNativeData = IntPtr.Zero;
            }
        }
		public IntPtr MarshalManagedToNative(Charset charset, Descriptor descriptor)
		{
			// Set up XSQLDA structure
			XSQLDA xsqlda = new XSQLDA();

			xsqlda.version  = descriptor.Version;
			xsqlda.sqln     = descriptor.Count;
			xsqlda.sqld     = descriptor.ActualCount;

			XSQLVAR[] xsqlvar = new XSQLVAR[descriptor.Count];

			for (int i = 0; i < xsqlvar.Length; i++)
			{
				// Create a	new	XSQLVAR	structure and fill it
				xsqlvar[i] = new XSQLVAR();

				xsqlvar[i].sqltype      = descriptor[i].DataType;
				xsqlvar[i].sqlscale     = descriptor[i].NumericScale;
				xsqlvar[i].sqlsubtype   = descriptor[i].SubType;
				xsqlvar[i].sqllen       = descriptor[i].Length;

				// Create a	new	pointer	for	the	xsqlvar	data
				byte[] buffer = descriptor[i].DbValue.GetBytes();
				xsqlvar[i].sqldata = Marshal.AllocHGlobal(buffer.Length);
				Marshal.Copy(buffer, 0, xsqlvar[i].sqldata, buffer.Length);

				// Create a	new	pointer	for	the	sqlind value
				xsqlvar[i].sqlind = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int16)));
				Marshal.WriteInt16(xsqlvar[i].sqlind, descriptor[i].NullFlag);

				// Name
				xsqlvar[i].sqlname = this.GetStringBuffer(charset, descriptor[i].Name);
				xsqlvar[i].sqlname_length = (short)descriptor[i].Name.Length;

				// Relation	Name
				xsqlvar[i].relname = this.GetStringBuffer(charset, descriptor[i].Relation);
				xsqlvar[i].relname_length = (short)descriptor[i].Relation.Length;

				// Owner name
				xsqlvar[i].ownername = this.GetStringBuffer(charset, descriptor[i].Owner);
				xsqlvar[i].ownername_length = (short)descriptor[i].Owner.Length;

				// Alias name
				xsqlvar[i].aliasname = this.GetStringBuffer(charset, descriptor[i].Alias);
				xsqlvar[i].aliasname_length = (short)descriptor[i].Alias.Length;
			}

			return this.MarshalManagedToNative(xsqlda, xsqlvar);
		}
		public Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData, bool fetching)
		{
			// Obtain XSQLDA information
			XSQLDA xsqlda = new XSQLDA();

			xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

			// Create a	new	Descriptor
			Descriptor descriptor   = new Descriptor(xsqlda.sqln);
			descriptor.ActualCount  = xsqlda.sqld;

			// Obtain XSQLVAR members information
			XSQLVAR[] xsqlvar = new XSQLVAR[xsqlda.sqln];

			for (int i = 0; i < xsqlvar.Length; i++)
			{
				IntPtr ptr = this.GetIntPtr(pNativeData, this.ComputeLength(i));
				xsqlvar[i] = (XSQLVAR)Marshal.PtrToStructure(ptr, typeof(XSQLVAR));

				// Map XSQLVAR information to Descriptor
				descriptor[i].DataType      = xsqlvar[i].sqltype;
				descriptor[i].NumericScale  = xsqlvar[i].sqlscale;
				descriptor[i].SubType       = xsqlvar[i].sqlsubtype;
				descriptor[i].Length        = xsqlvar[i].sqllen;

				// Decode sqlind value
				if (xsqlvar[i].sqlind == IntPtr.Zero)
				{
					descriptor[i].NullFlag = 0;
				}
				else
				{
					descriptor[i].NullFlag = Marshal.ReadInt16(xsqlvar[i].sqlind);
				}

				// Set value
				if (fetching)
				{
					if (descriptor[i].NullFlag != -1)
					{
						descriptor[i].SetValue(this.GetBytes(xsqlvar[i]));
					}
				}

				descriptor[i].Name      = this.GetString(charset, xsqlvar[i].sqlname);
				descriptor[i].Relation  = this.GetString(charset, xsqlvar[i].relname);
				descriptor[i].Owner     = this.GetString(charset, xsqlvar[i].ownername);
				descriptor[i].Alias     = this.GetString(charset, xsqlvar[i].aliasname);
			}

			return descriptor;
		}
		public IntPtr MarshalManagedToNative(XSQLDA xsqlda, XSQLVAR[] xsqlvar)
		{
			int size = this.ComputeLength(xsqlda.sqln);
			IntPtr ptr = Marshal.AllocHGlobal(size);

			Marshal.StructureToPtr(xsqlda, ptr, true);

			for (int i = 0; i < xsqlvar.Length; i++)
			{
				int offset = this.ComputeLength(i);
				Marshal.StructureToPtr(xsqlvar[i], this.GetIntPtr(ptr, offset), true);
			}

			return ptr;
		}
		public static IntPtr MarshalManagedToNative(XSQLDA xsqlda, XSQLVAR[] xsqlvar)
		{
			var size = ComputeLength(xsqlda.sqln);
			var ptr = Marshal.AllocHGlobal(size);

			Marshal.StructureToPtr(xsqlda, ptr, true);

			for (var i = 0; i < xsqlvar.Length; i++)
			{
				var offset = ComputeLength(i);
				Marshal.StructureToPtr(xsqlvar[i], GetIntPtr(ptr, offset), true);
			}

			return ptr;
		}