2 * Firebird ADO.NET Data provider for .NET and Mono
\r
4 * The contents of this file are subject to the Initial
\r
5 * Developer's Public License Version 1.0 (the "License");
\r
6 * you may not use this file except in compliance with the
\r
7 * License. You may obtain a copy of the License at
\r
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
\r
10 * Software distributed under the License is distributed on
\r
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
\r
12 * express or implied. See the License for the specific
\r
13 * language governing rights and limitations under the License.
\r
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
\r
16 * All Rights Reserved.
\r
20 using System.Globalization;
\r
22 namespace FirebirdSql.Data.Common
\r
24 internal sealed class TypeEncoder
\r
26 #region Constructors
\r
28 private TypeEncoder()
\r
34 #region Static Methods
\r
36 public static object EncodeDecimal(decimal d, int scale, int sqltype)
\r
38 long multiplier = 1;
\r
42 multiplier = (long)System.Math.Pow(10, scale * (-1));
\r
45 switch (sqltype & ~1)
\r
47 case IscCodes.SQL_SHORT:
\r
48 return (short)(d * multiplier);
\r
50 case IscCodes.SQL_LONG:
\r
51 return (int)(d * multiplier);
\r
53 case IscCodes.SQL_QUAD:
\r
54 case IscCodes.SQL_INT64:
\r
55 return (long)(d * multiplier);
\r
57 case IscCodes.SQL_DOUBLE:
\r
63 public static int EncodeTime(DateTime d)
\r
65 GregorianCalendar calendar = new GregorianCalendar();
\r
68 (int)(calendar.GetHour(d) * 3600000 +
\r
69 calendar.GetMinute(d) * 60000 +
\r
70 calendar.GetSecond(d) * 1000 +
\r
71 calendar.GetMilliseconds(d)) * 10;
\r
76 public static int EncodeDate(DateTime d)
\r
78 int day, month, year;
\r
81 GregorianCalendar calendar = new GregorianCalendar();
\r
83 day = calendar.GetDayOfMonth(d);
\r
84 month = calendar.GetMonth(d);
\r
85 year = calendar.GetYear(d);
\r
98 ya = year - 100 * c;
\r
100 return ((146097 * c) / 4 +
\r
102 (153 * month + 2) / 5 +
\r
103 day + 1721119 - 2400001);
\r