[PATCH v4] msado15: Implement _Connection get/put ConnectionString

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Mon Jan 27 18:19:08 CST 2020


Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
 dlls/msado15/connection.c    | 31 +++++++++++++++++++++++++++----
 dlls/msado15/tests/msado15.c | 20 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/dlls/msado15/connection.c b/dlls/msado15/connection.c
index 73b225628c..0a1e8de668 100644
--- a/dlls/msado15/connection.c
+++ b/dlls/msado15/connection.c
@@ -37,6 +37,7 @@ struct connection
     LONG              refs;
     ObjectStateEnum   state;
     LONG              timeout;
+    WCHAR             *datasource;
 };
 
 static inline struct connection *impl_from_Connection( _Connection *iface )
@@ -62,6 +63,7 @@ static ULONG WINAPI connection_Release( _Connection *iface )
     if (!refs)
     {
         TRACE( "destroying %p\n", connection );
+        heap_free( connection->datasource );
         heap_free( connection );
     }
     return refs;
@@ -125,14 +127,34 @@ static HRESULT WINAPI connection_get_Properties( _Connection *iface, Properties
 
 static HRESULT WINAPI connection_get_ConnectionString( _Connection *iface, BSTR *str )
 {
-    FIXME( "%p, %p\n", iface, str );
-    return E_NOTIMPL;
+    struct connection *connection = impl_from_Connection( iface );
+
+    TRACE( "%p, %p\n", connection, str );
+
+    *str = SysAllocString( connection->datasource );
+
+    return S_OK;
 }
 
 static HRESULT WINAPI connection_put_ConnectionString( _Connection *iface, BSTR str )
 {
-    FIXME( "%p, %s\n", iface, debugstr_w(str) );
-    return E_NOTIMPL;
+    struct connection *connection = impl_from_Connection( iface );
+
+    TRACE( "%p\n", connection );
+
+    if (str && !wcsstr(str, L"Password"))
+        TRACE( "datasource: %s\n", debugstr_w(str) );
+
+    heap_free( connection->datasource );
+    connection->datasource = NULL;
+    if (str)
+    {
+        connection->datasource = strdupW(str);
+        if (!connection->datasource)
+            return E_OUTOFMEMORY;
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI connection_get_CommandTimeout( _Connection *iface, LONG *timeout )
@@ -392,6 +414,7 @@ HRESULT Connection_create( void **obj )
     connection->refs = 1;
     connection->state = adStateClosed;
     connection->timeout = 30;
+    connection->datasource = NULL;
 
     *obj = &connection->Connection_iface;
     TRACE( "returning iface %p\n", *obj );
diff --git a/dlls/msado15/tests/msado15.c b/dlls/msado15/tests/msado15.c
index 917d131063..de3d6270d5 100644
--- a/dlls/msado15/tests/msado15.c
+++ b/dlls/msado15/tests/msado15.c
@@ -667,6 +667,7 @@ static void test_Connection(void)
     IRunnableObject *runtime;
     ISupportErrorInfo *errorinfo;
     LONG state, timeout;
+    BSTR connect1, connect2;
 
     hr = CoCreateInstance(&CLSID_Connection, NULL, CLSCTX_INPROC_SERVER, &IID__Connection, (void**)&connection);
     ok( hr == S_OK, "got %08x\n", hr );
@@ -702,6 +703,25 @@ if (0)   /* Crashes on windows */
     ok(hr == S_OK, "Failed to get state, hr 0x%08x\n", hr);
     ok(timeout == 300, "Unexpected timeout value %d\n", timeout);
 
+    hr = _Connection_put_ConnectionString(connection, NULL);
+    ok(hr == S_OK, "Failed, hr 0x%08x\n", hr);
+
+    connect1 = SysAllocString(L"Provider=MSDASQL.1;Persist Security Info=False;Data Source=wine_test");
+    hr = _Connection_put_ConnectionString(connection, connect1);
+    ok(hr == S_OK, "Failed, hr 0x%08x\n", hr);
+
+if (0) /* Crashes on windows */
+{
+    hr = _Connection_get_ConnectionString(connection, NULL);
+    ok(hr == E_POINTER, "Failed, hr 0x%08x\n", hr);
+}
+
+    hr = _Connection_get_ConnectionString(connection, &connect2);
+    ok(hr == S_OK, "Failed, hr 0x%08x\n", hr);
+    ok(wcscmp(connect1, connect2) == 0, "wrong string %s\n", wine_dbgstr_w(connect2));
+    SysFreeString(connect1);
+    SysFreeString(connect2);
+
     _Connection_Release(connection);
 }
 
-- 
2.17.1




More information about the wine-devel mailing list