Beispiel #1
0
        public void Detach()
        {
            int[] statusVector = FesConnection.GetNewStatusVector();
            int   svcHandle    = this.Handle;

            FbClient.isc_service_detach(statusVector, ref svcHandle);

            // Parse status	vector
            this.ParseStatusVector(statusVector);

            // Update status vector
            this.handle = svcHandle;
        }
Beispiel #2
0
        public void DropDatabase()
        {
            lock (this)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = this.Handle;

                FbClient.isc_drop_database(statusVector, ref dbHandle);

                this.ParseStatusVector(statusVector);

                this.handle = 0;
            }
        }
Beispiel #3
0
        protected override void PutSegment(byte[] buffer)
        {
            lock (this.db)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();

                FbClient.isc_put_segment(
                    statusVector,
                    ref this.blobHandle,
                    (short)buffer.Length,
                    buffer);

                FesConnection.ParseStatusVector(statusVector);
            }
        }
Beispiel #4
0
        internal void ParseStatusVector(int[] statusVector)
        {
            IscException ex = FesConnection.ParseStatusVector(statusVector);

            if (ex != null)
            {
                if (ex.IsWarning)
                {
                    this.warningMessage(ex);
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #5
0
        public void Start(ServiceParameterBuffer spb)
        {
            int[] statusVector = FesConnection.GetNewStatusVector();
            int   svcHandle    = this.Handle;
            int   reserved     = 0;

            FbClient.isc_service_start(
                statusVector,
                ref svcHandle,
                ref reserved,
                (short)spb.Length,
                spb.ToArray());

            // Parse status	vector
            this.ParseStatusVector(statusVector);
        }
Beispiel #6
0
        protected override byte[] GetSegment()
        {
            short requested     = (short)this.SegmentSize;
            short segmentLength = 0;

            lock (this.db)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();

                MemoryStream segment = new MemoryStream();
                byte[]       tmp     = new byte[requested];

                int status = FbClient.isc_get_segment(
                    statusVector,
                    ref this.blobHandle,
                    ref segmentLength,
                    requested,
                    tmp);

                if (segmentLength > 0)
                {
                    segment.Write(tmp, 0, segmentLength > requested ? requested : segmentLength);
                }

                this.RblRemoveValue(IscCodes.RBL_segment);
                if (statusVector[1] == IscCodes.isc_segstr_eof)
                {
                    segment.SetLength(0);
                    this.RblAddValue(IscCodes.RBL_eof_pending);
                }
                else
                {
                    if (status == 0 || statusVector[1] == IscCodes.isc_segment)
                    {
                        this.RblAddValue(IscCodes.RBL_segment);
                    }
                    else
                    {
                        this.db.ParseStatusVector(statusVector);
                    }
                }

                return(segment.ToArray());
            }
        }
Beispiel #7
0
        private void DatabaseInfo(byte[] items, byte[] buffer, int bufferLength)
        {
            lock (this)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = this.Handle;

                FbClient.isc_database_info(
                    statusVector,
                    ref dbHandle,
                    (short)items.Length,
                    items,
                    (short)bufferLength,
                    buffer);

                this.ParseStatusVector(statusVector);
            }
        }
Beispiel #8
0
        public void Detach()
        {
            lock (this)
            {
                if (this.TransactionCount > 0)
                {
                    throw new IscException(IscCodes.isc_open_trans, this.TransactionCount);
                }

                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = this.Handle;

                FbClient.isc_detach_database(statusVector, ref dbHandle);

                this.handle = dbHandle;

                FesConnection.ParseStatusVector(statusVector);
            }
        }
Beispiel #9
0
        public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service)
        {
            int[] statusVector = FesConnection.GetNewStatusVector();
            int   svcHandle    = this.Handle;

            FbClient.isc_service_attach(
                statusVector,
                (short)service.Length,
                service,
                ref svcHandle,
                (short)spb.Length,
                spb.ToArray());

            // Parse status	vector
            this.ParseStatusVector(statusVector);

            // Update status vector
            this.handle = svcHandle;
        }
