示例#1
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);
        }