Exemple #1
0
        public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service)
        {
            int[] statusVector = ExtConnection.GetNewStatusVector();
            int   svcHandle    = this.Handle;

            SafeNativeMethods.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;
        }
Exemple #2
0
        private void Allocate()
        {
            lock (this.db)
            {
                int[] statusVector = ExtConnection.GetNewStatusVector();
                int   dbHandle     = this.db.Handle;
                int   stmtHandle   = this.handle;

                SafeNativeMethods.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;
            }
        }
Exemple #3
0
        protected override byte[] GetSqlInfo(byte[] items, int bufferLength)
        {
            lock (this.db)
            {
                byte[] buffer       = new byte[bufferLength];
                int[]  statusVector = ExtConnection.GetNewStatusVector();
                int    stmtHandle   = this.handle;

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

                this.db.ParseStatusVector(statusVector);

                return(buffer);
            }
        }
        protected override void Open()
        {
            lock (this.db)
            {
                int[] statusVector = ExtConnection.GetNewStatusVector();

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

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

                ExtConnection.ParseStatusVector(statusVector);
            }
        }
Exemple #5
0
        public override void PutSlice(System.Array sourceArray, int sliceLength)
        {
            int[] statusVector = ExtConnection.GetNewStatusVector();

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

            ArrayDescMarshaler marshaler = ArrayDescMarshaler.Instance;

            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);
            }

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

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

            ExtConnection.ParseStatusVector(statusVector);
        }
        private void SetValue(string name, object value, bool oldValue)
        {
            int[]  statusVector = ExtConnection.GetNewStatusVector();
            byte[] fieldName    = new byte[32];

            _database.Charset.GetBytes(name, 0, name.Length, fieldName, 0);

            // Marshal structures to pointer
            ParamDscMarshaler marshaler = ParamDscMarshaler.Instance;

            IntPtr valuePtr = marshaler.MarshalManagedToNative(_database.Charset, value);

            bool result = SafeNativeMethods.isc_set_trigger_field(
                statusVector,
                (oldValue) ? 0 : 1,
                fieldName,
                valuePtr);

            marshaler.CleanUpNativeData(ref valuePtr);

            ExtConnection.ParseStatusVector(statusVector);
        }
        protected override void Create()
        {
            lock (this.db)
            {
                int[] statusVector = ExtConnection.GetNewStatusVector();

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

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

                ExtConnection.ParseStatusVector(statusVector);

                this.RblAddValue(IscCodes.RBL_create);
            }
        }
Exemple #8
0
        public override void DescribeParameters()
        {
            lock (this.db)
            {
                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

                this.parameters = new Descriptor(1);

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

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

                SafeNativeMethods.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);

                    SafeNativeMethods.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;
            }
        }
Exemple #9
0
        public override DbValue[] Fetch()
        {
            DbValue[] row = null;

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

            lock (this.db)
            {
                if (!this.allRowsFetched)
                {
                    // Get the XSQLDA Marshaler
                    XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

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

                    // Marshal structures to pointer
                    IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, fields);

                    // Creta a new status vector
                    int[] statusVector = ExtConnection.GetNewStatusVector();

                    // Statement handle to be passed to the fetch method
                    int stmtHandle = this.handle;

                    // Fetch data
                    int status = SafeNativeMethods.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);
        }
Exemple #10
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.Instance;

                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 = ExtConnection.GetNewStatusVector();
                int   trHandle     = this.transaction.Handle;
                int   stmtHandle   = this.handle;

                SafeNativeMethods.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;
            }
        }
Exemple #11
0
        public override void Prepare(string commandText)
        {
            // Clear data
            this.ClearAll();

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

                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

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

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

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

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

                SafeNativeMethods.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;
            }
        }