runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.Data.Odbc Namespace

Open alexgwolff opened this issue 10 years ago • 68 comments

Are there any plans to provide this API? My project is still rightfully so. Not everything can to use with ADO.NET like Excel ODBC You see that even the Mono has support for it. Att.

alexgwolff avatar Oct 26 '16 12:10 alexgwolff

It's not part of .NET Standard 2.0. CC: @saurabh500 @weshaggard @stephentoub

karelz avatar Oct 26 '16 15:10 karelz

cc @YoungGah

saurabh500 avatar Oct 26 '16 18:10 saurabh500

@YoungGah says the code is a thin layer on top of native libraries. It should be in reference source code, so we just need it ported over.

karelz avatar Nov 10 '16 23:11 karelz

says the code is a thin layer on top of native libraries. It should be in reference source code, so we just need it ported over

The reference source code probably only includes the managed layer. Is the native code in Windows? If so, a counterpart would be needed for Unix. Or is the native code portable? If so, we'd need to open source it and make it available as part of corefx.

stephentoub avatar Nov 10 '16 23:11 stephentoub

@stephentoub ODBC driver is available on Windows and Linux and the API is available to be consumed by applications.

System.Data.Odbc was a managed layer calling into the ODBC APIs

saurabh500 avatar Nov 11 '16 00:11 saurabh500

ODBC driver is available on Windows and Linux and the API is available to be consumed by applications.

Excellent. And macOS as well?

stephentoub avatar Nov 11 '16 00:11 stephentoub

No its not available on macOS. EDIT: SqlServer ODBC driver is not available on macOS

saurabh500 avatar Nov 11 '16 00:11 saurabh500

@stephentoub & @saurabh500 Any ODBC drivers that run on Linux and MacOS should work with System.Data.Odbc layer once it is ported. There are many difference ODBC drivers that are provided by other companies.

YoungGah avatar Nov 11 '16 00:11 YoungGah

@saurabh500

No its not available on macOS.

Do you mean that ODBC isn't available to macOS or that specific ODBC drivers aren't supported on macOS?

terrajobst avatar Nov 17 '16 21:11 terrajobst

@terrajobst When I wrote that comment I meant that Sql ODBC driver is not available on macOS.

However there are ODBC managers for macOS which can be used with ODBC drivers. Hence this namespace implementation is feasible on Xplat.

saurabh500 avatar Nov 17 '16 21:11 saurabh500

@terrajobst When I wrote that comment I meant that Sql ODBC driver is not available on macOS.

Got it. Thanks!

Hence this namespace implementation is feasible on Xplat.

That's what I was concerned about. Sweet.

terrajobst avatar Nov 17 '16 22:11 terrajobst

The MIT-licensed source code to port can be found here: https://github.com/Microsoft/referencesource/tree/4fe4349175f4c5091d972a7e56ea12012f1e7170/System.Data/System/Data/Odbc

bleroy avatar Nov 23 '16 01:11 bleroy

FYI: as part of our effort in https://github.com/aspnet/EntityFramework/issues/7432 I'll be looking at porting this library.

On a side note, I was just looking at the DbConnectionHelper.cs code and there is clearly some build step missing. I found how mono generates the XXXXConnection (e.g. OdbcConnection) files here: https://github.com/mono/mono/blob/master/mcs/class/System.Data/Makefile.

For the record, I believe this is missing from System.Data.SqlClient, but maybe because they just didn't use this partial class' features. For Odbc it seems to be necessary.

colltoaction avatar Jan 21 '17 01:01 colltoaction

On a side note, I was just looking at the DbConnectionHelper.cs code and there is clearly some build step missing. I found how mono generates the XXXXConnection (e.g. OdbcConnection) files here: https://github.com/mono/mono/blob/master/mcs/class/System.Data/Makefile.

The namespace and the Class name in DbConnectionHelper.cs were changed to the name of the provider i.e. OdbcConnection during build time in System.Data

You can copy the file over and change the name to OdbcConnection and the relevant namespace.

saurabh500 avatar Jan 21 '17 01:01 saurabh500

@saurabh500 figured it out from the Makefile :')

colltoaction avatar Jan 21 '17 01:01 colltoaction

First passing test! Connecting, selecting and reading seem to be working fine in Windows using the native odbc32.dll.

I'm wondering now what a good approach would be for making tests that don't depend on my own environment. Haven't yet looked at how SqlClient does it, but will do on Monday. Anyway, please let me know if you have any suggestions!

colltoaction avatar Jan 29 '17 04:01 colltoaction

Just a quick update since I've been working on other stuff and couldn't get this merged yet:

  1. Everything seems to be working fine in my branch
  2. Support for Linux and Mac comes from unixODBC, and since it implements the ODBC standard which specifies the C interface, we don't even need to change the native function signatures.
  3. I'm working with the CI team so we can have some integration tests running on the SQLite provider. So far we've found that not all the Linux distros we support have an up-to-date version (we require unixODBC>2.3.1).

colltoaction avatar Feb 24 '17 19:02 colltoaction

  1. Support for Linux and Mac comes from unixODBC, and since it implements the ODBC standard which specifies the C interface, we don't even need to change the native function signatures.

C types can have different sizes on different platforms. Do we know that's not an issue here? This is one of the reasons we have the native shims for other libraries, so that we can have the managed APIs P/Invoke to native signatures that use types of known sizes regardless of platform, e.g. int32_t, int64_t, etc.

stephentoub avatar Feb 24 '17 19:02 stephentoub

From what I see here, it looks like all parameters are standard-specific types, e.g. SQLUSMALLINT which is a C# UInt16 or SQLSMALLINT which is a C# Int16.

unixODBC also has these types: http://www.unixodbc.org/doc/ProgrammerManual/Tutorial/gloss.html

colltoaction avatar Feb 24 '17 19:02 colltoaction

From what I see here, it looks like all parameters are standard-specific types, e.g. SQLUSMALLINT which is a C# UInt16 or SQLSMALLINT which is a C# Int16.

The trouble is that the C standard doesn't actually define the byte size of these types, only the range of values they're required to be able to hold and the relationship between them. Thus, for example, in theory a type like int could be 32-bit on some systems and 64-bit on others, and they'd all conform to the spec.

stephentoub avatar Feb 25 '17 16:02 stephentoub