* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Embedded / FesArray.cs
index 8a63fff7789316201029491e701e2d83ae5dc9e2..f1b4337577e6d7a0169fad2c5aecf4af0a731854 100644 (file)
-/*\r
- *     Firebird ADO.NET Data provider for .NET and Mono \r
- * \r
- *        The contents of this file are subject to the Initial \r
- *        Developer's Public License Version 1.0 (the "License"); \r
- *        you may not use this file except in compliance with the \r
- *        License. You may obtain a copy of the License at \r
- *        http://www.firebirdsql.org/index.php?op=doc&id=idpl\r
- *\r
- *        Software distributed under the License is distributed on \r
- *        an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either \r
- *        express or implied. See the License for the specific \r
- *        language governing rights and limitations under the License.\r
- * \r
- *     Copyright (c) 2002, 2005 Carlos Guzman Alvarez\r
- *     All Rights Reserved.\r
- */\r
-\r
-using System;\r
-using System.Collections;\r
-using System.Globalization;\r
-using System.IO;\r
-using System.Net;\r
-using System.Runtime.InteropServices;\r
-using System.Text;\r
-\r
-using FirebirdSql.Data.Common;\r
-\r
-namespace FirebirdSql.Data.Embedded\r
-{\r
-       internal sealed class FesArray : ArrayBase\r
-       {\r
-               #region Fields\r
-\r
-               private long                    handle;\r
-               private FesDatabase             db;\r
-               private FesTransaction  transaction;\r
-\r
-               #endregion\r
-\r
-               #region Properties\r
-\r
-               public override long Handle\r
-               {\r
-                       get     { return this.handle; }\r
-                       set     { this.handle = value; }\r
-               }\r
-\r
-               public override IDatabase DB\r
-               {\r
-                       get     { return this.db; }\r
-                       set     { this.db = (FesDatabase)value; }\r
-               }\r
-\r
-               public override ITransaction Transaction\r
-               {\r
-                       get     { return this.transaction; }\r
-                       set     { this.transaction = (FesTransaction)value;     }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Constructors\r
-\r
-               public FesArray(ArrayDesc descriptor) : base(descriptor)\r
-               {\r
-               }\r
-\r
-               public FesArray(\r
-                       IDatabase               db,\r
-                       ITransaction    transaction,\r
-                       string                  tableName, \r
-                       string                  fieldName) : this(db, transaction, -1, tableName, fieldName)\r
-               {\r
-               }\r
-\r
-               public FesArray(\r
-                       IDatabase               db,\r
-                       ITransaction    transaction,\r
-                       long                    handle, \r
-                       string                  tableName, \r
-                       string                  fieldName)      : base(tableName, fieldName)\r
-               {\r
-                       if (!(db is     FesDatabase))\r
-                       {\r
-                               throw new ArgumentException("Specified argument is not of GdsDatabase type.");\r
-                       }\r
-                       if (!(transaction is FesTransaction))\r
-                       {\r
-                               throw new ArgumentException("Specified argument is not of GdsTransaction type.");\r
-                       }\r
-                       this.db                  = (FesDatabase)db;\r
-                       this.transaction = (FesTransaction)transaction;\r
-                       this.handle              = handle;\r
-\r
-                       this.LookupBounds();\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Methods\r
-\r
-               public override byte[] GetSlice(int     sliceLength)\r
-               {\r
-                       int[] statusVector = FesConnection.GetNewStatusVector();\r
-\r
-                       int     dbHandle = this.db.Handle;\r
-                       int     trHandle = this.transaction.Handle;\r
-\r
-                       ArrayDescMarshaler marshaler = ArrayDescMarshaler.GetInstance();\r
-\r
-                       IntPtr arrayDesc = marshaler.MarshalManagedToNative(this.Descriptor);\r
-\r
-                       byte[] buffer = new     byte[sliceLength];\r
-\r
-                       FbClient.isc_array_get_slice(\r
-                               statusVector,\r
-                               ref     dbHandle,\r
-                               ref     trHandle,\r
-                               ref     this.handle,\r
-                               arrayDesc,\r
-                               buffer,\r
-                               ref     sliceLength);\r
-                       \r
-                       // Free memory\r
-                       marshaler.CleanUpNativeData(ref arrayDesc);\r
-\r
-                       FesConnection.ParseStatusVector(statusVector);\r
-\r
-                       return buffer;\r
-               }\r
-\r
-               public override void PutSlice(System.Array sourceArray, int     sliceLength)\r
-               {\r
-                       int[] statusVector = FesConnection.GetNewStatusVector();\r
-\r
-                       int     dbHandle = this.db.Handle;\r
-                       int     trHandle = this.transaction.Handle;\r
-\r
-                       ArrayDescMarshaler marshaler = ArrayDescMarshaler.GetInstance();\r
-\r
-                       IntPtr arrayDesc = marshaler.MarshalManagedToNative(this.Descriptor);\r
-\r
-                       // Obtain the System of type of Array elements and\r
-                       // Fill buffer\r
-                       Type systemType = this.GetSystemType();\r
-\r
-                       byte[] buffer = new     byte[sliceLength];\r
-                       if (systemType.IsPrimitive)\r
-                       {\r
-                               Buffer.BlockCopy(sourceArray, 0, buffer, 0,     buffer.Length);\r
-                       }\r
-                       else\r
-                       {\r
-                               buffer = this.EncodeSlice(this.Descriptor, sourceArray, sliceLength);\r
-                       }\r
-\r
-                       FbClient.isc_array_put_slice(\r
-                               statusVector,\r
-                               ref     dbHandle,\r
-                               ref     trHandle,\r
-                               ref     this.handle,\r
-                               arrayDesc,\r
-                               buffer,\r
-                               ref     sliceLength);\r
-                       \r
-                       // Free memory\r
-                       marshaler.CleanUpNativeData(ref arrayDesc);\r
-\r
-                       FesConnection.ParseStatusVector(statusVector);\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Protected Methods\r
-\r
-               protected override System.Array DecodeSlice(byte[] slice)\r
-               {\r
-                       Array           sliceData        = null;\r
-                       int                     slicePosition = 0;\r
-                       int                     type             = 0;\r
-                       DbDataType      dbType           = DbDataType.Array;\r
-                       Type            systemType       = this.GetSystemType();\r
-                       Charset         charset          = this.db.Charset;\r
-                       int[]           lengths          = new int[this.Descriptor.Dimensions];\r
-                       int[]           lowerBounds      = new int[this.Descriptor.Dimensions];                 \r
-\r
-                       // Get upper and lower bounds of each dimension\r
-                       for     (int i = 0;     i <     this.Descriptor.Dimensions;     i++)\r
-                       {\r
-                               lowerBounds[i]  = this.Descriptor.Bounds[i].LowerBound;\r
-                               lengths[i]              = this.Descriptor.Bounds[i].UpperBound;\r
-\r
-                               if (lowerBounds[i] == 0)\r
-                               {\r
-                                       lengths[i]++;\r
-                               }\r
-                       }\r
-                       \r
-                       // Create slice arrays\r
-                       sliceData = Array.CreateInstance(systemType, lengths, lowerBounds);\r
-\r
-                       Array tempData = Array.CreateInstance(systemType, sliceData.Length);\r
-\r
-                       // Infer data types\r
-                       type = TypeHelper.GetFbType(this.Descriptor.DataType);\r
-                       dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, 0,  this.Descriptor.Scale);\r
-\r
-                       int     itemLength = this.Descriptor.Length;\r
-\r
-                       for     (int i = 0;     i <     tempData.Length; i++)\r
-                       {\r
-                               if (slicePosition >= slice.Length)\r
-                               {\r
-                                       break;\r
-                               }\r
-                                                               \r
-                               switch(dbType)\r
-                               {                                                       \r
-                                       case DbDataType.Char:\r
-                                               tempData.SetValue(charset.GetString(slice, slicePosition, itemLength), i);\r
-                                               break;\r
-\r
-                                       case DbDataType.VarChar:\r
-                                       {\r
-                                               int     index = slicePosition;\r
-                                               int     count = 0;\r
-                                               while (slice[index++] != 0)\r
-                                               {\r
-                                                       count ++;\r
-                                               }\r
-                                               tempData.SetValue(charset.GetString(slice, slicePosition, count), i);\r
-\r
-                                               slicePosition += 2;\r
-                                       }\r
-                                       break;\r
-                                       \r
-                                       case DbDataType.SmallInt:\r
-                                               tempData.SetValue(BitConverter.ToInt16(slice, slicePosition), i);\r
-                                               break;\r
-       \r
-                                       case DbDataType.Integer:\r
-                                               tempData.SetValue(BitConverter.ToInt32(slice, slicePosition), i);\r
-                                               break;\r
-       \r
-                                       case DbDataType.BigInt:\r
-                                               tempData.SetValue(BitConverter.ToInt64(slice, slicePosition), i);\r
-                                               break;\r
-                                       \r
-                                       case DbDataType.Decimal:\r
-                                       case DbDataType.Numeric:\r
-                                       {\r
-                                               object evalue = null;\r
-\r
-                                               switch (type)\r
-                                               {\r
-                                                       case IscCodes.SQL_SHORT:\r
-                                                               evalue = BitConverter.ToInt16(slice, slicePosition);\r
-                                                               break;\r
-\r
-                                                       case IscCodes.SQL_LONG:\r
-                                                               evalue = BitConverter.ToInt32(slice, slicePosition);\r
-                                                               break;\r
-\r
-                                                       case IscCodes.SQL_QUAD:\r
-                                                       case IscCodes.SQL_INT64:\r
-                                                               evalue = BitConverter.ToInt64(slice, slicePosition);\r
-                                                               break;\r
-                                               }\r
-\r
-                                               decimal dvalue = TypeDecoder.DecodeDecimal(evalue, this.Descriptor.Scale, type);\r
-\r
-                                               tempData.SetValue(dvalue, i);\r
-                                       }\r
-                                       break;\r
-\r
-                                       case DbDataType.Double: \r
-                                               tempData.SetValue(BitConverter.ToDouble(slice, slicePosition), i);\r
-                                               break;\r
-       \r
-                                       case DbDataType.Float:\r
-                                               tempData.SetValue(BitConverter.ToSingle(slice, slicePosition), i);\r
-                                               break;\r
-\r
-                                       case DbDataType.Date:\r
-                                       {\r
-                                               int     idate = BitConverter.ToInt32(slice,     slicePosition);\r
-\r
-                                               DateTime date = TypeDecoder.DecodeDate(idate);\r
-                                               \r
-                                               tempData.SetValue(date, i);\r
-                                       }\r
-                                       break;\r
-                                       \r
-                                       case DbDataType.Time:\r
-                                       {\r
-                                               int     itime = BitConverter.ToInt32(slice,     slicePosition);\r
-                                       \r
-                                               DateTime time = TypeDecoder.DecodeTime(itime);                                  \r
-                                               \r
-                                               tempData.SetValue(time, i);\r
-                                       }\r
-                                       break;\r
-                                                                               \r
-                                       case DbDataType.TimeStamp:\r
-                                       {\r
-                                               int     idate = BitConverter.ToInt32(slice,     slicePosition);\r
-                                               int     itime = BitConverter.ToInt32(slice,     slicePosition + 4);\r
-                                       \r
-                                               DateTime date = TypeDecoder.DecodeDate(idate);\r
-                                               DateTime time = TypeDecoder.DecodeTime(itime);\r
-\r
-                                               DateTime timestamp = new System.DateTime(\r
-                                                       date.Year, date.Month, date.Day,\r
-                                                       time.Hour,time.Minute, time.Second,     time.Millisecond);\r
-                                                                                       \r
-                                               tempData.SetValue(timestamp, i);\r
-                                       }\r
-                                       break;\r
-                               }\r
-                               \r
-                               slicePosition += itemLength;\r
-                       }\r
-                       \r
-                       if (systemType.IsPrimitive)\r
-                       {\r
-                               // For primitive types we can use System.Buffer to copy generated data to destination array\r
-                               Buffer.BlockCopy(tempData, 0, sliceData, 0,     Buffer.ByteLength(tempData));\r
-                       }\r
-                       else\r
-                       {\r
-                               sliceData = tempData;   \r
-                       }\r
-                       \r
-                       return sliceData;\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Private Metods\r
-\r
-               private byte[] EncodeSlice(ArrayDesc desc, Array sourceArray, int length)\r
-               {\r
-                       BinaryWriter    writer  = new BinaryWriter(new MemoryStream());\r
-                       IEnumerator             i               = sourceArray.GetEnumerator();\r
-                       Charset                 charset = this.db.Charset;\r
-                       DbDataType              dbType  = DbDataType.Array;\r
-                       int                             type    = 0;\r
-                       int                             subtype = (this.Descriptor.Scale < 0) ? 2 : 0;\r
-\r
-                       // Infer data types\r
-                       type = TypeHelper.GetFbType(this.Descriptor.DataType);\r
-                       dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subtype,    this.Descriptor.Scale);\r
-\r
-                       while (i.MoveNext())\r
-                       {\r
-                               switch (dbType)\r
-                               {\r
-                                       case DbDataType.Char:\r
-                                       {\r
-                                               string value  = i.Current != null ?     (string)i.Current :     String.Empty;\r
-                                               byte[] buffer = charset.GetBytes(value);\r
-\r
-                                               writer.Write(buffer);\r
-\r
-                                               if (desc.Length > buffer.Length)\r
-                                               {\r
-                                                       for     (int j = buffer.Length; j <     desc.Length; j++)\r
-                                                       {\r
-                                                               writer.Write((byte)32);\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       break;\r
-\r
-                                       case DbDataType.VarChar:\r
-                                       {\r
-                                               string value = i.Current !=     null ? (string)i.Current : String.Empty;\r
-\r
-                                               value = value.TrimEnd();\r
-\r
-                                               byte[] buffer = charset.GetBytes(value);\r
-                                               writer.Write(buffer);\r
-\r
-                                               if (desc.Length > buffer.Length)\r
-                                               {\r
-                                                       for     (int j = buffer.Length; j <     desc.Length; j++)\r
-                                                       {\r
-                                                               writer.Write((byte)0);\r
-                                                       }\r
-                                               }\r
-                                               writer.Write((short)0);\r
-                                       }\r
-                                       break;\r
-       \r
-                                       case DbDataType.SmallInt:\r
-                                               writer.Write((short)i.Current);\r
-                                               break;\r
-       \r
-                                       case DbDataType.Integer:\r
-                                               writer.Write((int)i.Current);\r
-                                               break;\r
-\r
-                                       case DbDataType.BigInt:\r
-                                               writer.Write((long)i.Current);\r
-                                               break;\r
-                                       \r
-                                       case DbDataType.Float:\r
-                                               writer.Write((float)i.Current);\r
-                                               break;\r
-                                                                               \r
-                                       case DbDataType.Double:\r
-                                               writer.Write((double)i.Current);\r
-                                               break;\r
-                                       \r
-                                       case DbDataType.Numeric:\r
-                                       case DbDataType.Decimal:\r
-                                       {\r
-                                               object numeric = TypeEncoder.EncodeDecimal((decimal)i.Current, desc.Scale, type);\r
-\r
-                                               switch (type)\r
-                                               {\r
-                                                       case IscCodes.SQL_SHORT:\r
-                                                               writer.Write((short)numeric);\r
-                                                               break;\r
-\r
-                                                       case IscCodes.SQL_LONG:\r
-                                                               writer.Write((int)numeric);\r
-                                                               break;\r
-\r
-                                                       case IscCodes.SQL_QUAD:\r
-                                                       case IscCodes.SQL_INT64:\r
-                                                               writer.Write((long)numeric);\r
-                                                               break;\r
-                                               }\r
-                                       }\r
-                                       break;\r
-\r
-                                       case DbDataType.Date:\r
-                                               writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));\r
-                                               break;\r
-                                       \r
-                                       case DbDataType.Time:\r
-                                               writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));\r
-                                               break;\r
-\r
-                                       case DbDataType.TimeStamp:\r
-                                               writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));\r
-                                               writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));\r
-                                               break;\r
-                                       \r
-                                       default:\r
-                                               throw new NotSupportedException("Unknown data type");\r
-                               }\r
-                       }\r
-\r
-                       return ((MemoryStream)writer.BaseStream).ToArray();\r
-               }\r
-\r
-               #endregion\r
-       }\r
+/*
+ *     Firebird ADO.NET Data provider for .NET and Mono 
+ * 
+ *        The contents of this file are subject to the Initial 
+ *        Developer's Public License Version 1.0 (the "License"); 
+ *        you may not use this file except in compliance with the 
+ *        License. You may obtain a copy of the License at 
+ *        http://www.firebirdsql.org/index.php?op=doc&id=idpl
+ *
+ *        Software distributed under the License is distributed on 
+ *        an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
+ *        express or implied. See the License for the specific 
+ *        language governing rights and limitations under the License.
+ * 
+ *     Copyright (c) 2002, 2005 Carlos Guzman Alvarez
+ *     All Rights Reserved.
+ */
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.IO;
+using System.Net;
+using System.Runtime.InteropServices;
+using System.Text;
+
+using FirebirdSql.Data.Common;
+
+namespace FirebirdSql.Data.Embedded
+{
+       internal sealed class FesArray : ArrayBase
+       {
+               #region Fields
+
+               private long                    handle;
+               private FesDatabase             db;
+               private FesTransaction  transaction;
+
+               #endregion
+
+               #region Properties
+
+               public override long Handle
+               {
+                       get     { return this.handle; }
+                       set     { this.handle = value; }
+               }
+
+               public override IDatabase DB
+               {
+                       get     { return this.db; }
+                       set     { this.db = (FesDatabase)value; }
+               }
+
+               public override ITransaction Transaction
+               {
+                       get     { return this.transaction; }
+                       set     { this.transaction = (FesTransaction)value;     }
+               }
+
+               #endregion
+
+               #region Constructors
+
+               public FesArray(ArrayDesc descriptor) : base(descriptor)
+               {
+               }
+
+               public FesArray(
+                       IDatabase               db,
+                       ITransaction    transaction,
+                       string                  tableName, 
+                       string                  fieldName) : this(db, transaction, -1, tableName, fieldName)
+               {
+               }
+
+               public FesArray(
+                       IDatabase               db,
+                       ITransaction    transaction,
+                       long                    handle, 
+                       string                  tableName, 
+                       string                  fieldName)      : base(tableName, fieldName)
+               {
+                       if (!(db is     FesDatabase))
+                       {
+                               throw new ArgumentException("Specified argument is not of GdsDatabase type.");
+                       }
+                       if (!(transaction is FesTransaction))
+                       {
+                               throw new ArgumentException("Specified argument is not of GdsTransaction type.");
+                       }
+                       this.db                  = (FesDatabase)db;
+                       this.transaction = (FesTransaction)transaction;
+                       this.handle              = handle;
+
+                       this.LookupBounds();
+               }
+
+               #endregion
+
+               #region Methods
+
+               public override byte[] GetSlice(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);
+
+                       byte[] buffer = new     byte[sliceLength];
+
+                       FbClient.isc_array_get_slice(
+                               statusVector,
+                               ref     dbHandle,
+                               ref     trHandle,
+                               ref     this.handle,
+                               arrayDesc,
+                               buffer,
+                               ref     sliceLength);
+                       
+                       // Free memory
+                       marshaler.CleanUpNativeData(ref arrayDesc);
+
+                       FesConnection.ParseStatusVector(statusVector);
+
+                       return buffer;
+               }
+
+               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);
+               }
+
+               #endregion
+
+               #region Protected Methods
+
+               protected override System.Array DecodeSlice(byte[] slice)
+               {
+                       Array           sliceData        = null;
+                       int                     slicePosition = 0;
+                       int                     type             = 0;
+                       DbDataType      dbType           = DbDataType.Array;
+                       Type            systemType       = this.GetSystemType();
+                       Charset         charset          = this.db.Charset;
+                       int[]           lengths          = new int[this.Descriptor.Dimensions];
+                       int[]           lowerBounds      = new int[this.Descriptor.Dimensions];                 
+
+                       // Get upper and lower bounds of each dimension
+                       for     (int i = 0;     i <     this.Descriptor.Dimensions;     i++)
+                       {
+                               lowerBounds[i]  = this.Descriptor.Bounds[i].LowerBound;
+                               lengths[i]              = this.Descriptor.Bounds[i].UpperBound;
+
+                               if (lowerBounds[i] == 0)
+                               {
+                                       lengths[i]++;
+                               }
+                       }
+                       
+                       // Create slice arrays
+                       sliceData = Array.CreateInstance(systemType, lengths, lowerBounds);
+
+                       Array tempData = Array.CreateInstance(systemType, sliceData.Length);
+
+                       // Infer data types
+                       type = TypeHelper.GetFbType(this.Descriptor.DataType);
+                       dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, 0,  this.Descriptor.Scale);
+
+                       int     itemLength = this.Descriptor.Length;
+
+                       for     (int i = 0;     i <     tempData.Length; i++)
+                       {
+                               if (slicePosition >= slice.Length)
+                               {
+                                       break;
+                               }
+                                                               
+                               switch(dbType)
+                               {                                                       
+                                       case DbDataType.Char:
+                                               tempData.SetValue(charset.GetString(slice, slicePosition, itemLength), i);
+                                               break;
+
+                                       case DbDataType.VarChar:
+                                       {
+                                               int     index = slicePosition;
+                                               int     count = 0;
+                                               while (slice[index++] != 0)
+                                               {
+                                                       count ++;
+                                               }
+                                               tempData.SetValue(charset.GetString(slice, slicePosition, count), i);
+
+                                               slicePosition += 2;
+                                       }
+                                       break;
+                                       
+                                       case DbDataType.SmallInt:
+                                               tempData.SetValue(BitConverter.ToInt16(slice, slicePosition), i);
+                                               break;
+       
+                                       case DbDataType.Integer:
+                                               tempData.SetValue(BitConverter.ToInt32(slice, slicePosition), i);
+                                               break;
+       
+                                       case DbDataType.BigInt:
+                                               tempData.SetValue(BitConverter.ToInt64(slice, slicePosition), i);
+                                               break;
+                                       
+                                       case DbDataType.Decimal:
+                                       case DbDataType.Numeric:
+                                       {
+                                               object evalue = null;
+
+                                               switch (type)
+                                               {
+                                                       case IscCodes.SQL_SHORT:
+                                                               evalue = BitConverter.ToInt16(slice, slicePosition);
+                                                               break;
+
+                                                       case IscCodes.SQL_LONG:
+                                                               evalue = BitConverter.ToInt32(slice, slicePosition);
+                                                               break;
+
+                                                       case IscCodes.SQL_QUAD:
+                                                       case IscCodes.SQL_INT64:
+                                                               evalue = BitConverter.ToInt64(slice, slicePosition);
+                                                               break;
+                                               }
+
+                                               decimal dvalue = TypeDecoder.DecodeDecimal(evalue, this.Descriptor.Scale, type);
+
+                                               tempData.SetValue(dvalue, i);
+                                       }
+                                       break;
+
+                                       case DbDataType.Double: 
+                                               tempData.SetValue(BitConverter.ToDouble(slice, slicePosition), i);
+                                               break;
+       
+                                       case DbDataType.Float:
+                                               tempData.SetValue(BitConverter.ToSingle(slice, slicePosition), i);
+                                               break;
+
+                                       case DbDataType.Date:
+                                       {
+                                               int     idate = BitConverter.ToInt32(slice,     slicePosition);
+
+                                               DateTime date = TypeDecoder.DecodeDate(idate);
+                                               
+                                               tempData.SetValue(date, i);
+                                       }
+                                       break;
+                                       
+                                       case DbDataType.Time:
+                                       {
+                                               int     itime = BitConverter.ToInt32(slice,     slicePosition);
+                                       
+                                               DateTime time = TypeDecoder.DecodeTime(itime);                                  
+                                               
+                                               tempData.SetValue(time, i);
+                                       }
+                                       break;
+                                                                               
+                                       case DbDataType.TimeStamp:
+                                       {
+                                               int     idate = BitConverter.ToInt32(slice,     slicePosition);
+                                               int     itime = BitConverter.ToInt32(slice,     slicePosition + 4);
+                                       
+                                               DateTime date = TypeDecoder.DecodeDate(idate);
+                                               DateTime time = TypeDecoder.DecodeTime(itime);
+
+                                               DateTime timestamp = new System.DateTime(
+                                                       date.Year, date.Month, date.Day,
+                                                       time.Hour,time.Minute, time.Second,     time.Millisecond);
+                                                                                       
+                                               tempData.SetValue(timestamp, i);
+                                       }
+                                       break;
+                               }
+                               
+                               slicePosition += itemLength;
+                       }
+                       
+                       if (systemType.IsPrimitive)
+                       {
+                               // For primitive types we can use System.Buffer to copy generated data to destination array
+                               Buffer.BlockCopy(tempData, 0, sliceData, 0,     Buffer.ByteLength(tempData));
+                       }
+                       else
+                       {
+                               sliceData = tempData;   
+                       }
+                       
+                       return sliceData;
+               }
+
+               #endregion
+
+               #region Private Metods
+
+               private byte[] EncodeSlice(ArrayDesc desc, Array sourceArray, int length)
+               {
+                       BinaryWriter    writer  = new BinaryWriter(new MemoryStream());
+                       IEnumerator             i               = sourceArray.GetEnumerator();
+                       Charset                 charset = this.db.Charset;
+                       DbDataType              dbType  = DbDataType.Array;
+                       int                             type    = 0;
+                       int                             subtype = (this.Descriptor.Scale < 0) ? 2 : 0;
+
+                       // Infer data types
+                       type = TypeHelper.GetFbType(this.Descriptor.DataType);
+                       dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subtype,    this.Descriptor.Scale);
+
+                       while (i.MoveNext())
+                       {
+                               switch (dbType)
+                               {
+                                       case DbDataType.Char:
+                                       {
+                                               string value  = i.Current != null ?     (string)i.Current :     String.Empty;
+                                               byte[] buffer = charset.GetBytes(value);
+
+                                               writer.Write(buffer);
+
+                                               if (desc.Length > buffer.Length)
+                                               {
+                                                       for     (int j = buffer.Length; j <     desc.Length; j++)
+                                                       {
+                                                               writer.Write((byte)32);
+                                                       }
+                                               }
+                                       }
+                                       break;
+
+                                       case DbDataType.VarChar:
+                                       {
+                                               string value = i.Current !=     null ? (string)i.Current : String.Empty;
+
+                                               value = value.TrimEnd();
+
+                                               byte[] buffer = charset.GetBytes(value);
+                                               writer.Write(buffer);
+
+                                               if (desc.Length > buffer.Length)
+                                               {
+                                                       for     (int j = buffer.Length; j <     desc.Length; j++)
+                                                       {
+                                                               writer.Write((byte)0);
+                                                       }
+                                               }
+                                               writer.Write((short)0);
+                                       }
+                                       break;
+       
+                                       case DbDataType.SmallInt:
+                                               writer.Write((short)i.Current);
+                                               break;
+       
+                                       case DbDataType.Integer:
+                                               writer.Write((int)i.Current);
+                                               break;
+
+                                       case DbDataType.BigInt:
+                                               writer.Write((long)i.Current);
+                                               break;
+                                       
+                                       case DbDataType.Float:
+                                               writer.Write((float)i.Current);
+                                               break;
+                                                                               
+                                       case DbDataType.Double:
+                                               writer.Write((double)i.Current);
+                                               break;
+                                       
+                                       case DbDataType.Numeric:
+                                       case DbDataType.Decimal:
+                                       {
+                                               object numeric = TypeEncoder.EncodeDecimal((decimal)i.Current, desc.Scale, type);
+
+                                               switch (type)
+                                               {
+                                                       case IscCodes.SQL_SHORT:
+                                                               writer.Write((short)numeric);
+                                                               break;
+
+                                                       case IscCodes.SQL_LONG:
+                                                               writer.Write((int)numeric);
+                                                               break;
+
+                                                       case IscCodes.SQL_QUAD:
+                                                       case IscCodes.SQL_INT64:
+                                                               writer.Write((long)numeric);
+                                                               break;
+                                               }
+                                       }
+                                       break;
+
+                                       case DbDataType.Date:
+                                               writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
+                                               break;
+                                       
+                                       case DbDataType.Time:
+                                               writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
+                                               break;
+
+                                       case DbDataType.TimeStamp:
+                                               writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
+                                               writer.Write(TypeEncoder.EncodeTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat)));
+                                               break;
+                                       
+                                       default:
+                                               throw new NotSupportedException("Unknown data type");
+                               }
+                       }
+
+                       return ((MemoryStream)writer.BaseStream).ToArray();
+               }
+
+               #endregion
+       }
 }
\ No newline at end of file