comparison Source/Data/DataProvider/DB2DataProvider.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
5 using IBM.Data.DB2;
6
7 namespace BLToolkit.Data.DataProvider
8 {
9 using Sql.SqlProvider;
10
11 public class DB2DataProvider : DataProviderBase
12 {
13 public override IDbConnection CreateConnectionObject () { return new DB2Connection (); }
14 public override DbDataAdapter CreateDataAdapterObject() { return new DB2DataAdapter(); }
15 public override ISqlProvider CreateSqlProvider () { return new DB2SqlProvider(); }
16
17 public override Type ConnectionType { get { return typeof(DB2Connection); } }
18 public override string Name { get { return DataProvider.ProviderName.DB2; } }
19
20 public override bool DeriveParameters(IDbCommand command)
21 {
22 if (command is DB2Command)
23 {
24 DB2CommandBuilder.DeriveParameters((DB2Command)command);
25 return true;
26 }
27
28 return false;
29 }
30
31 public override object Convert(object value, ConvertType convertType)
32 {
33 switch (convertType)
34 {
35 case ConvertType.ExceptionToErrorNumber:
36 if (value is DB2Exception)
37 {
38 var ex = (DB2Exception)value;
39
40 foreach (DB2Error error in ex.Errors)
41 return error.RowNumber;
42
43 return 0;
44 }
45
46 break;
47
48 }
49
50 return SqlProvider.Convert(value, convertType);
51 }
52
53 public override void PrepareCommand(ref CommandType commandType, ref string commandText, ref IDbDataParameter[] commandParameters)
54 {
55 base.PrepareCommand(ref commandType, ref commandText, ref commandParameters);
56
57 if (commandParameters != null) foreach (var p in commandParameters)
58 {
59 if (p.Value is bool)
60 p.Value = (bool)p.Value ? 1 : 0;
61 else if (p.Value is Guid)
62 {
63 p.Value = ((Guid)p.Value).ToByteArray();
64 p.DbType = DbType.Binary;
65 p.Size = 16;
66 }
67 }
68 }
69
70 /*
71 public override int ExecuteArray(IDbCommand command, int iterations)
72 {
73 var cmd = (DB2Command)command;
74 try
75 {
76 cmd.ArrayBindCount = iterations;
77 return cmd.ExecuteNonQuery();
78 }
79 finally
80 {
81 cmd.ArrayBindCount = 0;
82 }
83 }
84 */
85 }
86 }