From: Hans Leidekker hans@codeweavers.com
--- dlls/odbc32/proxyodbc.c | 120 +++++++++++++++++++++++++------ dlls/odbc32/unixlib.c | 156 ---------------------------------------- dlls/odbc32/unixlib.h | 58 ++------------- 3 files changed, 105 insertions(+), 229 deletions(-)
diff --git a/dlls/odbc32/proxyodbc.c b/dlls/odbc32/proxyodbc.c index 23ca8974f33..fb2b5e09929 100644 --- a/dlls/odbc32/proxyodbc.c +++ b/dlls/odbc32/proxyodbc.c @@ -403,6 +403,14 @@ SQLRETURN WINAPI SQLCopyDesc(SQLHDESC SourceDescHandle, SQLHDESC TargetDescHandl return ret; }
+static HKEY open_sources_key( HKEY root ) +{ + static const WCHAR sourcesW[] = L"Software\ODBC\ODBC.INI\ODBC Data Sources"; + HKEY key; + if (!RegCreateKeyExW( root, sourcesW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL )) return key; + return NULL; +} + /************************************************************************* * SQLDataSources [ODBC32.057] */ @@ -410,10 +418,10 @@ SQLRETURN WINAPI SQLDataSources(SQLHENV EnvironmentHandle, SQLUSMALLINT Directio SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, SQLCHAR *Description, SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2) { - struct SQLDataSources_params params = { 0, Direction, ServerName, BufferLength1, NameLength1, Description, - BufferLength2, NameLength2 }; struct handle *handle = EnvironmentHandle; - SQLRETURN ret; + SQLRETURN ret = SQL_ERROR; + DWORD len_source = BufferLength1, len_desc = BufferLength2; + LONG res;
TRACE("(EnvironmentHandle %p, Direction %d, ServerName %p, BufferLength1 %d, NameLength1 %p, Description %p," " BufferLength2 %d, NameLength2 %p)\n", EnvironmentHandle, Direction, ServerName, BufferLength1, @@ -421,16 +429,52 @@ SQLRETURN WINAPI SQLDataSources(SQLHENV EnvironmentHandle, SQLUSMALLINT Directio
if (!handle) return SQL_INVALID_HANDLE;
- params.EnvironmentHandle = handle->unix_handle; - if (SUCCESS((ret = ODBC_CALL( SQLDataSources, ¶ms ))) && TRACE_ON(odbc)) + if (Direction == SQL_FETCH_FIRST) { - if (ServerName && NameLength1 && *NameLength1 > 0) - TRACE(" DataSource %s", debugstr_an((const char *)ServerName, *NameLength1)); - if (Description && NameLength2 && *NameLength2 > 0) - TRACE(" Description %s", debugstr_an((const char *)Description, *NameLength2)); - TRACE("\n"); + handle->sources_idx = 0; + handle->sources_system = FALSE; + RegCloseKey( handle->sources_key ); + if (!(handle->sources_key = open_sources_key( HKEY_CURRENT_USER ))) return SQL_ERROR; }
+ res = RegEnumValueA( handle->sources_key, handle->sources_idx, (char *)ServerName, &len_source, NULL, + NULL, (BYTE *)Description, &len_desc ); + if (res == ERROR_NO_MORE_ITEMS) + { + if (handle->sources_system) + { + ret = SQL_NO_DATA; + goto done; + } + /* user key exhausted, continue with system key */ + RegCloseKey( handle->sources_key ); + if (!(handle->sources_key = open_sources_key( HKEY_LOCAL_MACHINE ))) goto done; + handle->sources_idx = 0; + handle->sources_system = TRUE; + res = RegEnumValueA( handle->sources_key, handle->sources_idx, (char *)ServerName, &len_source, NULL, + NULL, (BYTE *)Description, &len_desc ); + } + if (res == ERROR_NO_MORE_ITEMS) + { + ret = SQL_NO_DATA; + goto done; + } + else if (res == ERROR_SUCCESS) + { + if (NameLength1) *NameLength1 = len_source; + if (NameLength2) *NameLength2 = len_desc - 1; + + handle->sources_idx++; + ret = SQL_SUCCESS; + } + +done: + if (ret) + { + RegCloseKey( handle->sources_key ); + handle->sources_key = NULL; + handle->sources_idx = 0; + } TRACE("Returning %d\n", ret); return ret; } @@ -2788,10 +2832,10 @@ SQLRETURN WINAPI SQLDataSourcesW(SQLHENV EnvironmentHandle, SQLUSMALLINT Directi SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, WCHAR *Description, SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2) { - struct SQLDataSourcesW_params params = { 0, Direction, ServerName, BufferLength1, NameLength1, Description, - BufferLength2, NameLength2 }; struct handle *handle = EnvironmentHandle; - SQLRETURN ret; + SQLRETURN ret = SQL_ERROR; + DWORD len_source = BufferLength1, len_desc = BufferLength2; + LONG res;
TRACE("(EnvironmentHandle %p, Direction %d, ServerName %p, BufferLength1 %d, NameLength1 %p, Description %p," " BufferLength2 %d, NameLength2 %p)\n", EnvironmentHandle, Direction, ServerName, BufferLength1, @@ -2799,18 +2843,52 @@ SQLRETURN WINAPI SQLDataSourcesW(SQLHENV EnvironmentHandle, SQLUSMALLINT Directi
if (!handle) return SQL_INVALID_HANDLE;
- params.EnvironmentHandle = handle->unix_handle; - ret = ODBC_CALL( SQLDataSourcesW, ¶ms ); + if (Direction == SQL_FETCH_FIRST) + { + handle->sources_idx = 0; + handle->sources_system = FALSE; + RegCloseKey( handle->sources_key ); + if (!(handle->sources_key = open_sources_key( HKEY_CURRENT_USER ))) return SQL_ERROR; + }
- if (ret >= 0 && TRACE_ON(odbc)) + res = RegEnumValueW( handle->sources_key, handle->sources_idx, ServerName, &len_source, NULL, NULL, + (BYTE *)Description, &len_desc ); + if (res == ERROR_NO_MORE_ITEMS) { - if (ServerName && NameLength1 && *NameLength1 > 0) - TRACE(" DataSource %s", debugstr_wn(ServerName, *NameLength1)); - if (Description && NameLength2 && *NameLength2 > 0) - TRACE(" Description %s", debugstr_wn(Description, *NameLength2)); - TRACE("\n"); + if (handle->sources_system) + { + ret = SQL_NO_DATA; + goto done; + } + /* user key exhausted, continue with system key */ + RegCloseKey( handle->sources_key ); + if (!(handle->sources_key = open_sources_key( HKEY_LOCAL_MACHINE ))) goto done; + handle->sources_idx = 0; + handle->sources_system = TRUE; + res = RegEnumValueW( handle->sources_key, handle->sources_idx, ServerName, &len_source, NULL, NULL, + (BYTE *)Description, &len_desc ); } + if (res == ERROR_NO_MORE_ITEMS) + { + ret = SQL_NO_DATA; + goto done; + } + else if (res == ERROR_SUCCESS) + { + if (NameLength1) *NameLength1 = len_source; + if (NameLength2) *NameLength2 = len_desc - 1;
+ handle->sources_idx++; + ret = SQL_SUCCESS; + } + +done: + if (ret) + { + RegCloseKey( handle->sources_key ); + handle->sources_key = NULL; + handle->sources_idx = 0; + } TRACE("Returning %d\n", ret); return ret; } diff --git a/dlls/odbc32/unixlib.c b/dlls/odbc32/unixlib.c index e5612678899..24f935fb1d2 100644 --- a/dlls/odbc32/unixlib.c +++ b/dlls/odbc32/unixlib.c @@ -609,22 +609,6 @@ static NTSTATUS wrap_SQLCopyDesc( void *args ) return SQLCopyDesc( (SQLHDESC)(ULONG_PTR)params->SourceDescHandle, (SQLHDESC)(ULONG_PTR)params->TargetDescHandle ); }
-static NTSTATUS wrap_SQLDataSources( void *args ) -{ - struct SQLDataSources_params *params = args; - return SQLDataSources( (SQLHENV)(ULONG_PTR)params->EnvironmentHandle, params->Direction, params->ServerName, - params->BufferLength1, params->NameLength1, params->Description, - params->BufferLength2, params->NameLength2 ); -} - -static NTSTATUS wrap_SQLDataSourcesW( void *args ) -{ - struct SQLDataSourcesW_params *params = args; - return SQLDataSourcesW( (SQLHENV)(ULONG_PTR)params->EnvironmentHandle, params->Direction, params->ServerName, - params->BufferLength1, params->NameLength1, params->Description, - params->BufferLength2, params->NameLength2 ); -} - static NTSTATUS wrap_SQLDescribeCol( void *args ) { struct SQLDescribeCol_params *params = args; @@ -670,22 +654,6 @@ static NTSTATUS wrap_SQLDriverConnectW( void *args ) params->BufferLength, params->Length2, params->DriverCompletion ); }
-static NTSTATUS wrap_SQLDrivers( void *args ) -{ - struct SQLDrivers_params *params = args; - return SQLDrivers( (SQLHENV)(ULONG_PTR)params->EnvironmentHandle, params->Direction, params->DriverDescription, - params->BufferLength1, params->DescriptionLength, params->DriverAttributes, - params->BufferLength2, params->AttributesLength ); -} - -static NTSTATUS wrap_SQLDriversW( void *args ) -{ - struct SQLDriversW_params *params = args; - return SQLDriversW( (SQLHENV)(ULONG_PTR)params->EnvironmentHandle, params->Direction, params->DriverDescription, - params->BufferLength1, params->DescriptionLength, params->DriverAttributes, - params->BufferLength2, params->AttributesLength ); -} - static NTSTATUS wrap_SQLEndTran( void *args ) { struct SQLEndTran_params *params = args; @@ -1274,16 +1242,12 @@ const unixlib_entry_t __wine_unix_call_funcs[] = wrap_SQLConnect, wrap_SQLConnectW, wrap_SQLCopyDesc, - wrap_SQLDataSources, - wrap_SQLDataSourcesW, wrap_SQLDescribeCol, wrap_SQLDescribeColW, wrap_SQLDescribeParam, wrap_SQLDisconnect, wrap_SQLDriverConnect, wrap_SQLDriverConnectW, - wrap_SQLDrivers, - wrap_SQLDriversW, wrap_SQLEndTran, wrap_SQLError, wrap_SQLErrorW, @@ -1767,64 +1731,6 @@ static NTSTATUS wow64_SQLConnectW( void *args ) return wrap_SQLConnectW( ¶ms ); }
-static NTSTATUS wow64_SQLDataSources( void *args ) -{ - struct - { - UINT64 EnvironmentHandle; - UINT16 Direction; - PTR32 ServerName; - INT16 BufferLength1; - PTR32 NameLength1; - PTR32 Description; - INT16 BufferLength2; - PTR32 NameLength2; - } const *params32 = args; - - struct SQLDataSources_params params = - { - params32->EnvironmentHandle, - params32->Direction, - ULongToPtr(params32->ServerName), - params32->BufferLength1, - ULongToPtr(params32->NameLength1), - ULongToPtr(params32->Description), - params32->BufferLength2, - ULongToPtr(params32->NameLength2) - }; - - return wrap_SQLDataSources( ¶ms ); -} - -static NTSTATUS wow64_SQLDataSourcesW( void *args ) -{ - struct - { - UINT64 EnvironmentHandle; - UINT16 Direction; - PTR32 ServerName; - INT16 BufferLength1; - PTR32 NameLength1; - PTR32 Description; - INT16 BufferLength2; - PTR32 NameLength2; - } const *params32 = args; - - struct SQLDataSourcesW_params params = - { - params32->EnvironmentHandle, - params32->Direction, - ULongToPtr(params32->ServerName), - params32->BufferLength1, - ULongToPtr(params32->NameLength1), - ULongToPtr(params32->Description), - params32->BufferLength2, - ULongToPtr(params32->NameLength2) - }; - - return wrap_SQLDataSourcesW( ¶ms ); -} - static NTSTATUS wow64_SQLDescribeCol( void *args ) { struct @@ -1912,64 +1818,6 @@ static NTSTATUS wow64_SQLDescribeParam( void *args ) return wrap_SQLDescribeParam( ¶ms ); }
-static NTSTATUS wow64_SQLDrivers( void *args ) -{ - struct - { - UINT64 EnvironmentHandle; - UINT16 Direction; - PTR32 DriverDescription; - INT16 BufferLength1; - PTR32 DescriptionLength; - PTR32 DriverAttributes; - INT16 BufferLength2; - PTR32 AttributesLength; - } const *params32 = args; - - struct SQLDrivers_params params = - { - params32->EnvironmentHandle, - params32->Direction, - ULongToPtr(params32->DriverDescription), - params32->BufferLength1, - ULongToPtr(params32->DescriptionLength), - ULongToPtr(params32->DriverAttributes), - params32->BufferLength2, - ULongToPtr(params32->AttributesLength) - }; - - return wrap_SQLDrivers( ¶ms ); -} - -static NTSTATUS wow64_SQLDriversW( void *args ) -{ - struct - { - UINT64 EnvironmentHandle; - UINT16 Direction; - PTR32 DriverDescription; - INT16 BufferLength1; - PTR32 DescriptionLength; - PTR32 DriverAttributes; - INT16 BufferLength2; - PTR32 AttributesLength; - } const *params32 = args; - - struct SQLDriversW_params params = - { - params32->EnvironmentHandle, - params32->Direction, - ULongToPtr(params32->DriverDescription), - params32->BufferLength1, - ULongToPtr(params32->DescriptionLength), - ULongToPtr(params32->DriverAttributes), - params32->BufferLength2, - ULongToPtr(params32->AttributesLength) - }; - - return wrap_SQLDriversW( ¶ms ); -} - static NTSTATUS wow64_SQLDriverConnect( void *args ) { struct @@ -3646,16 +3494,12 @@ const unixlib_entry_t __wine_unix_call_wow64_funcs[] = wow64_SQLConnect, wow64_SQLConnectW, wrap_SQLCopyDesc, - wow64_SQLDataSources, - wow64_SQLDataSourcesW, wow64_SQLDescribeCol, wow64_SQLDescribeColW, wow64_SQLDescribeParam, wrap_SQLDisconnect, wow64_SQLDriverConnect, wow64_SQLDriverConnectW, - wow64_SQLDrivers, - wow64_SQLDriversW, wrap_SQLEndTran, wow64_SQLError, wow64_SQLErrorW, diff --git a/dlls/odbc32/unixlib.h b/dlls/odbc32/unixlib.h index 5e4d799b509..5cc27902ca1 100644 --- a/dlls/odbc32/unixlib.h +++ b/dlls/odbc32/unixlib.h @@ -57,16 +57,12 @@ enum sql_funcs unix_SQLConnect, unix_SQLConnectW, unix_SQLCopyDesc, - unix_SQLDataSources, - unix_SQLDataSourcesW, unix_SQLDescribeCol, unix_SQLDescribeColW, unix_SQLDescribeParam, unix_SQLDisconnect, unix_SQLDriverConnect, unix_SQLDriverConnectW, - unix_SQLDrivers, - unix_SQLDriversW, unix_SQLEndTran, unix_SQLError, unix_SQLErrorW, @@ -189,9 +185,15 @@ struct param_binding
struct handle { + /* handles */ UINT64 unix_handle; + /* drivers and data sources */ UINT32 drivers_idx; void *drivers_key; + UINT32 sources_idx; + void *sources_key; + BOOL sources_system; + /* parameter bindings */ struct param_binding bind_col; struct param_binding bind_parameter; UINT32 row_count; /* number of rows returned by SQLFetch() */ @@ -412,30 +414,6 @@ struct SQLCopyDesc_params UINT64 TargetDescHandle; };
-struct SQLDataSources_params -{ - UINT64 EnvironmentHandle; - UINT16 Direction; - UCHAR *ServerName; - INT16 BufferLength1; - INT16 *NameLength1; - UCHAR *Description; - INT16 BufferLength2; - INT16 *NameLength2; -}; - -struct SQLDataSourcesW_params -{ - UINT64 EnvironmentHandle; - UINT16 Direction; - WCHAR *ServerName; - INT16 BufferLength1; - INT16 *NameLength1; - WCHAR *Description; - INT16 BufferLength2; - INT16 *NameLength2; -}; - struct SQLDescribeCol_params { UINT64 StatementHandle; @@ -501,30 +479,6 @@ struct SQLDriverConnectW_params UINT16 DriverCompletion; };
-struct SQLDrivers_params -{ - UINT64 EnvironmentHandle; - UINT16 Direction; - UCHAR *DriverDescription; - INT16 BufferLength1; - INT16 *DescriptionLength; - UCHAR *DriverAttributes; - INT16 BufferLength2; - INT16 *AttributesLength; -}; - -struct SQLDriversW_params -{ - UINT64 EnvironmentHandle; - UINT16 Direction; - WCHAR *DriverDescription; - INT16 BufferLength1; - INT16 *DescriptionLength; - WCHAR *DriverAttributes; - INT16 BufferLength2; - INT16 *AttributesLength; -}; - struct SQLEndTran_params { INT16 HandleType;