2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
22 namespace FirebirdSql.Data.Common
24 internal sealed class TypeHelper
34 #region Static Methods
36 public static short GetSize(DbDataType dataType)
40 case DbDataType.Array:
41 case DbDataType.Binary:
45 case DbDataType.SmallInt:
48 case DbDataType.Integer:
49 case DbDataType.Float:
54 case DbDataType.BigInt:
55 case DbDataType.Double:
56 case DbDataType.TimeStamp:
67 public static int GetFbType(DbDataType dataType, bool isNullable)
73 case DbDataType.Array:
74 sqltype = IscCodes.SQL_ARRAY;
77 case DbDataType.Binary:
79 sqltype = IscCodes.SQL_BLOB;
83 sqltype = IscCodes.SQL_TEXT;
86 case DbDataType.VarChar:
87 sqltype = IscCodes.SQL_VARYING;
90 case DbDataType.SmallInt:
91 sqltype = IscCodes.SQL_SHORT;
94 case DbDataType.Integer:
95 sqltype = IscCodes.SQL_LONG;
98 case DbDataType.BigInt:
99 sqltype = IscCodes.SQL_INT64;
102 case DbDataType.Float:
103 sqltype = IscCodes.SQL_FLOAT;
106 case DbDataType.Guid:
107 sqltype = IscCodes.SQL_TEXT;
110 case DbDataType.Double:
111 sqltype = IscCodes.SQL_DOUBLE;
114 case DbDataType.Date:
115 sqltype = IscCodes.SQL_TYPE_DATE;
118 case DbDataType.Time:
119 sqltype = IscCodes.SQL_TYPE_TIME;
122 case DbDataType.TimeStamp:
123 sqltype = IscCodes.SQL_TIMESTAMP;
127 throw new ArgumentException("Invalid data type");
138 public static int GetFbType(int blrType)
142 case IscCodes.blr_varying:
143 case IscCodes.blr_varying2:
144 return IscCodes.SQL_VARYING;
146 case IscCodes.blr_text:
147 case IscCodes.blr_text2:
148 case IscCodes.blr_cstring:
149 case IscCodes.blr_cstring2:
150 return IscCodes.SQL_TEXT;
152 case IscCodes.blr_short:
153 return IscCodes.SQL_SHORT;
155 case IscCodes.blr_long:
156 return IscCodes.SQL_LONG;
158 case IscCodes.blr_quad:
159 return IscCodes.SQL_QUAD;
161 case IscCodes.blr_int64:
162 case IscCodes.blr_blob_id:
163 return IscCodes.SQL_INT64;
165 case IscCodes.blr_double:
166 return IscCodes.SQL_DOUBLE;
168 case IscCodes.blr_d_float:
169 return IscCodes.SQL_D_FLOAT;
171 case IscCodes.blr_float:
172 return IscCodes.SQL_FLOAT;
174 case IscCodes.blr_sql_date:
175 return IscCodes.SQL_TYPE_DATE;
177 case IscCodes.blr_sql_time:
178 return IscCodes.SQL_TYPE_TIME;
180 case IscCodes.blr_timestamp:
181 return IscCodes.SQL_TIMESTAMP;
183 case IscCodes.blr_blob:
184 return IscCodes.SQL_BLOB;
187 throw new ArgumentException("Invalid data type");
191 public static DbDataType GetDbDataType(int blrType, int subType, int scale)
195 case IscCodes.blr_varying:
196 case IscCodes.blr_varying2:
197 return DbDataType.VarChar;
199 case IscCodes.blr_text:
200 case IscCodes.blr_text2:
201 return DbDataType.Char;
203 case IscCodes.blr_cstring:
204 case IscCodes.blr_cstring2:
205 return DbDataType.Text;
207 case IscCodes.blr_short:
210 return DbDataType.Decimal;
212 else if (subType == 1)
214 return DbDataType.Numeric;
218 return DbDataType.SmallInt;
221 case IscCodes.blr_long:
224 return DbDataType.Decimal;
226 else if (subType == 1)
228 return DbDataType.Numeric;
232 return DbDataType.Integer;
235 case IscCodes.blr_quad:
236 case IscCodes.blr_int64:
237 case IscCodes.blr_blob_id:
240 return DbDataType.Decimal;
242 else if (subType == 1)
244 return DbDataType.Numeric;
248 return DbDataType.BigInt;
251 case IscCodes.blr_double:
252 case IscCodes.blr_d_float:
253 return DbDataType.Double;
255 case IscCodes.blr_float:
256 return DbDataType.Float;
258 case IscCodes.blr_sql_date:
259 return DbDataType.Date;
261 case IscCodes.blr_sql_time:
262 return DbDataType.Time;
264 case IscCodes.blr_timestamp:
265 return DbDataType.TimeStamp;
267 case IscCodes.blr_blob:
270 return DbDataType.Text;
274 return DbDataType.Binary;
278 throw new ArgumentException("Invalid data type");
282 public static string GetDataTypeName(DbDataType dataType)
286 case DbDataType.Array:
289 case DbDataType.Binary:
292 case DbDataType.Text:
293 return "BLOB SUB_TYPE 1";
295 case DbDataType.Char:
296 case DbDataType.Guid:
299 case DbDataType.VarChar:
302 case DbDataType.SmallInt:
305 case DbDataType.Integer:
308 case DbDataType.Float:
311 case DbDataType.Double:
312 return "DOUBLE PRECISION";
314 case DbDataType.BigInt:
317 case DbDataType.Numeric:
320 case DbDataType.Decimal:
323 case DbDataType.Date:
326 case DbDataType.Time:
329 case DbDataType.TimeStamp:
337 public static DbType GetDbType(DbDataType type)
341 case DbDataType.Array:
342 case DbDataType.Binary:
343 return DbType.Binary;
345 case DbDataType.Text:
346 case DbDataType.VarChar:
347 case DbDataType.Char:
348 return DbType.String;
350 case DbDataType.SmallInt:
353 case DbDataType.Integer:
356 case DbDataType.BigInt:
359 case DbDataType.Date:
362 case DbDataType.Time:
365 case DbDataType.TimeStamp:
366 return DbType.DateTime;
368 case DbDataType.Numeric:
369 case DbDataType.Decimal:
370 return DbType.Decimal;
372 case DbDataType.Float:
373 return DbType.Single;
375 case DbDataType.Double:
376 return DbType.Double;
378 case DbDataType.Guid:
382 throw new ArgumentException("Invalid data type");
386 public static DbDataType GetDbDataType(DbType dbType)
391 case DbType.AnsiString:
392 return DbDataType.VarChar;
394 case DbType.StringFixedLength:
395 case DbType.AnsiStringFixedLength:
396 return DbDataType.Char;
403 return DbDataType.SmallInt;
407 return DbDataType.Integer;
411 return DbDataType.BigInt;
414 return DbDataType.Date;
417 return DbDataType.Time;
419 case DbType.DateTime:
420 return DbDataType.TimeStamp;
424 return DbDataType.Binary;
427 return DbDataType.Decimal;
430 return DbDataType.Double;
433 return DbDataType.Float;
436 return DbDataType.Guid;
439 throw new ArgumentException("Invalid data type");