[PATCH 3/3] msado15: Implement _Connection Open.

Hans Leidekker hans at codeweavers.com
Wed Oct 21 04:47:14 CDT 2020


From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>

v3: Remove unused define and dsn field, style fixes.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
 dlls/msado15/Makefile.in     |  2 +-
 dlls/msado15/connection.c    | 55 +++++++++++++++++++++++++++++++++---
 dlls/msado15/tests/msado15.c |  4 +--
 3 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/dlls/msado15/Makefile.in b/dlls/msado15/Makefile.in
index 9852e0863dd..e64da605473 100644
--- a/dlls/msado15/Makefile.in
+++ b/dlls/msado15/Makefile.in
@@ -1,5 +1,5 @@
 MODULE    = msado15.dll
-IMPORTS   = oleaut32
+IMPORTS   = oleaut32 ole32
 
 EXTRADLLFLAGS = -mno-cygwin
 
diff --git a/dlls/msado15/connection.c b/dlls/msado15/connection.c
index 3f1a87aa5b3..fd15d5a443f 100644
--- a/dlls/msado15/connection.c
+++ b/dlls/msado15/connection.c
@@ -23,6 +23,7 @@
 #include "initguid.h"
 #include "ocidl.h"
 #include "objbase.h"
+#include "msdasc.h"
 #include "olectl.h"
 #include "msado15_backcompat.h"
 
@@ -56,6 +57,7 @@ struct connection
     WCHAR                    *provider;
     ConnectModeEnum           mode;
     CursorLocationEnum        location;
+    IUnknown                 *session;
     struct connection_point   cp_connev;
 };
 
@@ -98,6 +100,7 @@ static ULONG WINAPI connection_Release( _Connection *iface )
             if (connection->cp_connev.sinks[i])
                 IUnknown_Release( connection->cp_connev.sinks[i] );
         }
+        if (connection->session) IUnknown_Release( connection->session );
         heap_free( connection->cp_connev.sinks );
         heap_free( connection->provider );
         heap_free( connection->datasource );
@@ -240,6 +243,12 @@ static HRESULT WINAPI connection_Close( _Connection *iface )
 
     if (connection->state == adStateClosed) return MAKE_ADO_HRESULT( adErrObjectClosed );
 
+    if (connection->session)
+    {
+        IUnknown_Release( connection->session );
+        connection->session = NULL;
+    }
+
     connection->state = adStateClosed;
     return S_OK;
 }
@@ -273,13 +282,50 @@ static HRESULT WINAPI connection_Open( _Connection *iface, BSTR connect_str, BST
                                        LONG options )
 {
     struct connection *connection = impl_from_Connection( iface );
-    FIXME( "%p, %s, %s, %p, %08x\n", iface, debugstr_w(connect_str), debugstr_w(userid),
-           password, options );
+    IDBProperties *props;
+    IDBInitialize *dbinit = NULL;
+    IDataInitialize *datainit;
+    IDBCreateSession *session = NULL;
+    HRESULT hr;
+
+    TRACE( "%p, %s, %s, %p, %08x\n", iface, debugstr_w(connect_str), debugstr_w(userid), password, options );
 
     if (connection->state == adStateOpen) return MAKE_ADO_HRESULT( adErrObjectOpen );
+    if (!connect_str) return E_FAIL;
 
-    connection->state = adStateOpen;
-    return S_OK;
+    if ((hr = CoCreateInstance( &CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,
+                                (void **)&datainit )) != S_OK) return hr;
+    if ((hr = IDataInitialize_GetDataSource( datainit, NULL, CLSCTX_INPROC_SERVER, connect_str, &IID_IDBInitialize,
+                                             (IUnknown **)&dbinit )) != S_OK) goto done;
+    if ((hr = IDBInitialize_QueryInterface( dbinit, &IID_IDBProperties, (void **)&props )) != S_OK) goto done;
+
+    /* TODO - Update username/password if required. */
+    if ((userid && *userid) || (password && *password))
+        FIXME("Username/password parameters currently not supported\n");
+
+    if ((hr = IDBInitialize_Initialize( dbinit )) != S_OK) goto done;
+    if ((hr = IDBInitialize_QueryInterface( dbinit, &IID_IDBCreateSession, (void **)&session )) != S_OK) goto done;
+    if ((hr = IDBCreateSession_CreateSession( session, NULL, &IID_IUnknown, &connection->session )) == S_OK)
+    {
+        connection->state = adStateOpen;
+    }
+    IDBCreateSession_Release( session );
+
+done:
+    if (hr != S_OK && connection->session)
+    {
+        IUnknown_Release( connection->session );
+        connection->session = NULL;
+    }
+    if (dbinit)
+    {
+        IDBInitialize_Uninitialize( dbinit );
+        IDBInitialize_Release( dbinit );
+    }
+    IDataInitialize_Release( datainit );
+
+    TRACE("ret 0x%08x\n", hr);
+    return hr;
 }
 
 static HRESULT WINAPI connection_get_Errors( _Connection *iface, Errors **obj )
@@ -688,6 +734,7 @@ HRESULT Connection_create( void **obj )
     }
     connection->mode = adModeUnknown;
     connection->location = adUseServer;
+    connection->session = NULL;
 
     connection->cp_connev.conn = connection;
     connection->cp_connev.riid = &DIID_ConnectionEvents;
diff --git a/dlls/msado15/tests/msado15.c b/dlls/msado15/tests/msado15.c
index 378c2eb918c..adf9fb30bc2 100644
--- a/dlls/msado15/tests/msado15.c
+++ b/dlls/msado15/tests/msado15.c
@@ -808,12 +808,12 @@ if (0) /* Crashes on windows */
     ok(!wcscmp(str, str2), "wrong string %s\n", wine_dbgstr_w(str2));
 
     hr = _Connection_Open(connection, NULL, NULL, NULL, 0);
-    todo_wine ok(hr == E_FAIL, "Failed, hr 0x%08x\n", hr);
+    ok(hr == E_FAIL, "Failed, hr 0x%08x\n", hr);
 
     /* Open adds trailing ; if it's missing */
     str3 = SysAllocString(L"Provider=MSDASQL.1;Persist Security Info=False;Data Source=wine_test;");
     hr = _Connection_Open(connection, NULL, NULL, NULL, adConnectUnspecified);
-    todo_wine ok(hr == E_FAIL, "Failed, hr 0x%08x\n", hr);
+    ok(hr == E_FAIL, "Failed, hr 0x%08x\n", hr);
 
     str2 = NULL;
     hr = _Connection_get_ConnectionString(connection, &str2);
-- 
2.20.1




More information about the wine-devel mailing list