comparison Source/Data/DataProvider/InformixDataProvider.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Data;
3 using System.Data.Common;
4 using System.Globalization;
5 using System.Threading;
6
7 using IBM.Data.Informix;
8
9 namespace BLToolkit.Data.DataProvider
10 {
11 using Sql.SqlProvider;
12
13 public class InformixDataProvider : DataProviderBase
14 {
15 public override IDbConnection CreateConnectionObject () { return new IfxConnection (); }
16 public override DbDataAdapter CreateDataAdapterObject() { return new IfxDataAdapter (); }
17 public override ISqlProvider CreateSqlProvider () { return new InformixSqlProvider(); }
18
19 public override Type ConnectionType { get { return typeof(IfxConnection); } }
20 public override string Name { get { return DataProvider.ProviderName.Informix; } }
21
22 public override bool DeriveParameters(IDbCommand command)
23 {
24 if (command is IfxCommand)
25 {
26 IfxCommandBuilder.DeriveParameters((IfxCommand)command);
27 return true;
28 }
29
30 return false;
31 }
32
33 public override object Convert(object value, ConvertType convertType)
34 {
35 switch (convertType)
36 {
37 case ConvertType.ExceptionToErrorNumber:
38 if (value is IfxException)
39 {
40 var ex = (IfxException)value;
41
42 foreach (IfxError error in ex.Errors)
43 return error.NativeError;
44
45 return 0;
46 }
47
48 break;
49 }
50
51 return SqlProvider.Convert(value, convertType);
52 }
53
54 public override void PrepareCommand(ref CommandType commandType, ref string commandText, ref IDbDataParameter[] commandParameters)
55 {
56 base.PrepareCommand(ref commandType, ref commandText, ref commandParameters);
57
58 if (commandParameters != null) foreach (var p in commandParameters)
59 {
60 if (p.Value is Guid)
61 {
62 var value = p.Value.ToString();
63 p.DbType = DbType.AnsiStringFixedLength;
64 p.Value = value;
65 p.Size = value.Length;
66 }
67 else if (p.Value is bool)
68 {
69 p.Value = ((InformixSqlProvider)SqlProvider).ConvertBooleanValue((bool)p.Value);
70 }
71 //else if (p.DbType == DbType.Binary)
72 //{
73 // var ip = (IfxParameter)p;
74
75 // ip.IfxType = IfxType.Blob;
76 //}
77 }
78 }
79
80 /*
81 public override int ExecuteArray(IDbCommand command, int iterations)
82 {
83 var cmd = (IfxCommand)command;
84 try
85 {
86 cmd.ArrayBindCount = iterations;
87 return cmd.ExecuteNonQuery();
88 }
89 finally
90 {
91 cmd.ArrayBindCount = 0;
92 }
93 }
94 */
95
96 #region GetDataReader
97
98 public override IDataReader GetDataReader(Mapping.MappingSchema schema, IDataReader dataReader)
99 {
100 return dataReader is IfxDataReader?
101 new InformixDataReaderEx((IfxDataReader)dataReader):
102 base.GetDataReader(schema, dataReader);
103 }
104
105 class InformixDataReaderEx : DataReaderBase<IfxDataReader>, IDataReader
106 {
107 public InformixDataReaderEx(IfxDataReader rd): base(rd)
108 {
109 }
110
111 public new float GetFloat(int i)
112 {
113 var current = Thread.CurrentThread.CurrentCulture;
114
115 if (Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture)
116 Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
117
118 var value = DataReader.GetFloat(i);
119
120 if (current != CultureInfo.InvariantCulture)
121 Thread.CurrentThread.CurrentCulture = current;
122
123 return value;
124 }
125
126 public new double GetDouble(int i)
127 {
128 var current = Thread.CurrentThread.CurrentCulture;
129
130 if (Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture)
131 Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
132
133 var value = DataReader.GetDouble(i);
134
135 if (current != CultureInfo.InvariantCulture)
136 Thread.CurrentThread.CurrentCulture = current;
137
138 return value;
139 }
140
141 public new decimal GetDecimal(int i)
142 {
143 var current = Thread.CurrentThread.CurrentCulture;
144
145 if (Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture)
146 Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
147
148 var value = DataReader.GetDecimal (i);
149
150 if (current != CultureInfo.InvariantCulture)
151 Thread.CurrentThread.CurrentCulture = current;
152
153 return value;
154 }
155 }
156
157 #endregion
158 }
159 }