Esempio n. 1
0
        public override void BeginTransaction(TransactionParameterBuffer tpb)
        {
            if (_state != TransactionState.NoTransaction)
            {
                throw new InvalidOperationException();
            }

            IscTeb teb     = new IscTeb();
            IntPtr tebData = IntPtr.Zero;

            try
            {
                ClearStatusVector();

                teb.dbb_ptr = Marshal.AllocHGlobal(4);
                Marshal.WriteInt32(teb.dbb_ptr, _db.Handle);

                teb.tpb_len = tpb.Length;

                teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                int size = Marshal2.SizeOf <IscTeb>();
                tebData = Marshal.AllocHGlobal(size);

                Marshal.StructureToPtr(teb, tebData, true);

                _db.FbClient.isc_start_multiple(
                    _statusVector,
                    ref _handle,
                    1,
                    tebData);

                _db.ProcessStatusVector(_statusVector);

                _state = TransactionState.Active;

                _db.TransactionCount++;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (teb.dbb_ptr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(teb.dbb_ptr);
                }
                if (teb.tpb_ptr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(teb.tpb_ptr);
                }
                if (tebData != IntPtr.Zero)
                {
                    Marshal2.DestroyStructure <IscTeb>(tebData);
                    Marshal.FreeHGlobal(tebData);
                }
            }
        }
        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(Marshal2.SizeOf <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));
        }
 public static int ComputeLength(int n)
 {
     return(Marshal2.SizeOf <ArrayDescMarshal>() + n * Marshal2.SizeOf <ArrayBoundMarshal>());
 }