From: Hans Leidekker hans@codeweavers.com
--- dlls/odbc32/proxyodbc.c | 98 ++++++++++++++++++++++++++++++++++++-- dlls/odbc32/tests/odbc32.c | 30 ++++++++++++ dlls/odbc32/unixlib.h | 1 + 3 files changed, 126 insertions(+), 3 deletions(-)
diff --git a/dlls/odbc32/proxyodbc.c b/dlls/odbc32/proxyodbc.c index 57930e59ad4..1e2bd0db2f6 100644 --- a/dlls/odbc32/proxyodbc.c +++ b/dlls/odbc32/proxyodbc.c @@ -824,6 +824,30 @@ static SQLRETURN prepare_env( struct handle *handle ) return SQL_SUCCESS; }
+static SQLRETURN set_con_attr( struct handle *handle, SQLINTEGER attr, SQLPOINTER value, SQLINTEGER len ) +{ + SQLRETURN ret = SQL_ERROR; + + if (handle->unix_handle) + { + struct SQLSetConnectAttr_params params = { handle->unix_handle, attr, value, len }; + ret = ODBC_CALL( SQLSetConnectAttr, ¶ms ); + } + else if (handle->win32_handle) + { + ret = handle->win32_funcs->SQLSetConnectAttr( handle->win32_handle, attr, value, len ); + } + return ret; +} + +static SQLRETURN prepare_con( struct handle *handle ) +{ + SQLRETURN ret; + if ((ret = set_con_attr( handle, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)(ULONG_PTR)handle->con_attr_login_timeout, 0 ))) + return ret; + return SQL_SUCCESS; +} + /************************************************************************* * SQLConnect [ODBC32.007] */ @@ -865,6 +889,7 @@ SQLRETURN WINAPI SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSM handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLConnect( handle->win32_handle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3 ); @@ -882,6 +907,7 @@ SQLRETURN WINAPI SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSM
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params_connect.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLConnect, ¶ms_connect ); @@ -1430,7 +1456,7 @@ SQLRETURN WINAPI SQLGetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribut SQLINTEGER BufferLength, SQLINTEGER *StringLength) { struct handle *handle = ConnectionHandle; - SQLRETURN ret = SQL_ERROR; + SQLRETURN ret = SQL_SUCCESS;
TRACE("(ConnectionHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", ConnectionHandle, Attribute, Value, BufferLength, StringLength); @@ -1448,6 +1474,20 @@ SQLRETURN WINAPI SQLGetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribut ret = handle->win32_funcs->SQLGetConnectAttr( handle->win32_handle, Attribute, Value, BufferLength, StringLength ); } + else + { + switch (Attribute) + { + case SQL_ATTR_LOGIN_TIMEOUT: + *(SQLINTEGER *)Value = handle->con_attr_login_timeout; + break; + + default: + FIXME( "unhandled attribute %d\n", Attribute ); + ret = SQL_ERROR; + break; + } + }
TRACE("Returning %d\n", ret); return ret; @@ -1990,7 +2030,7 @@ SQLRETURN WINAPI SQLSetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribut SQLINTEGER StringLength) { struct handle *handle = ConnectionHandle; - SQLRETURN ret = SQL_ERROR; + SQLRETURN ret = SQL_SUCCESS;
TRACE("(ConnectionHandle %p, Attribute %d, Value %p, StringLength %d)\n", ConnectionHandle, Attribute, Value, StringLength); @@ -2006,6 +2046,20 @@ SQLRETURN WINAPI SQLSetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribut { ret = handle->win32_funcs->SQLSetConnectAttr( handle->win32_handle, Attribute, Value, StringLength ); } + else + { + switch (Attribute) + { + case SQL_ATTR_LOGIN_TIMEOUT: + handle->con_attr_login_timeout = (UINT32)(ULONG_PTR)Value; + break; + + default: + FIXME( "unhandled attribute %d\n", Attribute ); + ret = SQL_ERROR; + break; + } + }
TRACE("Returning %d\n", ret); return ret; @@ -2523,6 +2577,7 @@ SQLRETURN WINAPI SQLBrowseConnect(SQLHDBC ConnectionHandle, SQLCHAR *InConnectio handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLBrowseConnect( handle->win32_handle, InConnectionString, StringLength1, OutConnectionString, BufferLength, StringLength2 ); @@ -2540,6 +2595,7 @@ SQLRETURN WINAPI SQLBrowseConnect(SQLHDBC ConnectionHandle, SQLCHAR *InConnectio
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLBrowseConnect, ¶ms ); @@ -3194,6 +3250,7 @@ SQLRETURN WINAPI SQLDriverConnect(SQLHDBC ConnectionHandle, SQLHWND WindowHandle handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLDriverConnect( handle->win32_handle, WindowHandle, InConnectionString, Length, OutConnectionString, BufferLength, Length2, DriverCompletion ); @@ -3211,6 +3268,7 @@ SQLRETURN WINAPI SQLDriverConnect(SQLHDBC ConnectionHandle, SQLHWND WindowHandle
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLDriverConnect, ¶ms ); @@ -3361,6 +3419,7 @@ SQLRETURN WINAPI SQLConnectW(SQLHDBC ConnectionHandle, WCHAR *ServerName, SQLSMA handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLConnectW( handle->win32_handle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3 ); @@ -3378,6 +3437,7 @@ SQLRETURN WINAPI SQLConnectW(SQLHDBC ConnectionHandle, WCHAR *ServerName, SQLSMA
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params_connect.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLConnectW, ¶ms_connect ); @@ -3624,7 +3684,7 @@ SQLRETURN WINAPI SQLGetConnectAttrW(SQLHDBC ConnectionHandle, SQLINTEGER Attribu SQLINTEGER BufferLength, SQLINTEGER *StringLength) { struct handle *handle = ConnectionHandle; - SQLRETURN ret = SQL_ERROR; + SQLRETURN ret = SQL_SUCCESS;
TRACE("(ConnectionHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", ConnectionHandle, Attribute, Value, BufferLength, StringLength); @@ -3642,6 +3702,20 @@ SQLRETURN WINAPI SQLGetConnectAttrW(SQLHDBC ConnectionHandle, SQLINTEGER Attribu ret = handle->win32_funcs->SQLGetConnectAttrW( handle->win32_handle, Attribute, Value, BufferLength, StringLength ); } + else + { + switch (Attribute) + { + case SQL_ATTR_LOGIN_TIMEOUT: + *(SQLINTEGER *)Value = handle->con_attr_login_timeout; + break; + + default: + FIXME( "unhandled attribute %d\n", Attribute ); + ret = SQL_ERROR; + break; + } + }
TRACE("Returning %d\n", ret); return ret; @@ -3831,6 +3905,20 @@ SQLRETURN WINAPI SQLSetConnectAttrW(SQLHDBC ConnectionHandle, SQLINTEGER Attribu { ret = handle->win32_funcs->SQLSetConnectAttrW( handle->win32_handle, Attribute, Value, StringLength ); } + else + { + switch (Attribute) + { + case SQL_ATTR_LOGIN_TIMEOUT: + handle->con_attr_login_timeout = (UINT32)(ULONG_PTR)Value; + break; + + default: + FIXME( "unhandled attribute %d\n", Attribute ); + ret = SQL_ERROR; + break; + } + }
TRACE("Returning %d\n", ret); return ret; @@ -3915,6 +4003,7 @@ SQLRETURN WINAPI SQLDriverConnectW(SQLHDBC ConnectionHandle, SQLHWND WindowHandl handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLDriverConnectW( handle->win32_handle, WindowHandle, InConnectionString, Length, OutConnectionString, BufferLength, Length2, DriverCompletion ); @@ -3932,6 +4021,7 @@ SQLRETURN WINAPI SQLDriverConnectW(SQLHDBC ConnectionHandle, SQLHWND WindowHandl
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLDriverConnectW, ¶ms ); @@ -4195,6 +4285,7 @@ SQLRETURN WINAPI SQLBrowseConnectW(SQLHDBC ConnectionHandle, SQLWCHAR *InConnect handle->parent->win32_funcs = handle->win32_funcs; if (!SUCCESS((ret = handle->win32_funcs->SQLAllocHandle( SQL_HANDLE_DBC, handle->parent->win32_handle, &handle->win32_handle )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
ret = handle->win32_funcs->SQLBrowseConnectW( handle->win32_handle, InConnectionString, StringLength1, OutConnectionString, BufferLength, StringLength2 ); @@ -4212,6 +4303,7 @@ SQLRETURN WINAPI SQLBrowseConnectW(SQLHDBC ConnectionHandle, SQLWCHAR *InConnect
params_alloc_connect.EnvironmentHandle = handle->parent->unix_handle; if (!SUCCESS((ret = ODBC_CALL( SQLAllocConnect, ¶ms_alloc_connect )))) goto done; + if (!SUCCESS((ret = prepare_con( handle )))) goto done;
params.ConnectionHandle = handle->unix_handle; ret = ODBC_CALL( SQLBrowseConnectW, ¶ms ); diff --git a/dlls/odbc32/tests/odbc32.c b/dlls/odbc32/tests/odbc32.c index 950b86ba036..0288260d3d3 100644 --- a/dlls/odbc32/tests/odbc32.c +++ b/dlls/odbc32/tests/odbc32.c @@ -478,6 +478,35 @@ static void test_SQLSetEnvAttr(void) ok( ret == SQL_SUCCESS, "got %d\n", ret ); }
+static void test_SQLSetConnectAttr(void) +{ + SQLUINTEGER timeout; + SQLHENV env; + SQLHDBC con; + SQLRETURN ret; + + ret = SQLAllocEnv( &env ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); + + ret = SQLAllocConnect( env, &con ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); + + timeout = 10; + ret = SQLSetConnectAttr( con, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)(ULONG_PTR)timeout, sizeof(timeout) ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); + + timeout = 0; + ret = SQLGetConnectAttr( con, SQL_ATTR_LOGIN_TIMEOUT, &timeout, sizeof(timeout), NULL ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); + ok( timeout == 10, "wrong timeout %d\n", timeout ); + + ret = SQLFreeConnect( con ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); + + ret = SQLFreeEnv( env ); + ok( ret == SQL_SUCCESS, "got %d\n", ret ); +} + START_TEST(odbc32) { test_SQLAllocHandle(); @@ -488,4 +517,5 @@ START_TEST(odbc32) test_SQLDrivers(); test_SQLExecDirect(); test_SQLSetEnvAttr(); + test_SQLSetConnectAttr(); } diff --git a/dlls/odbc32/unixlib.h b/dlls/odbc32/unixlib.h index 966ade5ad72..c26317012b5 100644 --- a/dlls/odbc32/unixlib.h +++ b/dlls/odbc32/unixlib.h @@ -192,6 +192,7 @@ struct handle struct handle *parent; /* attributes */ UINT32 env_attr_version; + UINT32 con_attr_login_timeout; /* drivers and data sources */ UINT32 drivers_idx; void *drivers_key;