DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DeveelDbParameter.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Data;
19 using System.Data.Common;
20 
21 using Deveel.Data.Types;
22 
23 namespace Deveel.Data.Client {
24  public sealed class DeveelDbParameter : DbParameter, IDbDataParameter {
26  private DbType dbType;
27 
28  public override void ResetDbType() {
29  if (typeCode == SqlTypeCode.Bit ||
30  typeCode == SqlTypeCode.Boolean) {
31  dbType = DbType.Boolean;
32  } else if (typeCode == SqlTypeCode.TinyInt) {
33  dbType = DbType.Byte;
34  } else if (typeCode == SqlTypeCode.SmallInt) {
35  dbType = DbType.Int16;
36  } else if (typeCode == SqlTypeCode.Integer) {
37  dbType = DbType.Int32;
38  } else if (typeCode == SqlTypeCode.BigInt) {
39  dbType = DbType.Int64;
40  } else if (typeCode == SqlTypeCode.Real ||
41  typeCode == SqlTypeCode.Float) {
42  dbType = DbType.Single;
43  } else if (typeCode == SqlTypeCode.Double) {
44  dbType = DbType.Double;
45  } else if (typeCode == SqlTypeCode.Decimal) {
46  dbType = DbType.Decimal;
47  } else if (typeCode == SqlTypeCode.Numeric) {
48  dbType = DbType.VarNumeric;
49  } else {
50  throw new NotSupportedException(String.Format("The SQL Type '{0}' cannot be converted to DbType.", typeCode));
51  }
52  }
53 
54  private void ResetSqlType() {
55  if (dbType == DbType.String ||
56  dbType == DbType.AnsiString) {
57  typeCode = SqlTypeCode.VarChar;
58  } else if (dbType == DbType.StringFixedLength ||
59  dbType == DbType.AnsiStringFixedLength) {
60  typeCode = SqlTypeCode.Char;
61  } else if (dbType == DbType.Binary) {
62  typeCode = SqlTypeCode.Binary;
63  } else if (dbType == DbType.Boolean) {
64  typeCode = SqlTypeCode.Boolean;
65  } else if (dbType == DbType.Byte) {
66  typeCode = SqlTypeCode.TinyInt;
67  } else if (dbType == DbType.Int16) {
68  typeCode = SqlTypeCode.SmallInt;
69  } else if (dbType == DbType.Int32) {
70  typeCode = SqlTypeCode.Integer;
71  } else if (dbType == DbType.Int64) {
72  typeCode = SqlTypeCode.BigInt;
73  } else if (dbType == DbType.Single) {
74  typeCode = SqlTypeCode.Float;
75  } else if (dbType == DbType.Double) {
76  typeCode = SqlTypeCode.Double;
77  } else if (dbType == DbType.VarNumeric ||
78  dbType == DbType.Decimal ||
79  dbType == DbType.Currency) {
80  typeCode = SqlTypeCode.Numeric;
81  } else if (dbType == DbType.Date ||
82  dbType == DbType.DateTime2) {
83  typeCode = SqlTypeCode.Date;
84  } else if (dbType == DbType.DateTime ||
85  dbType == DbType.DateTimeOffset) {
86  typeCode = SqlTypeCode.TimeStamp;
87  } else if (dbType == DbType.Time) {
88  typeCode = SqlTypeCode.Time;
89  } else if (dbType == DbType.Object ||
90  dbType == DbType.Xml) {
91  typeCode = SqlTypeCode.Type;
92  } else {
93  throw new NotSupportedException(String.Format("The DbType '{0}' is not supported by DeveelDB engine", dbType));
94  }
95  }
96 
97  public override DbType DbType {
98  get { return dbType; }
99  set {
100  dbType = value;
101  ResetSqlType();
102  }
103  }
104 
106  get { return typeCode; }
107  set {
108  typeCode = value;
109  ResetDbType();
110  }
111  }
112 
113  public override System.Data.ParameterDirection Direction { get; set; }
114 
115  public override bool IsNullable { get; set; }
116 
117  public override string ParameterName { get; set; }
118 
119  public override string SourceColumn { get; set; }
120 
121  public override DataRowVersion SourceVersion { get; set; }
122 
123  public override object Value { get; set; }
124 
125  public override bool SourceColumnNullMapping { get; set; }
126 
127  public override int Size { get; set; }
128 
129  byte IDbDataParameter.Precision {
130  get { return Precision; }
131  set { Precision = value; }
132  }
133 
134  byte IDbDataParameter.Scale {
135  get { return Scale; }
136  set { Scale = value; }
137  }
138 
139  public byte Precision { get; set; }
140 
141  public byte Scale { get; set; }
142 
143  public string Locale { get; set; }
144  }
145 }
A long string in the system.
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23