OdbcColumn.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. namespace System.Data.Odbc
  25. {
  26. /// <summary>
  27. /// Summary description for OdbcColumn.
  28. /// </summary>
  29. internal class OdbcColumn
  30. {
  31. internal string ColumnName;
  32. internal OdbcType OdbcType;
  33. private SQL_TYPE _sqlType = SQL_TYPE.UNASSIGNED;
  34. private SQL_C_TYPE _sqlCType = SQL_C_TYPE.UNASSIGNED;
  35. internal bool AllowDBNull;
  36. internal int MaxLength;
  37. internal int Digits;
  38. internal object Value;
  39. internal OdbcColumn (string Name, OdbcType Type)
  40. {
  41. this.ColumnName = Name;
  42. this.OdbcType = Type;
  43. AllowDBNull = false;
  44. MaxLength = 0;
  45. Digits = 0;
  46. Value = null;
  47. }
  48. internal OdbcColumn (string Name, SQL_TYPE type)
  49. {
  50. this.ColumnName = Name;
  51. AllowDBNull = false;
  52. MaxLength = 0;
  53. Digits = 0;
  54. Value = null;
  55. UpdateTypes (type);
  56. }
  57. internal Type DataType
  58. {
  59. get
  60. {
  61. switch (OdbcType)
  62. {
  63. case OdbcType.TinyInt:
  64. return typeof (System.Byte);
  65. case OdbcType.BigInt:
  66. return typeof (System.Int64);
  67. case OdbcType.Image:
  68. case OdbcType.VarBinary:
  69. case OdbcType.Binary:
  70. return typeof (byte[]);
  71. case OdbcType.Bit:
  72. return typeof (bool);
  73. case OdbcType.NChar:
  74. case OdbcType.Char:
  75. return typeof (string);
  76. case OdbcType.Time:
  77. return typeof (TimeSpan);
  78. case OdbcType.Timestamp:
  79. case OdbcType.DateTime:
  80. case OdbcType.Date:
  81. case OdbcType.SmallDateTime:
  82. return typeof (DateTime);
  83. case OdbcType.Decimal:
  84. return typeof (Decimal);
  85. case OdbcType.Numeric:
  86. case OdbcType.Double:
  87. return typeof (Double);
  88. case OdbcType.Int:
  89. return typeof (System.Int32);
  90. case OdbcType.Text:
  91. case OdbcType.NText:
  92. case OdbcType.NVarChar:
  93. case OdbcType.VarChar:
  94. return typeof (string);
  95. case OdbcType.Real:
  96. return typeof (float);
  97. case OdbcType.SmallInt:
  98. return typeof (System.Int16);
  99. case OdbcType.UniqueIdentifier:
  100. return typeof (Guid);
  101. }
  102. throw new InvalidCastException();
  103. }
  104. }
  105. internal bool IsDateType
  106. {
  107. get
  108. {
  109. switch (OdbcType)
  110. {
  111. case OdbcType.Time:
  112. case OdbcType.Timestamp:
  113. case OdbcType.DateTime:
  114. case OdbcType.Date:
  115. case OdbcType.SmallDateTime:
  116. return true;
  117. default:
  118. return false;
  119. }
  120. }
  121. }
  122. internal bool IsStringType
  123. {
  124. get
  125. {
  126. switch (OdbcType)
  127. {
  128. case OdbcType.Char:
  129. case OdbcType.Text:
  130. case OdbcType.NText:
  131. case OdbcType.NVarChar:
  132. case OdbcType.VarChar:
  133. return true;
  134. default:
  135. return false;
  136. }
  137. }
  138. }
  139. internal bool IsVariableSizeType {
  140. get {
  141. if (IsStringType)
  142. return true;
  143. switch (OdbcType) {
  144. case OdbcType.Binary :
  145. case OdbcType.VarBinary :
  146. case OdbcType.Image :
  147. return true;
  148. default :
  149. return false;
  150. }
  151. }
  152. }
  153. internal SQL_TYPE SqlType
  154. {
  155. get {
  156. if ( _sqlType == SQL_TYPE.UNASSIGNED)
  157. _sqlType = OdbcTypeConverter.GetTypeMap (OdbcType).SqlType;
  158. return _sqlType;
  159. }
  160. set {_sqlType = value;}
  161. }
  162. internal SQL_C_TYPE SqlCType
  163. {
  164. get {
  165. if ( _sqlCType == SQL_C_TYPE.UNASSIGNED)
  166. _sqlCType = OdbcTypeConverter.GetTypeMap (OdbcType).NativeType;
  167. return _sqlCType;
  168. }
  169. set {_sqlCType = value;}
  170. }
  171. internal void UpdateTypes (SQL_TYPE sqlType)
  172. {
  173. SqlType = sqlType;
  174. OdbcTypeMap map = OdbcTypeConverter.GetTypeMap (SqlType);
  175. OdbcType = map.OdbcType;
  176. SqlCType = map.NativeType;
  177. }
  178. }
  179. }