Beispiel #10
0
        protected override void Open()
        {
            lock (this.db)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();

                int dbHandle = this.db.Handle;
                int trHandle = this.transaction.Handle;

                FbClient.isc_open_blob2(
                    statusVector,
                    ref dbHandle,
                    ref trHandle,
                    ref this.blobHandle,
                    ref this.blobId,
                    0,
                    new byte[0]);

                FesConnection.ParseStatusVector(statusVector);
            }
        }
Beispiel #11
0
        private void Allocate()
        {
            lock (this.db)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = this.db.Handle;
                int   stmtHandle   = this.handle;

                FbClient.isc_dsql_allocate_statement(
                    statusVector,
                    ref dbHandle,
                    ref stmtHandle);

                this.db.ParseStatusVector(statusVector);

                this.handle         = stmtHandle;
                this.allRowsFetched = false;
                this.state          = StatementState.Allocated;
                this.statementType  = DbStatementType.None;
            }
        }
Beispiel #12
0
        public override byte[] GetSqlInfo(byte[] items, int bufferLength)
        {
            lock (this.db)
            {
                byte[] buffer       = new byte[bufferLength];
                int[]  statusVector = FesConnection.GetNewStatusVector();
                int    stmtHandle   = this.handle;

                FbClient.isc_dsql_sql_info(
                    statusVector,
                    ref stmtHandle,
                    (short)items.Length,
                    items,
                    (short)bufferLength,
                    buffer);

                this.db.ParseStatusVector(statusVector);

                return(buffer);
            }
        }
Beispiel #13
0
        public override void PutSlice(System.Array sourceArray, int sliceLength)
        {
            int[] statusVector = FesConnection.GetNewStatusVector();

            int dbHandle = this.db.Handle;
            int trHandle = this.transaction.Handle;

            ArrayDescMarshaler marshaler = ArrayDescMarshaler.GetInstance();

            IntPtr arrayDesc = marshaler.MarshalManagedToNative(this.Descriptor);

            // Obtain the System of	type of	Array elements and
            // Fill	buffer
            Type systemType = this.GetSystemType();

            byte[] buffer = new     byte[sliceLength];
            if (systemType.IsPrimitive)
            {
                Buffer.BlockCopy(sourceArray, 0, buffer, 0, buffer.Length);
            }
            else
            {
                buffer = this.EncodeSlice(this.Descriptor, sourceArray, sliceLength);
            }

            FbClient.isc_array_put_slice(
                statusVector,
                ref dbHandle,
                ref trHandle,
                ref this.handle,
                arrayDesc,
                buffer,
                ref sliceLength);

            // Free	memory
            marshaler.CleanUpNativeData(ref arrayDesc);

            FesConnection.ParseStatusVector(statusVector);
        }
Beispiel #14
0
        protected override void Create()
        {
            lock (this.db)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();

                int dbHandle = this.db.Handle;
                int trHandle = this.transaction.Handle;

                FbClient.isc_create_blob2(
                    statusVector,
                    ref dbHandle,
                    ref trHandle,
                    ref this.blobHandle,
                    ref this.blobId,
                    0,
                    new byte[0]);

                FesConnection.ParseStatusVector(statusVector);

                this.RblAddValue(IscCodes.RBL_create);
            }
        }
Beispiel #15
0
        public void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = 0;

                FbClient.isc_attach_database(
                    statusVector,
                    (short)database.Length,
                    database,
                    ref dbHandle,
                    (short)dpb.Length,
                    dpb.ToArray());

                this.handle = dbHandle;

                this.ParseStatusVector(statusVector);

                // Get server version
                this.serverVersion = this.GetServerVersion();
            }
        }
Beispiel #16
0
        public void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database)
        {
            lock (this)
            {
                int[] statusVector = FesConnection.GetNewStatusVector();
                int   dbHandle     = this.Handle;

                FbClient.isc_create_database(
                    statusVector,
                    (short)database.Length,
                    database,
                    ref dbHandle,
                    (short)dpb.Length,
                    dpb.ToArray(),
                    0);

                this.ParseStatusVector(statusVector);

                this.handle = dbHandle;

                this.Detach();
            }
        }
