2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
22 namespace FirebirdSql.Data.Common
25 /// Descriptor of query input and output parameters.
28 /// This is similar to the XSQLDA structure described
29 /// in the Interbase 6.0 API docs.
31 internal sealed class Descriptor : ICloneable
35 private short version;
37 private short actualCount;
38 private DbField[] fields;
58 get { return this.count; }
61 public short ActualCount
63 get { return this.actualCount; }
64 set { this.actualCount = value; }
71 public DbField this[int index]
73 get { return this.fields[index]; }
80 public Descriptor(int count)
82 this.version = IscCodes.SQLDA_VERSION1;
83 this.count = (short)count;
84 this.actualCount = (short)count;
85 this.fields = new DbField[count];
87 for (int i = 0; i < this.fields.Length; i++)
89 this.fields[i] = new DbField();
95 #region ICloneable Methods
99 Descriptor descriptor = new Descriptor(this.Count);
100 descriptor.Version = this.version;
102 for (int i = 0; i < descriptor.Count; i++)
104 descriptor[i].DataType = this.fields[i].DataType;
105 descriptor[i].NumericScale = this.fields[i].NumericScale;
106 descriptor[i].SubType = this.fields[i].SubType;
107 descriptor[i].Length = this.fields[i].Length;
108 descriptor[i].Value = this.fields[i].Value;
109 descriptor[i].NullFlag = this.fields[i].NullFlag;
110 descriptor[i].Name = this.fields[i].Name;
111 descriptor[i].Relation = this.fields[i].Relation;
112 descriptor[i].Owner = this.fields[i].Owner;
113 descriptor[i].Alias = this.fields[i].Alias;
123 public void ResetValues()
125 for (int i = 0; i < this.fields.Length; i++)
127 this.fields[i].Value = null;
131 public byte[] ToBlrArray()
133 MemoryStream blr = new MemoryStream();
134 int par_count = this.Count * 2;
136 blr.WriteByte(IscCodes.blr_version5);
137 blr.WriteByte(IscCodes.blr_begin);
138 blr.WriteByte(IscCodes.blr_message);
140 blr.WriteByte((byte)(par_count & 255));
141 blr.WriteByte((byte)(par_count >> 8));
143 for (int i = 0; i < this.fields.Length; i++)
145 int dtype = this.fields[i].SqlType;
146 int len = this.fields[i].Length;
150 case IscCodes.SQL_VARYING:
151 blr.WriteByte(IscCodes.blr_varying);
152 blr.WriteByte((byte)(len & 255));
153 blr.WriteByte((byte)(len >> 8));
156 case IscCodes.SQL_TEXT:
157 blr.WriteByte(IscCodes.blr_text);
158 blr.WriteByte((byte)(len & 255));
159 blr.WriteByte((byte)(len >> 8));
162 case IscCodes.SQL_DOUBLE:
163 blr.WriteByte(IscCodes.blr_double);
166 case IscCodes.SQL_FLOAT:
167 blr.WriteByte(IscCodes.blr_float);
170 case IscCodes.SQL_D_FLOAT:
171 blr.WriteByte(IscCodes.blr_d_float);
174 case IscCodes.SQL_TYPE_DATE:
175 blr.WriteByte(IscCodes.blr_sql_date);
178 case IscCodes.SQL_TYPE_TIME:
179 blr.WriteByte(IscCodes.blr_sql_time);
182 case IscCodes.SQL_TIMESTAMP:
183 blr.WriteByte(IscCodes.blr_timestamp);
186 case IscCodes.SQL_BLOB:
187 blr.WriteByte(IscCodes.blr_quad);
191 case IscCodes.SQL_ARRAY:
192 blr.WriteByte(IscCodes.blr_quad);
196 case IscCodes.SQL_LONG:
197 blr.WriteByte(IscCodes.blr_long);
198 blr.WriteByte((byte)this.fields[i].NumericScale);
201 case IscCodes.SQL_SHORT:
202 blr.WriteByte(IscCodes.blr_short);
203 blr.WriteByte((byte)this.fields[i].NumericScale);
206 case IscCodes.SQL_INT64:
207 blr.WriteByte(IscCodes.blr_int64);
208 blr.WriteByte((byte)this.fields[i].NumericScale);
211 case IscCodes.SQL_QUAD:
212 blr.WriteByte(IscCodes.blr_quad);
213 blr.WriteByte((byte)this.fields[i].NumericScale);
217 blr.WriteByte(IscCodes.blr_short);
221 blr.WriteByte(IscCodes.blr_end);
222 blr.WriteByte(IscCodes.blr_eoc);
224 return blr.ToArray();