OdbcColumn.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. case OdbcType.Timestamp:
  78. case OdbcType.DateTime:
  79. case OdbcType.Date:
  80. case OdbcType.SmallDateTime:
  81. return typeof(DateTime);
  82. case OdbcType.Decimal:
  83. return typeof(Decimal);
  84. case OdbcType.Numeric:
  85. case OdbcType.Double:
  86. return typeof(Double);
  87. case OdbcType.Int:
  88. return typeof(System.Int32);
  89. case OdbcType.Text:
  90. case OdbcType.NText:
  91. case OdbcType.NVarChar:
  92. case OdbcType.VarChar:
  93. return typeof(string);
  94. case OdbcType.Real:
  95. return typeof(float);
  96. case OdbcType.SmallInt:
  97. return typeof(System.Int16);
  98. case OdbcType.UniqueIdentifier:
  99. return typeof(Guid);
  100. }
  101. throw new InvalidCastException();
  102. }
  103. }
  104. internal bool IsDateType
  105. {
  106. get
  107. {
  108. switch (OdbcType)
  109. {
  110. case OdbcType.Time:
  111. case OdbcType.Timestamp:
  112. case OdbcType.DateTime:
  113. case OdbcType.Date:
  114. case OdbcType.SmallDateTime:
  115. return true;
  116. default:
  117. return false;
  118. }
  119. }
  120. }
  121. internal bool IsStringType
  122. {
  123. get
  124. {
  125. switch (OdbcType)
  126. {
  127. case OdbcType.Char:
  128. case OdbcType.Text:
  129. case OdbcType.NText:
  130. case OdbcType.NVarChar:
  131. case OdbcType.VarChar:
  132. return true;
  133. default:
  134. return false;
  135. }
  136. }
  137. }
  138. internal bool IsVariableSizeType {
  139. get {
  140. if (IsStringType)
  141. return true;
  142. switch (OdbcType) {
  143. case OdbcType.Binary :
  144. case OdbcType.VarBinary :
  145. case OdbcType.Image :
  146. return true;
  147. default :
  148. return false;
  149. }
  150. }
  151. }
  152. internal SQL_TYPE SqlType
  153. {
  154. get {
  155. if ( _sqlType == SQL_TYPE.UNASSIGNED)
  156. _sqlType = OdbcTypeConverter.GetTypeMap (OdbcType).SqlType;
  157. return _sqlType;
  158. }
  159. set {_sqlType = value;}
  160. }
  161. internal SQL_C_TYPE SqlCType
  162. {
  163. get {
  164. if ( _sqlCType == SQL_C_TYPE.UNASSIGNED)
  165. _sqlCType = OdbcTypeConverter.GetTypeMap (OdbcType).NativeType;
  166. return _sqlCType;
  167. }
  168. set {_sqlCType = value;}
  169. }
  170. internal void UpdateTypes (SQL_TYPE sqlType)
  171. {
  172. SqlType = sqlType;
  173. OdbcTypeMap map = OdbcTypeConverter.GetTypeMap (SqlType);
  174. OdbcType = map.OdbcType;
  175. SqlCType = map.NativeType;
  176. }
  177. }
  178. }