2 // OdbcTypeMap.cs : Mapping between different odbc types
5 // Sureshkumar T <tsureshkumar@novell.com>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 // * Type mapping between various odbc driver types.
33 // For further infomartion between these mapping visit following msdn site
35 // * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/
36 // odbcc_data_types.asp
37 // * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/
38 // odbcconverting_data_from_c_to_sql_data_types.asp
39 // * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/
40 // odbcconverting_data_from_sql_to_c_data_types.asp
41 // * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/
42 // odbcparameter_data_types.asp
43 // * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/
44 // html/frlrfsystemdataodbcodbctypeclasstopic.asp
47 // OdbcType SQL_C_TYPE SQL_TYPE
48 // ===================================================================
49 // BigInt SQL_C_TYPE.SBIGINT SQL_TYPE.BIGINT
50 // Binary SQL_C_TYPE.BINARY SQL_TYPE.BINARY
51 // Bit SQL_C_TYPE.BIT SQL_TYPE.BIT
52 // Char SQL_C_TYPE.CHAR SQL_TYPE.CHAR
53 // Date SQL_C_TYPE.TYPE_DATE SQL_TYPE.TYPE_DATE
54 // DateTime SQL_C_TYPE.TIMESTAMP SQL_TYPE.TIMESTAMP
55 // Decimal SQL_C_TYPE.NUMERIC SQL_TYPE.NUMERIC
56 // Double SQL_C_TYPE.DOUBLE SQL_TYPE.DOUBLE
57 // Image SQL_C_TYPE.BINARY SQL_TYPE.BINARY
58 // Int SQL_C_TYPE.LONG SQL_TYPE.INTEGER
59 // NChar SQL_C_TYPE.WCHAR SQL_TYPE.WCHAR
60 // NText SQL_C_TYPE.WCHAR SQL_TYPE.WLONGVARCHAR
61 // Numeric SQL_C_TYPE.NUMERIC SQL_TYPE.NUMERIC
62 // NVarChar SQL_C_TYPE.WCHAR SQL_TYPE.WVARCHAR
63 // Real SQL_C_TYPE.FLOAT SQL_TYPE.REAL
64 // SignedBigInt SQL_C_TYPE.SBIGINT SQL_TYPE.BIGINT
65 // SmallDateTime SQL_C_TYPE.TIMESTAMP SQL_TYPE.TIMESTAMP
66 // SmallInt SQL_C_TYPE.SHORT SQL_TYPE.SMALLINT
67 // Text SQL_C_TYPE.WCHAR SQL_TYPE.LONGVARCHAR
68 // Time SQL_C_TYPE.TYPE_TIME SQL_TYPE.TYPE_TIME
69 // Timestamp SQL_C_TYPE.BINARY SQL_TYPE.BINARY
70 // TinyInt SQL_C_TYPE.UTINYINT SQL_TYPE.TINYINT
71 // UniqueIdentifier SQL_C_TYPE.GUID SQL_TYPE.GUID
72 // VarBinary SQL_C_TYPE.BINARY SQL_TYPE.VARBINARY
73 // VarChar SQL_C_TYPE.WCHAR SQL_TYPE.WVARCHAR
74 //====================================================================
78 using System.Collections;
79 using System.Data.Common;
81 namespace System.Data.Odbc
83 internal struct OdbcTypeMap
86 public OdbcType OdbcType;
87 public SQL_C_TYPE NativeType;
88 public SQL_TYPE SqlType;
90 private static Hashtable maps = new Hashtable ();
92 public OdbcTypeMap (DbType dbType, OdbcType odbcType,
93 SQL_C_TYPE nativeType, SQL_TYPE sqlType)
98 NativeType = nativeType;
102 public static Hashtable Maps {
106 static OdbcTypeMap ()
108 maps [OdbcType.BigInt] = new OdbcTypeMap (DbType.Int64,
112 maps [OdbcType.Binary] = new OdbcTypeMap (DbType.Binary,
116 maps [OdbcType.Bit] = new OdbcTypeMap (DbType.Boolean,
120 maps [OdbcType.Char] = new OdbcTypeMap (DbType.String,
124 maps [OdbcType.Date] = new OdbcTypeMap (DbType.Date,
128 maps [OdbcType.DateTime] = new OdbcTypeMap (DbType.DateTime,
130 SQL_C_TYPE.TIMESTAMP,
132 maps [OdbcType.Decimal] = new OdbcTypeMap (DbType.Decimal,
136 maps [OdbcType.Double] = new OdbcTypeMap (DbType.Double,
140 maps [OdbcType.Image] = new OdbcTypeMap (DbType.Binary,
144 maps [OdbcType.Int] = new OdbcTypeMap (DbType.Int32,
148 maps [OdbcType.NChar] = new OdbcTypeMap (DbType.String,
150 SQL_C_TYPE.CHAR, //change
151 SQL_TYPE.CHAR); //change
152 maps [OdbcType.NText] = new OdbcTypeMap (DbType.String,
154 SQL_C_TYPE.CHAR, // change
155 SQL_TYPE.LONGVARCHAR); //change
156 // Currently, NUMERIC types works only with NUMERIC SQL Type to CHAR C Type mapping (pgsql). Other databases return
157 // SQL_TYPE.DECIMAL in place of numeric types.
158 maps [OdbcType.Numeric] = new OdbcTypeMap (DbType.Decimal,
162 maps [OdbcType.NVarChar] = new OdbcTypeMap (DbType.String,
164 SQL_C_TYPE.CHAR, // change
165 SQL_TYPE.VARCHAR); //change
166 maps [OdbcType.Real] = new OdbcTypeMap (DbType.Single,
170 maps [OdbcType.SmallDateTime] = new OdbcTypeMap (DbType.DateTime,
171 OdbcType.SmallDateTime,
172 SQL_C_TYPE.TIMESTAMP,
174 maps [OdbcType.SmallInt] = new OdbcTypeMap (DbType.Int16,
178 maps [OdbcType.Text] = new OdbcTypeMap (DbType.String,
180 SQL_C_TYPE.CHAR, //change
181 SQL_TYPE.LONGVARCHAR);
182 maps [OdbcType.Time] = new OdbcTypeMap (DbType.DateTime,
186 maps [OdbcType.Timestamp] = new OdbcTypeMap (DbType.DateTime,
190 maps [OdbcType.TinyInt] = new OdbcTypeMap (DbType.SByte,
194 maps [OdbcType.UniqueIdentifier] = new OdbcTypeMap (DbType.Guid,
195 OdbcType.UniqueIdentifier,
198 maps [OdbcType.VarBinary] = new OdbcTypeMap (DbType.Binary,
202 maps [OdbcType.VarChar] = new OdbcTypeMap (DbType.String,