[PATCH 3/5] msdasql: Implement ICommandText Get/Set CommandText

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


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

diff --git a/dlls/msdasql/msdasql_main.c b/dlls/msdasql/msdasql_main.c
index 79feacb83aa..a2d40e14b96 100644
--- a/dlls/msdasql/msdasql_main.c
+++ b/dlls/msdasql/msdasql_main.c
@@ -36,6 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msdasql);
 
 DEFINE_GUID(DBPROPSET_DBINIT,    0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
 
+DEFINE_GUID(DBGUID_DEFAULT,      0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
+
 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
diff --git a/dlls/msdasql/session.c b/dlls/msdasql/session.c
index da148fd7ca6..c0deb32d8ad 100644
--- a/dlls/msdasql/session.c
+++ b/dlls/msdasql/session.c
@@ -29,6 +29,7 @@
 #include "wine/debug.h"
 
 #include "msdasql.h"
+#include "oledberr.h"
 
 #include "msdasql_private.h"
 
@@ -283,6 +284,7 @@ struct command
     IConvertType IConvertType_iface;
     ICommandPrepare ICommandPrepare_iface;
     LONG refs;
+    WCHAR *query;
 };
 
 static inline struct command *impl_from_ICommandText( ICommandText *iface )
@@ -391,6 +393,7 @@ static ULONG WINAPI command_Release(ICommandText *iface)
     if (!refs)
     {
         TRACE( "destroying %p\n", command );
+        heap_free( command->query );
         heap_free( command );
     }
     return refs;
@@ -421,14 +424,40 @@ static HRESULT WINAPI command_GetDBSession(ICommandText *iface, REFIID riid, IUn
 static HRESULT WINAPI command_GetCommandText(ICommandText *iface, GUID *dialect, LPOLESTR *commandstr)
 {
     struct command *command = impl_from_ICommandText( iface );
-    FIXME("%p, %p, %p\n", command, dialect, commandstr);
-    return E_NOTIMPL;
+    HRESULT hr = S_OK;
+    TRACE("%p, %p, %p\n", command, dialect, commandstr);
+
+    if (!command->query)
+        return DB_E_NOCOMMAND;
+
+    if (IsEqualGUID(&DBGUID_DEFAULT, dialect))
+        hr = DB_S_DIALECTIGNORED;
+
+    *commandstr = heap_alloc((lstrlenW(command->query)+1)*sizeof(WCHAR));
+    wcscpy(*commandstr, command->query);
+    return hr;
 }
 
 static HRESULT WINAPI command_SetCommandText(ICommandText *iface, REFGUID dialect, LPCOLESTR commandstr)
 {
     struct command *command = impl_from_ICommandText( iface );
-    FIXME("%p, %s, %s\n", command, debugstr_guid(dialect), debugstr_w(commandstr));
+    TRACE("%p, %s, %s\n", command, debugstr_guid(dialect), debugstr_w(commandstr));
+
+    if (IsEqualGUID(&DBGUID_DEFAULT, dialect))
+        FIXME("Currently non Default Dialect isn't supported\n");
+
+    heap_free(command->query);
+
+    if (commandstr)
+    {
+        command->query = heap_alloc((lstrlenW(commandstr)+1)*sizeof(WCHAR));
+        if (!command->query)
+            return E_OUTOFMEMORY;
+
+        wcscpy(command->query, commandstr);
+    }
+    else
+        command->query = NULL;
     return S_OK;
 }
 
diff --git a/dlls/msdasql/tests/provider.c b/dlls/msdasql/tests/provider.c
index bb624bd9848..09a4b69c31d 100644
--- a/dlls/msdasql/tests/provider.c
+++ b/dlls/msdasql/tests/provider.c
@@ -27,12 +27,15 @@
 #include "initguid.h"
 
 #include "msdasql.h"
+#include "oledberr.h"
 
 #include "wine/test.h"
 
 DEFINE_GUID(DBPROPSET_DBINITALL, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
 DEFINE_GUID(DBPROPSET_DBINIT,    0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
 
+DEFINE_GUID(DBGUID_DEFAULT,      0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
+
 static BOOL db_created;
 static char mdbpath[MAX_PATH];
 
@@ -157,6 +160,52 @@ static void test_command_interfaces(IUnknown *cmd)
     ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
 }
 
+static void test_command_text(IUnknown *cmd)
+{
+    ICommandText *comand_text;
+    HRESULT hr;
+    OLECHAR *str;
+    GUID dialect;
+
+    hr = IUnknown_QueryInterface(cmd, &IID_ICommandText, (void**)&comand_text);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = ICommandText_GetCommandText(comand_text, &dialect, &str);
+    ok(hr == DB_E_NOCOMMAND, "got 0x%08x\n", hr);
+
+if (0)
+{
+    /* Crashes under windows */
+    hr = ICommandText_SetCommandText(comand_text, NULL, L"select * from testing");
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+}
+
+    hr = ICommandText_SetCommandText(comand_text, &DBGUID_DEFAULT, NULL);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    hr = ICommandText_GetCommandText(comand_text, &dialect, &str);
+    ok(hr == DB_E_NOCOMMAND, "got 0x%08x\n", hr);
+
+    hr = ICommandText_SetCommandText(comand_text, &DBGUID_DEFAULT, L"select * from testing");
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    /* dialect empty value */
+    hr = ICommandText_GetCommandText(comand_text, &dialect, &str);
+    ok(hr == DB_S_DIALECTIGNORED, "got 0x%08x\n", hr);
+    ok(IsEqualGUID(&DBGUID_DEFAULT, &dialect), "got %s\n", debugstr_guid(&dialect));
+    ok (!lstrcmpW(L"select * from testing", str), "got %s\n", debugstr_w(str));
+    HeapFree(GetProcessHeap(), 0, str);
+
+    dialect = DBGUID_DEFAULT;
+    hr = ICommandText_GetCommandText(comand_text, &dialect, &str);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(IsEqualGUID(&DBGUID_DEFAULT, &dialect), "got %s\n", debugstr_guid(&dialect));
+    ok (!lstrcmpW(L"select * from testing", str), "got %s\n", debugstr_w(str));
+    HeapFree(GetProcessHeap(), 0, str);
+
+    ICommandText_Release(comand_text);
+}
+
 static void test_sessions(void)
 {
     IDBProperties *props;
@@ -231,6 +280,7 @@ static void test_sessions(void)
     if (hr == S_OK)
     {
         test_command_interfaces(cmd);
+        test_command_text(cmd);
         IUnknown_Release(cmd);
     }
 
-- 
2.33.0




More information about the wine-devel mailing list