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