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;
214 return DbDataType.SmallInt;
217 case IscCodes.blr_long:
220 return DbDataType.Decimal;
224 return DbDataType.Integer;
227 case IscCodes.blr_quad:
228 case IscCodes.blr_int64:
229 case IscCodes.blr_blob_id:
232 return DbDataType.Decimal;
236 return DbDataType.BigInt;
239 case IscCodes.blr_double:
240 case IscCodes.blr_d_float:
241 return DbDataType.Double;
243 case IscCodes.blr_float:
244 return DbDataType.Float;
246 case IscCodes.blr_sql_date:
247 return DbDataType.Date;
249 case IscCodes.blr_sql_time:
250 return DbDataType.Time;
252 case IscCodes.blr_timestamp:
253 return DbDataType.TimeStamp;
255 case IscCodes.blr_blob:
258 return DbDataType.Text;
262 return DbDataType.Binary;
266 throw new ArgumentException("Invalid data type");
270 public static string GetDataTypeName(DbDataType dataType)
274 case DbDataType.Array:
277 case DbDataType.Binary:
280 case DbDataType.Text:
281 return "BLOB SUB_TYPE 1";
283 case DbDataType.Char:
284 case DbDataType.Guid:
287 case DbDataType.VarChar:
290 case DbDataType.SmallInt:
293 case DbDataType.Integer:
296 case DbDataType.Float:
299 case DbDataType.Double:
300 return "DOUBLE PRECISION";
302 case DbDataType.BigInt:
305 case DbDataType.Numeric:
308 case DbDataType.Decimal:
311 case DbDataType.Date:
314 case DbDataType.Time:
317 case DbDataType.TimeStamp:
325 public static DbType GetDbType(DbDataType type)
329 case DbDataType.Array:
330 case DbDataType.Binary:
331 return DbType.Binary;
333 case DbDataType.Text:
334 case DbDataType.VarChar:
335 case DbDataType.Char:
336 return DbType.String;
338 case DbDataType.SmallInt:
341 case DbDataType.Integer:
344 case DbDataType.BigInt:
347 case DbDataType.Date:
350 case DbDataType.Time:
353 case DbDataType.TimeStamp:
354 return DbType.DateTime;
356 case DbDataType.Numeric:
357 case DbDataType.Decimal:
358 return DbType.Decimal;
360 case DbDataType.Float:
361 return DbType.Single;
363 case DbDataType.Double:
364 return DbType.Double;
366 case DbDataType.Guid:
370 throw new ArgumentException("Invalid data type");
374 public static DbDataType GetDbDataType(DbType dbType)
379 case DbType.AnsiString:
380 return DbDataType.VarChar;
382 case DbType.StringFixedLength:
383 case DbType.AnsiStringFixedLength:
384 return DbDataType.Char;
391 return DbDataType.SmallInt;
395 return DbDataType.Integer;
399 return DbDataType.BigInt;
402 return DbDataType.Date;
405 return DbDataType.Time;
407 case DbType.DateTime:
408 return DbDataType.TimeStamp;
412 return DbDataType.Binary;
415 return DbDataType.Decimal;
418 return DbDataType.Double;
421 return DbDataType.Float;
424 return DbDataType.Guid;
427 throw new ArgumentException("Invalid data type");