Esempio n. 1
0
        public override void Describe()
        {
            lock (this.db)
            {
                // Update structure
                this.fields = new Descriptor(this.fields.ActualCount);

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

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

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

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

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

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

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

                // Update field	descriptor
                this.fields = descriptor;
            }
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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;
            }
        }