Skip to content

Commit

Permalink
Add Data.Odbc project
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahi committed Dec 23, 2020
1 parent 7657562 commit dd7fcbe
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/Data.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data.SqlServer", "Src\Data.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data.OleDb", "Src\Data.OleDb\Data.OleDb.csproj", "{4CC8278A-A7A4-4EDB-A533-9665D11498B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data.Odbc", "Src\Data.Odbc\Data.Odbc.csproj", "{883CEA76-BDAC-493B-B991-30910EF72091}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -79,6 +81,10 @@ Global
{4CC8278A-A7A4-4EDB-A533-9665D11498B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CC8278A-A7A4-4EDB-A533-9665D11498B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CC8278A-A7A4-4EDB-A533-9665D11498B3}.Release|Any CPU.Build.0 = Release|Any CPU
{883CEA76-BDAC-493B-B991-30910EF72091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{883CEA76-BDAC-493B-B991-30910EF72091}.Debug|Any CPU.Build.0 = Debug|Any CPU
{883CEA76-BDAC-493B-B991-30910EF72091}.Release|Any CPU.ActiveCfg = Release|Any CPU
{883CEA76-BDAC-493B-B991-30910EF72091}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -94,6 +100,7 @@ Global
{B5A822F0-965F-4959-80E6-F30A8E178B34} = {EC27CB28-3D15-4C74-A1E6-6A2E60BCE31E}
{6FB0152C-0089-4E28-B400-A20BEABCA936} = {EC27CB28-3D15-4C74-A1E6-6A2E60BCE31E}
{4CC8278A-A7A4-4EDB-A533-9665D11498B3} = {EC27CB28-3D15-4C74-A1E6-6A2E60BCE31E}
{883CEA76-BDAC-493B-B991-30910EF72091} = {EC27CB28-3D15-4C74-A1E6-6A2E60BCE31E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65EF901E-961B-48A6-9A64-1680F2624732}
Expand Down
26 changes: 26 additions & 0 deletions source/Src/Data.Odbc/Configuration/OdbcDatabaseData.cs
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);
}
}
24 changes: 24 additions & 0 deletions source/Src/Data.Odbc/Data.Odbc.csproj
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>
65 changes: 65 additions & 0 deletions source/Src/Data.Odbc/OdbcDatabase.cs
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;
}
}
}
}

0 comments on commit dd7fcbe

Please sign in to comment.