0
|
1 using System;
|
|
2 using System.Data;
|
|
3 using System.Data.Common;
|
|
4 using System.Data.Odbc;
|
|
5
|
|
6 namespace BLToolkit.Data.DataProvider
|
|
7 {
|
|
8 using Sql.SqlProvider;
|
|
9
|
|
10 /// <summary>
|
|
11 /// Implements access to the Data Provider for ODBC.
|
|
12 /// </summary>
|
|
13 /// <remarks>
|
|
14 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
15 /// </remarks>
|
|
16 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
|
|
17 public class OdbcDataProvider : DataProviderBase
|
|
18 {
|
|
19 /// <summary>
|
|
20 /// Creates the database connection object.
|
|
21 /// </summary>
|
|
22 /// <remarks>
|
|
23 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
24 /// </remarks>
|
|
25 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
|
|
26 /// <returns>The database connection object.</returns>
|
|
27 public override IDbConnection CreateConnectionObject()
|
|
28 {
|
|
29 return new OdbcConnection();
|
|
30 }
|
|
31
|
|
32 /// <summary>
|
|
33 /// Creates the data adapter object.
|
|
34 /// </summary>
|
|
35 /// <remarks>
|
|
36 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
37 /// </remarks>
|
|
38 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
|
|
39 /// <returns>A data adapter object.</returns>
|
|
40 public override DbDataAdapter CreateDataAdapterObject()
|
|
41 {
|
|
42 return new OdbcDataAdapter();
|
|
43 }
|
|
44
|
|
45 /// <summary>
|
|
46 /// Populates the specified <see cref="IDbCommand"/> object's Parameters collection with
|
|
47 /// parameter information for the stored procedure specified in the <see cref="IDbCommand"/>.
|
|
48 /// </summary>
|
|
49 /// <remarks>
|
|
50 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
51 /// </remarks>
|
|
52 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
|
|
53 /// <param name="command">The <see cref="IDbCommand"/> referencing the stored procedure for which the parameter
|
|
54 /// information is to be derived. The derived parameters will be populated into
|
|
55 /// the Parameters of this command.</param>
|
|
56 public override bool DeriveParameters(IDbCommand command)
|
|
57 {
|
|
58 OdbcCommandBuilder.DeriveParameters((OdbcCommand)command);
|
|
59 return true;
|
|
60 }
|
|
61
|
|
62 public override object Convert(object value, ConvertType convertType)
|
|
63 {
|
|
64 switch (convertType)
|
|
65 {
|
|
66 case ConvertType.ExceptionToErrorNumber:
|
|
67 if (value is OdbcException)
|
|
68 {
|
|
69 var ex = (OdbcException)value;
|
|
70 if (ex.Errors.Count > 0)
|
|
71 return ex.Errors[0].NativeError;
|
|
72 }
|
|
73 break;
|
|
74 }
|
|
75
|
|
76 return base.Convert(value, convertType);
|
|
77 }
|
|
78
|
|
79 public override ISqlProvider CreateSqlProvider()
|
|
80 {
|
|
81 throw new NotSupportedException();
|
|
82 }
|
|
83
|
|
84 /// <summary>
|
|
85 /// Returns connection type.
|
|
86 /// </summary>
|
|
87 /// <remarks>
|
|
88 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
89 /// </remarks>
|
|
90 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataManager Method</seealso>
|
|
91 /// <value>An instance of the <see cref="Type"/> class.</value>
|
|
92 public override Type ConnectionType
|
|
93 {
|
|
94 get { return typeof(OdbcConnection); }
|
|
95 }
|
|
96
|
|
97 public const string NameString = DataProvider.ProviderName.Odbc;
|
|
98
|
|
99 /// <summary>
|
|
100 /// Returns the data provider name.
|
|
101 /// </summary>
|
|
102 /// <remarks>
|
|
103 /// See the <see cref="DbManager.AddDataProvider(DataProviderBase)"/> method to find an example.
|
|
104 /// </remarks>
|
|
105 /// <seealso cref="DbManager.AddDataProvider(DataProviderBase)">AddDataProvider Method</seealso>
|
|
106 /// <value>Data provider name.</value>
|
|
107 public override string Name
|
|
108 {
|
|
109 get { return NameString; }
|
|
110 }
|
|
111 }
|
|
112 }
|