From 23d264d3279949d9b238dedbfd494cd8eebdb5d2 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Wed, 3 Nov 2021 16:37:09 +1100 Subject: [PATCH] msdasql: Support CLSID_MSDASQL_ENUMERATOR interface. Signed-off-by: Alistair Leslie-Hughes Signed-off-by: Alexandre Julliard --- dlls/msdasql/msdasql_main.c | 112 ++++++++++++++++++++++++++++++++++ dlls/oledb32/tests/database.c | 2 +- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/dlls/msdasql/msdasql_main.c b/dlls/msdasql/msdasql_main.c index a2d40e14b96..ff16413004e 100644 --- a/dlls/msdasql/msdasql_main.c +++ b/dlls/msdasql/msdasql_main.c @@ -72,6 +72,7 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) } static HRESULT create_msdasql_provider(REFIID riid, void **ppv); +static HRESULT create_msdasql_enumerator(REFIID riid, void **ppv); HRESULT WINAPI msdasql_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv) { @@ -94,7 +95,24 @@ static const IClassFactoryVtbl cfmsdasqlVtbl = { ClassFactory_LockServer }; +HRESULT WINAPI enumerationcf_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv) +{ + TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv); + + return create_msdasql_enumerator(riid, ppv); +} + +static const IClassFactoryVtbl enumfactoryVtbl = +{ + ClassFactory_QueryInterface, + ClassFactory_AddRef, + ClassFactory_Release, + enumerationcf_CreateInstance, + ClassFactory_LockServer +}; + static IClassFactory cfmsdasql = { &cfmsdasqlVtbl }; +static IClassFactory enumfactory = { &enumfactoryVtbl }; HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv ) { @@ -102,6 +120,8 @@ HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv ) if (IsEqualGUID(&CLSID_MSDASQL, rclsid)) return IClassFactory_QueryInterface(&cfmsdasql, riid, ppv); + else if (IsEqualGUID(&CLSID_MSDASQL_ENUMERATOR, rclsid)) + return IClassFactory_QueryInterface(&enumfactory, riid, ppv); return CLASS_E_CLASSNOTAVAILABLE; } @@ -526,3 +546,95 @@ static HRESULT create_msdasql_provider(REFIID riid, void **ppv) IUnknown_Release(&provider->MSDASQL_iface); return hr; } + +struct msdasql_enum +{ + ISourcesRowset ISourcesRowset_iface; + LONG ref; +}; + +static inline struct msdasql_enum *msdasql_enum_from_ISourcesRowset(ISourcesRowset *iface) +{ + return CONTAINING_RECORD(iface, struct msdasql_enum, ISourcesRowset_iface); +} + +static HRESULT WINAPI msdasql_enum_QueryInterface(ISourcesRowset *iface, REFIID riid, void **out) +{ + struct msdasql_enum *enumerator = msdasql_enum_from_ISourcesRowset(iface); + + TRACE("(%p)->(%s %p)\n", enumerator, debugstr_guid(riid), out); + + if(IsEqualGUID(riid, &IID_IUnknown) || + IsEqualGUID(riid, &IID_ISourcesRowset ) ) + { + *out = &enumerator->ISourcesRowset_iface; + } + else + { + FIXME("(%s, %p)\n", debugstr_guid(riid), out); + *out = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown*)*out); + return S_OK; +} + +static ULONG WINAPI msdasql_enum_AddRef(ISourcesRowset *iface) +{ + struct msdasql_enum *enumerator = msdasql_enum_from_ISourcesRowset(iface); + ULONG ref = InterlockedIncrement(&enumerator->ref); + + TRACE("(%p) ref=%u\n", enumerator, ref); + + return ref; +} + +static ULONG WINAPI msdasql_enum_Release(ISourcesRowset *iface) +{ + struct msdasql_enum *enumerator = msdasql_enum_from_ISourcesRowset(iface); + ULONG ref = InterlockedDecrement(&enumerator->ref); + + TRACE("(%p) ref=%u\n", enumerator, ref); + + if (!ref) + { + free(enumerator); + } + + return ref; +} + +static HRESULT WINAPI msdasql_enum_GetSourcesRowset(ISourcesRowset *iface, IUnknown *outer, REFIID riid, ULONG sets, + DBPROPSET properties[], IUnknown **rowset) +{ + struct msdasql_enum *enumerator = msdasql_enum_from_ISourcesRowset(iface); + FIXME("(%p) %p, %s, %d, %p, %p\n", enumerator, outer, debugstr_guid(riid), sets, properties, rowset); + + return E_NOTIMPL; +} + +static const ISourcesRowsetVtbl msdsqlenum_vtbl = +{ + msdasql_enum_QueryInterface, + msdasql_enum_AddRef, + msdasql_enum_Release, + msdasql_enum_GetSourcesRowset +}; + +static HRESULT create_msdasql_enumerator(REFIID riid, void **ppv) +{ + struct msdasql_enum *enumerator; + HRESULT hr; + + enumerator = malloc(sizeof(*enumerator)); + if (!enumerator) + return E_OUTOFMEMORY; + + enumerator->ISourcesRowset_iface.lpVtbl = &msdsqlenum_vtbl; + enumerator->ref = 1; + + hr = IUnknown_QueryInterface(&enumerator->ISourcesRowset_iface, riid, ppv); + IUnknown_Release(&enumerator->ISourcesRowset_iface); + return hr; +} diff --git a/dlls/oledb32/tests/database.c b/dlls/oledb32/tests/database.c index 775da0f7b61..7fdc3df4176 100644 --- a/dlls/oledb32/tests/database.c +++ b/dlls/oledb32/tests/database.c @@ -1066,7 +1066,7 @@ static void test_odbc_enumerator(void) IRowset *rowset; hr = CoCreateInstance( &CLSID_MSDASQL_ENUMERATOR, NULL, CLSCTX_ALL, &IID_ISourcesRowset, (void **)&source); - todo_wine ok(hr == S_OK, "Failed to create object 0x%08x\n", hr); + ok(hr == S_OK, "Failed to create object 0x%08x\n", hr); if (FAILED(hr)) { return;