static void test_GetDataSource(WCHAR *initstring) { IDataInitialize *datainit = NULL; IDBInitialize *dbinit = NULL; HRESULT hr; trace("Data Source: %s\n", wine_dbgstr_w(initstring)); hr = CoCreateInstance(&CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, &IID_IDataInitialize,(void**)&datainit); ok(hr == S_OK, "got %08x\n", hr); /* a failure to create data source here may indicate provider is simply not present */ hr = IDataInitialize_GetDataSource(datainit, NULL, CLSCTX_INPROC_SERVER, initstring, &IID_IDBInitialize, (IUnknown**)&dbinit); if(SUCCEEDED(hr)) { IDBProperties *props = NULL; hr = IDBInitialize_QueryInterface(dbinit, &IID_IDBProperties, (void**)&props); ok(hr == S_OK, "got %08x\n", hr); if(SUCCEEDED(hr)) { ULONG cnt; DBPROPINFOSET *pInfoset; OLECHAR *ary; hr = IDBProperties_GetPropertyInfo(props, 0, NULL, &cnt, &pInfoset, &ary); todo_wine ok(hr == S_OK, "got %08x\n", hr); if(hr == S_OK) { ULONG i; for(i =0; i < pInfoset->cPropertyInfos; i++) { trace("(0x%04x) '%s' %d\n", pInfoset->rgPropertyInfos[i].dwPropertyID, wine_dbgstr_w(pInfoset->rgPropertyInfos[i].pwszDescription), pInfoset->rgPropertyInfos[i].vtType); } CoTaskMemFree(ary); } IDBProperties_Release(props); } IDBInitialize_Release(dbinit); } IDataInitialize_Release(datainit); }
static HRESULT WINAPI datainit_GetInitializationString(IDataInitialize *iface, IUnknown *datasource, boolean include_pass, LPWSTR *init_string) { static const WCHAR provW[] = {'P','r','o','v','i','d','e','r','=',0}; static const WCHAR colW[] = {';',0}; datainit *This = impl_from_IDataInitialize(iface); DBPROPINFOSET *propinfoset; IDBProperties *props; DBPROPIDSET propidset; ULONG count, infocount; WCHAR *progid, *desc; DBPROPSET *propset; IPersist *persist; HRESULT hr; CLSID clsid; int i, len; TRACE("(%p)->(%p %d %p)\n", This, datasource, include_pass, init_string); /* IPersist support is mandatory for data sources */ hr = IUnknown_QueryInterface(datasource, &IID_IPersist, (void**)&persist); if (FAILED(hr)) return hr; memset(&clsid, 0, sizeof(clsid)); hr = IPersist_GetClassID(persist, &clsid); IPersist_Release(persist); if (FAILED(hr)) return hr; progid = NULL; ProgIDFromCLSID(&clsid, &progid); TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid), debugstr_w(progid)); /* now get initialization properties */ hr = IUnknown_QueryInterface(datasource, &IID_IDBProperties, (void**)&props); if (FAILED(hr)) { WARN("IDBProperties not supported\n"); CoTaskMemFree(progid); return hr; } propidset.rgPropertyIDs = NULL; propidset.cPropertyIDs = 0; propidset.guidPropertySet = DBPROPSET_DBINIT; propset = NULL; count = 0; hr = IDBProperties_GetProperties(props, 1, &propidset, &count, &propset); if (FAILED(hr)) { WARN("failed to get data source properties, 0x%08x\n", hr); CoTaskMemFree(progid); return hr; } infocount = 0; IDBProperties_GetPropertyInfo(props, 1, &propidset, &infocount, &propinfoset, &desc); IDBProperties_Release(props); /* check if we need to skip password */ len = strlenW(progid) + strlenW(provW) + 1; /* including ';' */ for (i = 0; i < count; i++) { WCHAR *descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset); if (descr) { /* include '=' and ';' */ len += strlenW(descr) + 2; len += get_propvalue_length(&propset->rgProperties[i]); } if ((propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO) && (V_BOOL(&propset->rgProperties[i].vValue) == VARIANT_FALSE)) include_pass = FALSE; } len *= sizeof(WCHAR); *init_string = CoTaskMemAlloc(len); *init_string[0] = 0; /* provider name */ strcatW(*init_string, provW); strcatW(*init_string, progid); strcatW(*init_string, colW); CoTaskMemFree(progid); for (i = 0; i < count; i++) { WCHAR *descr; if (!include_pass && propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PASSWORD) continue; descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset); if (descr) { static const WCHAR eqW[] = {'=',0}; strcatW(*init_string, descr); strcatW(*init_string, eqW); write_propvalue_str(*init_string, &propset->rgProperties[i]); strcatW(*init_string, colW); } } free_dbpropset(count, propset); free_dbpropinfoset(infocount, propinfoset); CoTaskMemFree(desc); if (!include_pass) TRACE("%s\n", debugstr_w(*init_string)); return S_OK; }