Beispiel #17
0
        public override void Prepare(string commandText)
        {
            // Clear data
            this.Clear();
            this.parameters = null;
            this.fields     = null;

            lock (this.db)
            {
                if (this.state == StatementState.Deallocated)
                {
                    // Allocate	statement
                    this.Allocate();
                }

                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.GetInstance();

                // Setup fields	structure
                this.fields = new Descriptor(1);

                IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields);

                int[] statusVector = FesConnection.GetNewStatusVector();
                int   trHandle     = this.transaction.Handle;
                int   stmtHandle   = this.handle;

                byte[] buffer = this.db.Charset.GetBytes(commandText);

                FbClient.isc_dsql_prepare(
                    statusVector,
                    ref trHandle,
                    ref stmtHandle,
                    (short)buffer.Length,
                    buffer,
                    this.db.Dialect,
                    sqlda);

                // Marshal Pointer
                Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda);

                // Free	memory
                marshaler.CleanUpNativeData(ref sqlda);

                // Parse status	vector
                this.db.ParseStatusVector(statusVector);

                // Describe	fields
                this.fields = descriptor;
                if (this.fields.ActualCount > 0 &&
                    this.fields.ActualCount != this.fields.Count)
                {
                    this.Describe();
                }
                else
                {
                    if (this.fields.ActualCount == 0)
                    {
                        this.fields = new Descriptor(0);
                    }
                }

                // Reset actual	field values
                this.fields.ResetValues();

                // Get Statement type
                this.statementType = this.GetStatementType();

                // Update state
                this.state = StatementState.Prepared;
            }
        }
Beispiel #18
0
        public override DbValue[] Fetch()
        {
            DbValue[] row = null;

            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statment is not correctly created.");
            }
            if (this.statementType != DbStatementType.Select &&
                this.statementType != DbStatementType.SelectForUpdate)
            {
                return(null);
            }

            lock (this.db)
            {
                if (!this.allRowsFetched)
                {
                    // Marshal structures to pointer
                    XsqldaMarshaler marshaler = XsqldaMarshaler.GetInstance();

                    // Reset actual	field values
                    this.fields.ResetValues();

                    IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, fields);

                    int[] statusVector = FesConnection.GetNewStatusVector();
                    int   stmtHandle   = this.handle;

                    int status = FbClient.isc_dsql_fetch(
                        statusVector,
                        ref stmtHandle,
                        IscCodes.SQLDA_VERSION1,
                        sqlda);

                    // Obtain values
                    Descriptor rowDesc = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda);

                    if (this.fields.Count == rowDesc.Count)
                    {
                        // Try to preserve Array Handle information
                        for (int i = 0; i < this.fields.Count; i++)
                        {
                            if (this.fields[i].IsArray() &&
                                this.fields[i].ArrayHandle != null)
                            {
                                rowDesc[i].ArrayHandle = this.fields[i].ArrayHandle;
                            }
                        }
                    }

                    this.fields = rowDesc;

                    // Free	memory
                    marshaler.CleanUpNativeData(ref sqlda);

                    // Parse status	vector
                    this.db.ParseStatusVector(statusVector);

                    if (status == 100)
                    {
                        this.allRowsFetched = true;
                    }
                    else
                    {
                        // Set row values
                        row = new DbValue[this.fields.ActualCount];
                        for (int i = 0; i < row.Length; i++)
                        {
                            row[i] = new DbValue(this, this.fields[i]);
                        }
                    }
                }
            }

            return(row);
        }
