-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Text; | ||
using Microsoft.Practices.EnterpriseLibrary.Data; | ||
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration; | ||
|
||
namespace Data.Odbc.Configuration | ||
{ | ||
public class OdbcDatabaseData : DatabaseData | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OdbcDatabaseData"/> class with the specified | ||
/// <paramref name="connectionStringSettings"/> and <paramref name="configurationSource"/> delegate. | ||
/// </summary> | ||
/// <param name="connectionStringSettings">The connection string configuration</param> | ||
/// <param name="configurationSource">A delegate to retrieve the configuration section</param> | ||
protected OdbcDatabaseData(ConnectionStringSettings connectionStringSettings, Func<string, ConfigurationSection> configurationSource) | ||
: base(connectionStringSettings, configurationSource) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Database BuildDatabase() => new OdbcDatabase(ConnectionString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net45;net46;net47;netcoreapp3.0;netstandard2.0</TargetFrameworks> | ||
<AssemblyName>$(PreAssemblyName).Data.Odbc</AssemblyName> | ||
<PackageId>$(PrePackageName).Data.Odbc$(PostPackageName)</PackageId> | ||
<RootNamespace>$(PreAssemblyName).Data.Odbc</RootNamespace> | ||
|
||
<Description>ODBC support for Enterprise Library Data Access Application Block. The Data Access Application Block simplifies the development of tasks that implement common data access functionality. Applications can use this application block in a variety of situations, such as reading data for display, passing data through application layers, and submitting changed data back to the database system.</Description> | ||
<PackageTags>entlib entlib6 Enterprise Library data daab dab LOB ODBC</PackageTags> | ||
|
||
<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion> | ||
<FileVersion>$(Version).$(Revision)</FileVersion> | ||
|
||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>..\..\EnterpriseLibrary.snk</AssemblyOriginatorKeyFile> | ||
<DelaySign>false</DelaySign> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Data\Data.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
using System.Data.Odbc; | ||
using Microsoft.Practices.EnterpriseLibrary.Data; | ||
using Microsoft.Practices.EnterpriseLibrary.Data.Properties; | ||
|
||
namespace Data.Odbc | ||
{ | ||
/// <summary> | ||
/// Represents an ODBC data provider wrapper. | ||
/// </summary> | ||
public class OdbcDatabase : Database | ||
{ | ||
/// <summary> | ||
/// Initialize a new instance of the <see cref="OdbcDatabase"/> using the specified <paramref name="connectionString"/>. | ||
/// </summary> | ||
/// <param name="connectionString">The connection string</param> | ||
public OdbcDatabase(string connectionString) : base(connectionString, OdbcFactory.Instance) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves parameter information from the stored procedure specified in the <see cref="DbCommand"/> and populates | ||
/// the Parameters collection of the specified <see cref="DbCommand"/> object. | ||
/// </summary> | ||
/// <param name="discoveryCommand">The <see cref="DbCommand"/> to do the discovery.</param> | ||
/// <exception cref="InvalidCastException"><paramref name="discoveryCommand"/> is not an <see cref="OdbcCommand"/>.</exception> | ||
/// <exception cref="InvalidOperationException">The underlying ODBC provider does not support returning stored | ||
/// procedure parameter information, the command text is not a valid stored procedure name, or the CommandType | ||
/// specified was not <see cref="CommandType.StoredProcedure" />.</exception> | ||
protected override void DeriveParameters(DbCommand discoveryCommand) | ||
{ | ||
OdbcCommandBuilder.DeriveParameters((OdbcCommand)discoveryCommand); | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the database provider supports parameter discovery. This depends on the underlying | ||
/// ODBC provider. | ||
/// </summary> | ||
/// <value>Returns <b>true</b>, but you should consult the documentation for the underlying ODBC provider.</value> | ||
/// <seealso cref="DeriveParameters(DbCommand)"/> | ||
public override bool SupportsParemeterDiscovery => true; | ||
|
||
/// <inheritdoc/> | ||
protected override void SetUpRowUpdatedEvent(DbDataAdapter adapter) | ||
{ | ||
((OdbcDataAdapter)adapter).RowUpdated += OdbcDataAdapter_RowUpdated; | ||
} | ||
|
||
/// <summary> | ||
/// Listens for the RowUpdate event on a data adapter to support UpdateBehavior.Continue | ||
/// </summary> | ||
/// <param name="sender">The <see cref="OdbcDataAdapter"/> which raised the event</param> | ||
/// <param name="e">The event arguments.</param> | ||
private void OdbcDataAdapter_RowUpdated(object sender, OdbcRowUpdatedEventArgs e) | ||
{ | ||
if (e.RecordsAffected == 0 && e.Errors != null) | ||
{ | ||
e.Row.RowError = Resources.ExceptionMessageUpdateDataSetRowFailure; | ||
e.Status = UpdateStatus.SkipCurrentRow; | ||
} | ||
} | ||
} | ||
} |