[PATCH 4/5] msdasql: Implement ICommandText GetDBSession

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Sun Oct 31 03:51:17 CDT 2021


Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
 dlls/msdasql/session.c        | 19 +++++++++++++++++--
 dlls/msdasql/tests/provider.c | 17 +++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/dlls/msdasql/session.c b/dlls/msdasql/session.c
index c0deb32d8ad..8b96620cc41 100644
--- a/dlls/msdasql/session.c
+++ b/dlls/msdasql/session.c
@@ -285,6 +285,7 @@ struct command
     ICommandPrepare ICommandPrepare_iface;
     LONG refs;
     WCHAR *query;
+    IUnknown *session;
 };
 
 static inline struct command *impl_from_ICommandText( ICommandText *iface )
@@ -393,6 +394,8 @@ static ULONG WINAPI command_Release(ICommandText *iface)
     if (!refs)
     {
         TRACE( "destroying %p\n", command );
+        if (command->session)
+            IUnknown_Release(command->session);
         heap_free( command->query );
         heap_free( command );
     }
@@ -417,8 +420,18 @@ static HRESULT WINAPI command_Execute(ICommandText *iface, IUnknown *outer, REFI
 static HRESULT WINAPI command_GetDBSession(ICommandText *iface, REFIID riid, IUnknown **session)
 {
     struct command *command = impl_from_ICommandText( iface );
-    FIXME("%p, %s, %p\n", command, debugstr_guid(riid), session);
-    return E_NOTIMPL;
+
+    TRACE("%p, %s, %p\n", command, debugstr_guid(riid), session);
+
+    if (!session)
+        return E_INVALIDARG;
+
+    *session = NULL;
+
+    if (!command->session)
+        return S_FALSE;
+
+    return IUnknown_QueryInterface(command->session, riid, (void**)session);;
 }
 
 static HRESULT WINAPI command_GetCommandText(ICommandText *iface, GUID *dialect, LPOLESTR *commandstr)
@@ -656,6 +669,8 @@ static HRESULT WINAPI createcommand_CreateCommand(IDBCreateCommand *iface, IUnkn
     command->ICommandPrepare_iface.lpVtbl = &commandprepareVtbl;
     command->refs = 1;
 
+    IUnknown_QueryInterface(&session->session_iface, &IID_IUnknown, (void**)&command->session);
+
     hr = ICommandText_QueryInterface(&command->ICommandText_iface, riid, (void**)out);
     ICommandText_Release(&command->ICommandText_iface);
     return hr;
diff --git a/dlls/msdasql/tests/provider.c b/dlls/msdasql/tests/provider.c
index 09a4b69c31d..35dfeb10d3d 100644
--- a/dlls/msdasql/tests/provider.c
+++ b/dlls/msdasql/tests/provider.c
@@ -206,6 +206,22 @@ if (0)
     ICommandText_Release(comand_text);
 }
 
+static void test_command_dbsession(IUnknown *cmd, IUnknown *session)
+{
+    ICommandText *comand_text;
+    HRESULT hr;
+    IUnknown *sess;
+
+    hr = IUnknown_QueryInterface(cmd, &IID_ICommandText, (void**)&comand_text);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = ICommandText_GetDBSession(comand_text, &IID_IUnknown, &sess);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(session == sess, "different session pointers\n");
+
+    ICommandText_Release(comand_text);
+}
+
 static void test_sessions(void)
 {
     IDBProperties *props;
@@ -281,6 +297,7 @@ static void test_sessions(void)
     {
         test_command_interfaces(cmd);
         test_command_text(cmd);
+        test_command_dbsession(cmd, session);
         IUnknown_Release(cmd);
     }
 
-- 
2.33.0




More information about the wine-devel mailing list