Beispiel #19
0
        public override void DescribeParameters()
        {
            lock (this.db)
            {
                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.GetInstance();

                this.parameters = new Descriptor(1);

                IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, parameters);

                int[] statusVector = FesConnection.GetNewStatusVector();
                int   stmtHandle   = this.handle;

                FbClient.isc_dsql_describe_bind(
                    statusVector,
                    ref stmtHandle,
                    IscCodes.SQLDA_VERSION1,
                    sqlda);

                Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda);

                // Parse status	vector
                this.db.ParseStatusVector(statusVector);

                if (descriptor.ActualCount != 0 &&
                    descriptor.Count != descriptor.ActualCount)
                {
                    short n = descriptor.ActualCount;
                    descriptor = new Descriptor(n);

                    // Fre memory
                    marshaler.CleanUpNativeData(ref sqlda);

                    // Marshal new structure
                    sqlda = marshaler.MarshalManagedToNative(this.db.Charset, descriptor);

                    FbClient.isc_dsql_describe_bind(
                        statusVector,
                        ref stmtHandle,
                        IscCodes.SQLDA_VERSION1,
                        sqlda);

                    descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda);

                    // Free	memory
                    marshaler.CleanUpNativeData(ref sqlda);

                    // Parse status	vector
                    this.db.ParseStatusVector(statusVector);
                }
                else
                {
                    if (descriptor.ActualCount == 0)
                    {
                        descriptor = new Descriptor(0);
                    }
                }

                // Free	memory
                if (sqlda != IntPtr.Zero)
                {
                    marshaler.CleanUpNativeData(ref sqlda);
                }

                // Update parameter	descriptor
                this.parameters = descriptor;
            }
        }
Beispiel #20
0
        public void BeginTransaction(TransactionParameterBuffer tpb)
        {
            lock (this.db)
            {
                if (this.state != TransactionState.NoTransaction)
                {
                    throw new IscException(
                              IscCodes.isc_arg_gds,
                              IscCodes.isc_tra_state,
                              this.handle,
                              "no valid");
                }

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

                try
                {
                    this.state = TransactionState.TrasactionStarting;

                    // Set db handle
                    teb.dbb_ptr = Marshal.AllocHGlobal(4);
                    Marshal.WriteInt32(teb.dbb_ptr, this.db.Handle);

                    // Set tpb length
                    teb.tpb_len = tpb.Length;

                    // Set TPB data
                    teb.tpb_ptr = Marshal.AllocHGlobal(tpb.Length);
                    Marshal.Copy(tpb.ToArray(), 0, teb.tpb_ptr, tpb.Length);

                    // Alloc memory	for	the	IscTeb structure
                    int size = Marshal.SizeOf(typeof(IscTeb));
                    tebData = Marshal.AllocHGlobal(size);

                    Marshal.StructureToPtr(teb, tebData, true);

                    int[] statusVector = FesConnection.GetNewStatusVector();
                    int   trHandle     = this.handle;

                    FbClient.isc_start_multiple(
                        statusVector,
                        ref trHandle,
                        1,
                        tebData);

                    this.handle = trHandle;

                    // Parse status	vector
                    this.db.ParseStatusVector(statusVector);

                    // Update transaction state
                    this.state = TransactionState.TransactionStarted;

                    // Update transaction count
                    this.db.TransactionCount++;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    // Free	memory
                    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)
                    {
                        Marshal.DestroyStructure(tebData, typeof(IscTeb));
                        Marshal.FreeHGlobal(tebData);
                    }
                }
            }
        }
Beispiel #21
0
        public override void Execute()
        {
            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statment is not correctly created.");
            }

            lock (this.db)
            {
                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.GetInstance();

                IntPtr inSqlda  = IntPtr.Zero;
                IntPtr outSqlda = IntPtr.Zero;

                if (this.parameters != null)
                {
                    inSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.parameters);
                }
                if (this.statementType == DbStatementType.StoredProcedure)
                {
                    this.Fields.ResetValues();
                    outSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields);
                }

                int[] statusVector = FesConnection.GetNewStatusVector();
                int   trHandle     = this.transaction.Handle;
                int   stmtHandle   = this.handle;

                FbClient.isc_dsql_execute2(
                    statusVector,
                    ref trHandle,
                    ref stmtHandle,
                    IscCodes.SQLDA_VERSION1,
                    inSqlda,
                    outSqlda);

                if (outSqlda != IntPtr.Zero)
                {
                    Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, outSqlda);

                    // This	would be an	Execute	procedure
                    DbValue[] values = new DbValue[descriptor.Count];

                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = new DbValue(this, descriptor[i]);
                    }

                    this.outputParams.Enqueue(values);
                }

                // Free	memory
                marshaler.CleanUpNativeData(ref inSqlda);
                marshaler.CleanUpNativeData(ref outSqlda);

                this.db.ParseStatusVector(statusVector);

                this.UpdateRecordsAffected();

                this.state = StatementState.Executed;
            }
        }