2005-09-30 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Common / DbField.cs
index 2cf27b5f3592db468e70d65480227c1c313b3fa0..bb5fbd665380e93efb1f1fb14c304f7e135a5669 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.Text;\r
-\r
-namespace FirebirdSql.Data.Common\r
-{\r
-       internal sealed class DbField\r
-       {\r
-               #region Fields\r
-\r
-               private short           dataType;\r
-               private short           numericScale;\r
-               private short           subType;\r
-               private short           length;\r
-               private short           nullFlag;\r
-               private string          name;\r
-               private string          relation;\r
-               private string          owner;\r
-               private string          alias;\r
-               private int                     charCount;\r
-               private DbValue         dbValue;\r
-               private Charset         charset;\r
-               private ArrayBase       arrayHandle;\r
-\r
-               #endregion\r
-\r
-               #region Properties\r
-\r
-               public DbDataType DbDataType\r
-               {\r
-                       get { return this.GetDbDataType(); }\r
-               }\r
-\r
-               public int SqlType\r
-               {\r
-                       get { return this.dataType & ~1; }\r
-               }\r
-\r
-               public short DataType\r
-               {\r
-                       get { return this.dataType; }\r
-                       set { this.dataType = value; }\r
-               }\r
-\r
-               public short NumericScale\r
-               {\r
-                       get { return this.numericScale; }\r
-                       set { this.numericScale = value; }\r
-               }\r
-\r
-               public short SubType\r
-               {\r
-                       get { return this.subType; }\r
-                       set\r
-                       {\r
-                               this.subType = value;\r
-                               if (this.IsCharacter())\r
-                               {\r
-                                       // Bits 0-7 of sqlsubtype is charset_id (127 is a special value -\r
-                                       // current attachment charset).\r
-                                       // Bits 8-17 hold collation_id for this value.\r
-                                       byte[] cs = BitConverter.GetBytes(value);\r
-\r
-                                       int index = Charset.SupportedCharsets.IndexOf(cs[0]);\r
-                                       if (index != -1)\r
-                                       {\r
-                                               this.charset = Charset.SupportedCharsets[index];\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               this.charset = Charset.SupportedCharsets[0];\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public short Length\r
-               {\r
-                       get { return this.length; }\r
-                       set\r
-                       {\r
-                               this.length = value;\r
-                               if (this.IsCharacter())\r
-                               {\r
-                                       this.charCount = this.length / this.charset.BytesPerCharacter;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public short NullFlag\r
-               {\r
-                       get { return this.nullFlag; }\r
-                       set { this.nullFlag = value; }\r
-               }\r
-\r
-               public string Name\r
-               {\r
-                       get { return this.name; }\r
-                       set { this.name = value.Trim(); }\r
-               }\r
-\r
-               public string Relation\r
-               {\r
-                       get { return this.relation; }\r
-                       set { this.relation = value.Trim(); }\r
-               }\r
-\r
-               public string Owner\r
-               {\r
-                       get { return this.owner; }\r
-                       set { this.owner = value.Trim(); }\r
-               }\r
-\r
-               public string Alias\r
-               {\r
-                       get { return this.alias; }\r
-                       set { this.alias = value.Trim(); }\r
-               }\r
-\r
-               public Charset Charset\r
-               {\r
-                       get { return this.charset; }\r
-               }\r
-\r
-               public int CharCount\r
-               {\r
-                       get { return this.charCount; }\r
-               }\r
-\r
-               public ArrayBase ArrayHandle\r
-               {\r
-                       get\r
-                       {\r
-                               if (this.IsArray())\r
-                               {\r
-                                       return this.arrayHandle;\r
-                               }\r
-                               else\r
-                               {\r
-                                       throw new IscException("Field is not an array type");\r
-                               }\r
-                       }\r
-\r
-                       set\r
-                       {\r
-                               if (this.IsArray())\r
-                               {\r
-                                       this.arrayHandle = value;\r
-                               }\r
-                               else\r
-                               {\r
-                                       throw new IscException("Field is not an array type");\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public DbValue DbValue\r
-               {\r
-                       get { return this.dbValue; }\r
-               }\r
-\r
-               public object Value\r
-               {\r
-                       get { return this.dbValue.Value; }\r
-                       set { this.dbValue.Value = value; }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Constructors\r
-\r
-               public DbField()\r
-               {\r
-                       this.charCount  = -1;\r
-                       this.name               = String.Empty;\r
-                       this.relation   = String.Empty;\r
-                       this.owner              = String.Empty;\r
-                       this.alias              = String.Empty;\r
-                       this.dbValue    = new DbValue(this, DBNull.Value);\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Methods\r
-\r
-               public bool IsNumeric()\r
-               {\r
-                       if (this.dataType == 0)\r
-                       {\r
-                               return false;\r
-                       }\r
-\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.SmallInt:\r
-                               case DbDataType.Integer:\r
-                               case DbDataType.BigInt:\r
-                               case DbDataType.Numeric:\r
-                               case DbDataType.Decimal:\r
-                               case DbDataType.Float:\r
-                               case DbDataType.Double:\r
-                                       return true;\r
-\r
-                               default:\r
-                                       return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsDecimal()\r
-               {\r
-                       if (this.dataType == 0)\r
-                       {\r
-                               return false;\r
-                       }\r
-\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.Numeric:\r
-                               case DbDataType.Decimal:\r
-                                       return true;\r
-\r
-                               default:\r
-                                       return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsLong()\r
-               {\r
-                       if (this.dataType == 0)\r
-                       {\r
-                               return false;\r
-                       }\r
-\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.Binary:\r
-                               case DbDataType.Text:\r
-                                       return true;\r
-\r
-                               default:\r
-                                       return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsCharacter()\r
-               {\r
-                       if (this.dataType == 0)\r
-                       {\r
-                               return false;\r
-                       }\r
-\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.Char:\r
-                               case DbDataType.VarChar:\r
-                               case DbDataType.Text:\r
-                                       return true;\r
-\r
-                               default:\r
-                                       return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsArray()\r
-               {\r
-                       if (this.dataType == 0)\r
-                       {\r
-                               return false;\r
-                       }\r
-\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.Array:\r
-                                       return true;\r
-\r
-                               default:\r
-                                       return false;\r
-                       }\r
-               }\r
-\r
-               public bool IsAliased()\r
-               {\r
-                       return (this.Name != this.Alias) ? true : false;\r
-               }\r
-\r
-               public bool IsExpression()\r
-               {\r
-                       return this.Name.Length == 0 ? true : false;\r
-               }\r
-\r
-               public int GetSize()\r
-               {\r
-                       if (this.IsLong())\r
-                       {\r
-                               return System.Int32.MaxValue;\r
-                       }\r
-                       else\r
-                       {\r
-                               if (this.IsCharacter())\r
-                               {\r
-                                       return this.CharCount;\r
-                               }\r
-                               else\r
-                               {\r
-                                       return this.Length;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public bool AllowDBNull()\r
-               {\r
-                       return ((this.DataType & 1) == 1);\r
-               }\r
-\r
-               public void SetValue(byte[] buffer)\r
-               {\r
-                       if (buffer == null || this.NullFlag == -1)\r
-                       {\r
-                               this.Value = System.DBNull.Value;\r
-                       }\r
-                       else\r
-                       {\r
-                               switch (this.SqlType)\r
-                               {\r
-                                       case IscCodes.SQL_TEXT:\r
-                                       case IscCodes.SQL_VARYING:\r
-                                               if (this.DbDataType == DbDataType.Guid)\r
-                                               {\r
-                                                       this.Value = new Guid(buffer);\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       string s = this.Charset.GetString(buffer, 0, buffer.Length);\r
-\r
-                                                       if ((this.Length % this.Charset.BytesPerCharacter) == 0 &&\r
-                                                               s.Length > this.CharCount)\r
-                                                       {\r
-                                                               s = s.Substring(0, this.CharCount);\r
-                                                       }\r
-\r
-                                                       this.Value = s;\r
-                                               }\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_SHORT:\r
-                                               if (this.numericScale < 0)\r
-                                               {\r
-                                                       this.Value = TypeDecoder.DecodeDecimal(\r
-                                                               BitConverter.ToInt16(buffer, 0),\r
-                                                               this.numericScale,\r
-                                                               this.dataType);\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       this.Value = BitConverter.ToInt16(buffer, 0);\r
-                                               }\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_LONG:\r
-                                               if (this.NumericScale < 0)\r
-                                               {\r
-                                                       this.Value = TypeDecoder.DecodeDecimal(\r
-                                                               BitConverter.ToInt32(buffer, 0),\r
-                                                               this.numericScale,\r
-                                                               this.dataType);\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       this.Value = BitConverter.ToInt32(buffer, 0);\r
-                                               }\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_FLOAT:\r
-                                               this.Value = BitConverter.ToSingle(buffer, 0);\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_DOUBLE:\r
-                                       case IscCodes.SQL_D_FLOAT:\r
-                                               this.Value = BitConverter.ToDouble(buffer, 0);\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_QUAD:\r
-                                       case IscCodes.SQL_INT64:\r
-                                       case IscCodes.SQL_BLOB:\r
-                                       case IscCodes.SQL_ARRAY:\r
-                                               if (this.NumericScale < 0)\r
-                                               {\r
-                                                       this.Value = TypeDecoder.DecodeDecimal(\r
-                                                               BitConverter.ToInt64(buffer, 0),\r
-                                                               this.numericScale,\r
-                                                               this.dataType);\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       this.Value = BitConverter.ToInt64(buffer, 0);\r
-                                               }\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_TIMESTAMP:\r
-                                               DateTime date = TypeDecoder.DecodeDate(\r
-                                                       BitConverter.ToInt32(buffer, 0));\r
-\r
-                                               DateTime time = TypeDecoder.DecodeTime(\r
-                                                       BitConverter.ToInt32(buffer, 4));\r
-\r
-                                               this.Value = new System.DateTime(\r
-                                                       date.Year, date.Month, date.Day,\r
-                                                       time.Hour, time.Minute, time.Second, time.Millisecond);\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_TYPE_TIME:\r
-                                               this.Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));\r
-                                               break;\r
-\r
-                                       case IscCodes.SQL_TYPE_DATE:\r
-                                               this.Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));\r
-                                               break;\r
-\r
-                                       default:\r
-                                               throw new NotSupportedException("Unknown data type");\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public void FixNull()\r
-               {\r
-                       if (this.NullFlag == -1 && this.dbValue.IsDBNull())\r
-                       {\r
-                               switch (this.DbDataType)\r
-                               {\r
-                                       case DbDataType.Char:\r
-                                       case DbDataType.VarChar:\r
-                                               this.Value = String.Empty;\r
-                                               break;\r
-\r
-                                       case DbDataType.Guid:\r
-                                               this.Value = Guid.Empty;\r
-                                               break;\r
-\r
-                                       case DbDataType.SmallInt:\r
-                                               this.Value = (short)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.Integer:\r
-                                               this.Value = (int)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.BigInt:\r
-                                       case DbDataType.Binary:\r
-                                       case DbDataType.Array:\r
-                                       case DbDataType.Text:\r
-                                               this.Value = (long)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.Numeric:\r
-                                       case DbDataType.Decimal:\r
-                                               this.Value = (decimal)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.Float:\r
-                                               this.Value = (float)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.Double:\r
-                                               this.Value = (double)0;\r
-                                               break;\r
-\r
-                                       case DbDataType.Date:\r
-                                       case DbDataType.Time:\r
-                                       case DbDataType.TimeStamp:\r
-                                               this.Value = new System.DateTime(0 * 10000L + 621355968000000000);\r
-                                               break;\r
-\r
-                                       default:\r
-                                               throw new IscException("Unknown sql data type: " + this.DataType);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public Type GetSystemType()\r
-               {\r
-                       switch (this.DbDataType)\r
-                       {\r
-                               case DbDataType.Char:\r
-                               case DbDataType.VarChar:\r
-                               case DbDataType.Text:\r
-                                       return Type.GetType("System.String");\r
-\r
-                               case DbDataType.SmallInt:\r
-                                       return Type.GetType("System.Int16");\r
-\r
-                               case DbDataType.Integer:\r
-                                       return Type.GetType("System.Int32");\r
-\r
-                               case DbDataType.BigInt:\r
-                                       return Type.GetType("System.Int64");\r
-\r
-                               case DbDataType.Numeric:\r
-                               case DbDataType.Decimal:\r
-                                       return Type.GetType("System.Decimal");\r
-\r
-                               case DbDataType.Float:\r
-                                       return Type.GetType("System.Single");\r
-\r
-                               case DbDataType.Guid:\r
-                                       return Type.GetType("System.Guid");\r
-\r
-                               case DbDataType.Double:\r
-                                       return Type.GetType("System.Double");\r
-\r
-                               case DbDataType.Date:\r
-                               case DbDataType.Time:\r
-                               case DbDataType.TimeStamp:\r
-                                       return Type.GetType("System.DateTime");\r
-\r
-                               case DbDataType.Binary:\r
-                                       return typeof(byte[]);\r
-\r
-                               case DbDataType.Array:\r
-                                       return Type.GetType("System.Array");\r
-\r
-                               default:\r
-                                       throw new SystemException("Invalid data type");\r
-                       }\r
-               }\r
-\r
-               #endregion\r
-\r
-               #region Private Methods\r
-\r
-               private DbDataType GetDbDataType()\r
-               {\r
-                       // Special case for Guid handling\r
-                       if (this.SqlType == IscCodes.SQL_TEXT && this.Length == 16 &&\r
-                               (this.Charset != null && this.Charset.Name == "OCTETS"))\r
-                       {\r
-                               return DbDataType.Guid;\r
-                       }\r
-\r
-                       switch (this.SqlType)\r
-                       {\r
-                               case IscCodes.SQL_TEXT:\r
-                                       return DbDataType.Char;\r
-\r
-                               case IscCodes.SQL_VARYING:\r
-                                       return DbDataType.VarChar;\r
-\r
-                               case IscCodes.SQL_SHORT:\r
-                                       if (this.subType == 2)\r
-                                       {\r
-                                               return DbDataType.Decimal;\r
-                                       }\r
-                    else if (subType == 1)\r
-                    {\r
-                        return DbDataType.Numeric;\r
-                    }\r
-                    else\r
-                                       {\r
-                                               return DbDataType.SmallInt;\r
-                                       }\r
-\r
-                               case IscCodes.SQL_LONG:\r
-                                       if (this.subType == 2)\r
-                                       {\r
-                                               return DbDataType.Decimal;\r
-                                       }\r
-                    else if (subType == 1)\r
-                    {\r
-                        return DbDataType.Numeric;\r
-                    }\r
-                    else\r
-                                       {\r
-                                               return DbDataType.Integer;\r
-                                       }\r
-\r
-                               case IscCodes.SQL_QUAD:\r
-                               case IscCodes.SQL_INT64:\r
-                                       if (this.subType == 2)\r
-                                       {\r
-                                               return DbDataType.Decimal;\r
-                                       }\r
-                    else if (subType == 1)\r
-                    {\r
-                        return DbDataType.Numeric;\r
-                    }\r
-                    else\r
-                                       {\r
-                                               return DbDataType.BigInt;\r
-                                       }\r
-\r
-                               case IscCodes.SQL_FLOAT:\r
-                                       return DbDataType.Float;\r
-\r
-                               case IscCodes.SQL_DOUBLE:\r
-                               case IscCodes.SQL_D_FLOAT:\r
-                                       if (this.subType == 2)\r
-                                       {\r
-                                               return DbDataType.Decimal;\r
-                                       }\r
-                    else if (subType == 1)\r
-                    {\r
-                        return DbDataType.Numeric;\r
-                    }\r
-                    else\r
-                                       {\r
-                                               return DbDataType.Double;\r
-                                       }\r
-\r
-                               case IscCodes.SQL_BLOB:\r
-                                       if (this.subType == 1)\r
-                                       {\r
-                                               return DbDataType.Text;\r
-                                       }\r
-                                       else\r
-                                       {\r
-                                               return DbDataType.Binary;\r
-                                       }\r
-\r
-                               case IscCodes.SQL_TIMESTAMP:\r
-                                       return DbDataType.TimeStamp;\r
-\r
-                               case IscCodes.SQL_TYPE_TIME:\r
-                                       return DbDataType.Time;\r
-\r
-                               case IscCodes.SQL_TYPE_DATE:\r
-                                       return DbDataType.Date;\r
-\r
-                               case IscCodes.SQL_ARRAY:\r
-                                       return DbDataType.Array;\r
-\r
-                               default:\r
-                                       throw new SystemException("Invalid data type");\r
-                       }\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.Text;
+
+namespace FirebirdSql.Data.Common
+{
+       internal sealed class DbField
+       {
+               #region Fields
+
+               private short           dataType;
+               private short           numericScale;
+               private short           subType;
+               private short           length;
+               private short           nullFlag;
+               private string          name;
+               private string          relation;
+               private string          owner;
+               private string          alias;
+               private int                     charCount;
+               private DbValue         dbValue;
+               private Charset         charset;
+               private ArrayBase       arrayHandle;
+
+               #endregion
+
+               #region Properties
+
+               public DbDataType DbDataType
+               {
+                       get { return this.GetDbDataType(); }
+               }
+
+               public int SqlType
+               {
+                       get { return this.dataType & ~1; }
+               }
+
+               public short DataType
+               {
+                       get { return this.dataType; }
+                       set { this.dataType = value; }
+               }
+
+               public short NumericScale
+               {
+                       get { return this.numericScale; }
+                       set { this.numericScale = value; }
+               }
+
+               public short SubType
+               {
+                       get { return this.subType; }
+                       set
+                       {
+                               this.subType = value;
+                               if (this.IsCharacter())
+                               {
+                                       // Bits 0-7 of sqlsubtype is charset_id (127 is a special value -
+                                       // current attachment charset).
+                                       // Bits 8-17 hold collation_id for this value.
+                                       byte[] cs = BitConverter.GetBytes(value);
+
+                                       int index = Charset.SupportedCharsets.IndexOf(cs[0]);
+                                       if (index != -1)
+                                       {
+                                               this.charset = Charset.SupportedCharsets[index];
+                                       }
+                                       else
+                                       {
+                                               this.charset = Charset.SupportedCharsets[0];
+                                       }
+                               }
+                       }
+               }
+
+               public short Length
+               {
+                       get { return this.length; }
+                       set
+                       {
+                               this.length = value;
+                               if (this.IsCharacter())
+                               {
+                                       this.charCount = this.length / this.charset.BytesPerCharacter;
+                               }
+                       }
+               }
+
+               public short NullFlag
+               {
+                       get { return this.nullFlag; }
+                       set { this.nullFlag = value; }
+               }
+
+               public string Name
+               {
+                       get { return this.name; }
+                       set { this.name = value.Trim(); }
+               }
+
+               public string Relation
+               {
+                       get { return this.relation; }
+                       set { this.relation = value.Trim(); }
+               }
+
+               public string Owner
+               {
+                       get { return this.owner; }
+                       set { this.owner = value.Trim(); }
+               }
+
+               public string Alias
+               {
+                       get { return this.alias; }
+                       set { this.alias = value.Trim(); }
+               }
+
+               public Charset Charset
+               {
+                       get { return this.charset; }
+               }
+
+               public int CharCount
+               {
+                       get { return this.charCount; }
+               }
+
+               public ArrayBase ArrayHandle
+               {
+                       get
+                       {
+                               if (this.IsArray())
+                               {
+                                       return this.arrayHandle;
+                               }
+                               else
+                               {
+                                       throw new IscException("Field is not an array type");
+                               }
+                       }
+
+                       set
+                       {
+                               if (this.IsArray())
+                               {
+                                       this.arrayHandle = value;
+                               }
+                               else
+                               {
+                                       throw new IscException("Field is not an array type");
+                               }
+                       }
+               }
+
+               public DbValue DbValue
+               {
+                       get { return this.dbValue; }
+               }
+
+               public object Value
+               {
+                       get { return this.dbValue.Value; }
+                       set { this.dbValue.Value = value; }
+               }
+
+               #endregion
+
+               #region Constructors
+
+               public DbField()
+               {
+                       this.charCount  = -1;
+                       this.name               = String.Empty;
+                       this.relation   = String.Empty;
+                       this.owner              = String.Empty;
+                       this.alias              = String.Empty;
+                       this.dbValue    = new DbValue(this, DBNull.Value);
+               }
+
+               #endregion
+
+               #region Methods
+
+               public bool IsNumeric()
+               {
+                       if (this.dataType == 0)
+                       {
+                               return false;
+                       }
+
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.SmallInt:
+                               case DbDataType.Integer:
+                               case DbDataType.BigInt:
+                               case DbDataType.Numeric:
+                               case DbDataType.Decimal:
+                               case DbDataType.Float:
+                               case DbDataType.Double:
+                                       return true;
+
+                               default:
+                                       return false;
+                       }
+               }
+
+               public bool IsDecimal()
+               {
+                       if (this.dataType == 0)
+                       {
+                               return false;
+                       }
+
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.Numeric:
+                               case DbDataType.Decimal:
+                                       return true;
+
+                               default:
+                                       return false;
+                       }
+               }
+
+               public bool IsLong()
+               {
+                       if (this.dataType == 0)
+                       {
+                               return false;
+                       }
+
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.Binary:
+                               case DbDataType.Text:
+                                       return true;
+
+                               default:
+                                       return false;
+                       }
+               }
+
+               public bool IsCharacter()
+               {
+                       if (this.dataType == 0)
+                       {
+                               return false;
+                       }
+
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.Char:
+                               case DbDataType.VarChar:
+                               case DbDataType.Text:
+                                       return true;
+
+                               default:
+                                       return false;
+                       }
+               }
+
+               public bool IsArray()
+               {
+                       if (this.dataType == 0)
+                       {
+                               return false;
+                       }
+
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.Array:
+                                       return true;
+
+                               default:
+                                       return false;
+                       }
+               }
+
+               public bool IsAliased()
+               {
+                       return (this.Name != this.Alias) ? true : false;
+               }
+
+               public bool IsExpression()
+               {
+                       return this.Name.Length == 0 ? true : false;
+               }
+
+               public int GetSize()
+               {
+                       if (this.IsLong())
+                       {
+                               return System.Int32.MaxValue;
+                       }
+                       else
+                       {
+                               if (this.IsCharacter())
+                               {
+                                       return this.CharCount;
+                               }
+                               else
+                               {
+                                       return this.Length;
+                               }
+                       }
+               }
+
+               public bool AllowDBNull()
+               {
+                       return ((this.DataType & 1) == 1);
+               }
+
+               public void SetValue(byte[] buffer)
+               {
+                       if (buffer == null || this.NullFlag == -1)
+                       {
+                               this.Value = System.DBNull.Value;
+                       }
+                       else
+                       {
+                               switch (this.SqlType)
+                               {
+                                       case IscCodes.SQL_TEXT:
+                                       case IscCodes.SQL_VARYING:
+                                               if (this.DbDataType == DbDataType.Guid)
+                                               {
+                                                       this.Value = new Guid(buffer);
+                                               }
+                                               else
+                                               {
+                                                       string s = this.Charset.GetString(buffer, 0, buffer.Length);
+
+                                                       if ((this.Length % this.Charset.BytesPerCharacter) == 0 &&
+                                                               s.Length > this.CharCount)
+                                                       {
+                                                               s = s.Substring(0, this.CharCount);
+                                                       }
+
+                                                       this.Value = s;
+                                               }
+                                               break;
+
+                                       case IscCodes.SQL_SHORT:
+                                               if (this.numericScale < 0)
+                                               {
+                                                       this.Value = TypeDecoder.DecodeDecimal(
+                                                               BitConverter.ToInt16(buffer, 0),
+                                                               this.numericScale,
+                                                               this.dataType);
+                                               }
+                                               else
+                                               {
+                                                       this.Value = BitConverter.ToInt16(buffer, 0);
+                                               }
+                                               break;
+
+                                       case IscCodes.SQL_LONG:
+                                               if (this.NumericScale < 0)
+                                               {
+                                                       this.Value = TypeDecoder.DecodeDecimal(
+                                                               BitConverter.ToInt32(buffer, 0),
+                                                               this.numericScale,
+                                                               this.dataType);
+                                               }
+                                               else
+                                               {
+                                                       this.Value = BitConverter.ToInt32(buffer, 0);
+                                               }
+                                               break;
+
+                                       case IscCodes.SQL_FLOAT:
+                                               this.Value = BitConverter.ToSingle(buffer, 0);
+                                               break;
+
+                                       case IscCodes.SQL_DOUBLE:
+                                       case IscCodes.SQL_D_FLOAT:
+                                               this.Value = BitConverter.ToDouble(buffer, 0);
+                                               break;
+
+                                       case IscCodes.SQL_QUAD:
+                                       case IscCodes.SQL_INT64:
+                                       case IscCodes.SQL_BLOB:
+                                       case IscCodes.SQL_ARRAY:
+                                               if (this.NumericScale < 0)
+                                               {
+                                                       this.Value = TypeDecoder.DecodeDecimal(
+                                                               BitConverter.ToInt64(buffer, 0),
+                                                               this.numericScale,
+                                                               this.dataType);
+                                               }
+                                               else
+                                               {
+                                                       this.Value = BitConverter.ToInt64(buffer, 0);
+                                               }
+                                               break;
+
+                                       case IscCodes.SQL_TIMESTAMP:
+                                               DateTime date = TypeDecoder.DecodeDate(
+                                                       BitConverter.ToInt32(buffer, 0));
+
+                                               DateTime time = TypeDecoder.DecodeTime(
+                                                       BitConverter.ToInt32(buffer, 4));
+
+                                               this.Value = new System.DateTime(
+                                                       date.Year, date.Month, date.Day,
+                                                       time.Hour, time.Minute, time.Second, time.Millisecond);
+                                               break;
+
+                                       case IscCodes.SQL_TYPE_TIME:
+                                               this.Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
+                                               break;
+
+                                       case IscCodes.SQL_TYPE_DATE:
+                                               this.Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
+                                               break;
+
+                                       default:
+                                               throw new NotSupportedException("Unknown data type");
+                               }
+                       }
+               }
+
+               public void FixNull()
+               {
+                       if (this.NullFlag == -1 && this.dbValue.IsDBNull())
+                       {
+                               switch (this.DbDataType)
+                               {
+                                       case DbDataType.Char:
+                                       case DbDataType.VarChar:
+                                               this.Value = String.Empty;
+                                               break;
+
+                                       case DbDataType.Guid:
+                                               this.Value = Guid.Empty;
+                                               break;
+
+                                       case DbDataType.SmallInt:
+                                               this.Value = (short)0;
+                                               break;
+
+                                       case DbDataType.Integer:
+                                               this.Value = (int)0;
+                                               break;
+
+                                       case DbDataType.BigInt:
+                                       case DbDataType.Binary:
+                                       case DbDataType.Array:
+                                       case DbDataType.Text:
+                                               this.Value = (long)0;
+                                               break;
+
+                                       case DbDataType.Numeric:
+                                       case DbDataType.Decimal:
+                                               this.Value = (decimal)0;
+                                               break;
+
+                                       case DbDataType.Float:
+                                               this.Value = (float)0;
+                                               break;
+
+                                       case DbDataType.Double:
+                                               this.Value = (double)0;
+                                               break;
+
+                                       case DbDataType.Date:
+                                       case DbDataType.Time:
+                                       case DbDataType.TimeStamp:
+                                               this.Value = new System.DateTime(0 * 10000L + 621355968000000000);
+                                               break;
+
+                                       default:
+                                               throw new IscException("Unknown sql data type: " + this.DataType);
+                               }
+                       }
+               }
+
+               public Type GetSystemType()
+               {
+                       switch (this.DbDataType)
+                       {
+                               case DbDataType.Char:
+                               case DbDataType.VarChar:
+                               case DbDataType.Text:
+                                       return Type.GetType("System.String");
+
+                               case DbDataType.SmallInt:
+                                       return Type.GetType("System.Int16");
+
+                               case DbDataType.Integer:
+                                       return Type.GetType("System.Int32");
+
+                               case DbDataType.BigInt:
+                                       return Type.GetType("System.Int64");
+
+                               case DbDataType.Numeric:
+                               case DbDataType.Decimal:
+                                       return Type.GetType("System.Decimal");
+
+                               case DbDataType.Float:
+                                       return Type.GetType("System.Single");
+
+                               case DbDataType.Guid:
+                                       return Type.GetType("System.Guid");
+
+                               case DbDataType.Double:
+                                       return Type.GetType("System.Double");
+
+                               case DbDataType.Date:
+                               case DbDataType.Time:
+                               case DbDataType.TimeStamp:
+                                       return Type.GetType("System.DateTime");
+
+                               case DbDataType.Binary:
+                                       return typeof(byte[]);
+
+                               case DbDataType.Array:
+                                       return Type.GetType("System.Array");
+
+                               default:
+                                       throw new SystemException("Invalid data type");
+                       }
+               }
+
+               #endregion
+
+               #region Private Methods
+
+               private DbDataType GetDbDataType()
+               {
+                       // Special case for Guid handling
+                       if (this.SqlType == IscCodes.SQL_TEXT && this.Length == 16 &&
+                               (this.Charset != null && this.Charset.Name == "OCTETS"))
+                       {
+                               return DbDataType.Guid;
+                       }
+
+                       switch (this.SqlType)
+                       {
+                               case IscCodes.SQL_TEXT:
+                                       return DbDataType.Char;
+
+                               case IscCodes.SQL_VARYING:
+                                       return DbDataType.VarChar;
+
+                               case IscCodes.SQL_SHORT:
+                                       if (this.subType == 2)
+                                       {
+                                               return DbDataType.Decimal;
+                                       }
+                    else if (subType == 1)
+                    {
+                        return DbDataType.Numeric;
+                    }
+                    else
+                                       {
+                                               return DbDataType.SmallInt;
+                                       }
+
+                               case IscCodes.SQL_LONG:
+                                       if (this.subType == 2)
+                                       {
+                                               return DbDataType.Decimal;
+                                       }
+                    else if (subType == 1)
+                    {
+                        return DbDataType.Numeric;
+                    }
+                    else
+                                       {
+                                               return DbDataType.Integer;
+                                       }
+
+                               case IscCodes.SQL_QUAD:
+                               case IscCodes.SQL_INT64:
+                                       if (this.subType == 2)
+                                       {
+                                               return DbDataType.Decimal;
+                                       }
+                    else if (subType == 1)
+                    {
+                        return DbDataType.Numeric;
+                    }
+                    else
+                                       {
+                                               return DbDataType.BigInt;
+                                       }
+
+                               case IscCodes.SQL_FLOAT:
+                                       return DbDataType.Float;
+
+                               case IscCodes.SQL_DOUBLE:
+                               case IscCodes.SQL_D_FLOAT:
+                                       if (this.subType == 2)
+                                       {
+                                               return DbDataType.Decimal;
+                                       }
+                    else if (subType == 1)
+                    {
+                        return DbDataType.Numeric;
+                    }
+                    else
+                                       {
+                                               return DbDataType.Double;
+                                       }
+
+                               case IscCodes.SQL_BLOB:
+                                       if (this.subType == 1)
+                                       {
+                                               return DbDataType.Text;
+                                       }
+                                       else
+                                       {
+                                               return DbDataType.Binary;
+                                       }
+
+                               case IscCodes.SQL_TIMESTAMP:
+                                       return DbDataType.TimeStamp;
+
+                               case IscCodes.SQL_TYPE_TIME:
+                                       return DbDataType.Time;
+
+                               case IscCodes.SQL_TYPE_DATE:
+                                       return DbDataType.Date;
+
+                               case IscCodes.SQL_ARRAY:
+                                       return DbDataType.Array;
+
+                               default:
+                                       throw new SystemException("Invalid data type");
+                       }
+               }
+
+               #endregion
+       }
 }
\ No newline at end of file