2 * Copyright (C) 2012 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "oledb_private.h"
31 #include "wine/debug.h"
32 #include "wine/list.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(oledb
);
36 DEFINE_GUID(DBGUID_SESSION
, 0xc8b522f5, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
37 DEFINE_GUID(DBGUID_ROWSET
, 0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
38 DEFINE_GUID(DBGUID_ROW
, 0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
39 DEFINE_GUID(DBGUID_STREAM
, 0xc8b522f9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
41 DEFINE_GUID(DBPROPSET_COLUMN
, 0xc8b522b9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
42 DEFINE_GUID(DBPROPSET_DATASOURCE
, 0xc8b522ba, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
43 DEFINE_GUID(DBPROPSET_DATASOURCEINFO
, 0xc8b522bb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
44 DEFINE_GUID(DBPROPSET_DBINIT
, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
45 DEFINE_GUID(DBPROPSET_INDEX
, 0xc8b522bd, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
46 DEFINE_GUID(DBPROPSET_ROWSET
, 0xc8b522be, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
47 DEFINE_GUID(DBPROPSET_TABLE
, 0xc8b522bf, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
48 DEFINE_GUID(DBPROPSET_DATASOURCEALL
, 0xc8b522c0, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
49 DEFINE_GUID(DBPROPSET_DATASOURCEINFOALL
, 0xc8b522c1, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
50 DEFINE_GUID(DBPROPSET_ROWSETALL
, 0xc8b522c2, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
51 DEFINE_GUID(DBPROPSET_SESSION
, 0xc8b522c6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
52 DEFINE_GUID(DBPROPSET_SESSIONALL
, 0xc8b522c7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
53 DEFINE_GUID(DBPROPSET_DBINITALL
, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
54 DEFINE_GUID(DBPROPSET_PROPERTIESINERROR
, 0xc8b522d4, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
56 typedef struct datainit
58 IDataInitialize IDataInitialize_iface
;
63 static inline datainit
*impl_from_IDataInitialize(IDataInitialize
*iface
)
65 return CONTAINING_RECORD(iface
, datainit
, IDataInitialize_iface
);
70 IDBInitialize IDBInitialize_iface
;
71 IDBProperties IDBProperties_iface
;
76 static inline dbinit
*impl_from_IDBInitialize(IDBInitialize
*iface
)
78 return CONTAINING_RECORD(iface
, dbinit
, IDBInitialize_iface
);
81 static inline dbinit
*impl_from_IDBProperties(IDBProperties
*iface
)
83 return CONTAINING_RECORD(iface
, dbinit
, IDBProperties_iface
);
86 static HRESULT WINAPI
dbprops_QueryInterface(IDBProperties
*iface
, REFIID riid
, void **ppvObject
)
88 dbinit
*This
= impl_from_IDBProperties(iface
);
90 return IDBInitialize_QueryInterface(&This
->IDBInitialize_iface
, riid
, ppvObject
);
93 static ULONG WINAPI
dbprops_AddRef(IDBProperties
*iface
)
95 dbinit
*This
= impl_from_IDBProperties(iface
);
97 return IDBInitialize_AddRef(&This
->IDBInitialize_iface
);
100 static ULONG WINAPI
dbprops_Release(IDBProperties
*iface
)
102 dbinit
*This
= impl_from_IDBProperties(iface
);
104 return IDBInitialize_Release(&This
->IDBInitialize_iface
);
107 static HRESULT WINAPI
dbprops_GetProperties(IDBProperties
*iface
, ULONG cPropertyIDSets
,
108 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertySets
, DBPROPSET
**prgPropertySets
)
110 dbinit
*This
= impl_from_IDBProperties(iface
);
112 FIXME("(%p)->(%ld %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertySets
, prgPropertySets
);
117 static HRESULT WINAPI
dbprops_GetPropertyInfo(IDBProperties
*iface
, ULONG cPropertyIDSets
,
118 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertyInfoSets
,
119 DBPROPINFOSET
**prgPropertyInfoSets
, OLECHAR
**ppDescBuffer
)
121 dbinit
*This
= impl_from_IDBProperties(iface
);
123 FIXME("(%p)->(%ld %p %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertyInfoSets
,
124 prgPropertyInfoSets
, ppDescBuffer
);
129 static HRESULT WINAPI
dbprops_SetProperties(IDBProperties
*iface
, ULONG cPropertySets
,
130 DBPROPSET rgPropertySets
[])
132 dbinit
*This
= impl_from_IDBProperties(iface
);
134 FIXME("(%p)->(%ld %p)\n", This
, cPropertySets
, rgPropertySets
);
139 static const struct IDBPropertiesVtbl dbprops_vtbl
=
141 dbprops_QueryInterface
,
144 dbprops_GetProperties
,
145 dbprops_GetPropertyInfo
,
146 dbprops_SetProperties
149 static HRESULT WINAPI
dbinit_QueryInterface(IDBInitialize
*iface
, REFIID riid
, void **obj
)
151 dbinit
*This
= impl_from_IDBInitialize(iface
);
152 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
156 if(IsEqualIID(riid
, &IID_IUnknown
) ||
157 IsEqualIID(riid
, &IID_IDBInitialize
))
161 else if(IsEqualIID(riid
, &IID_IDBProperties
))
163 *obj
= &This
->IDBProperties_iface
;
167 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
168 return E_NOINTERFACE
;
171 IDBInitialize_AddRef(iface
);
175 static ULONG WINAPI
dbinit_AddRef(IDBInitialize
*iface
)
177 dbinit
*This
= impl_from_IDBInitialize(iface
);
178 TRACE("(%p)\n", This
);
180 return InterlockedIncrement(&This
->ref
);
183 static ULONG WINAPI
dbinit_Release(IDBInitialize
*iface
)
185 dbinit
*This
= impl_from_IDBInitialize(iface
);
188 TRACE("(%p)\n", This
);
190 ref
= InterlockedDecrement(&This
->ref
);
197 static HRESULT WINAPI
dbinit_Initialize(IDBInitialize
*iface
)
199 dbinit
*This
= impl_from_IDBInitialize(iface
);
201 FIXME("(%p) stub\n", This
);
206 static HRESULT WINAPI
dbinit_Uninitialize(IDBInitialize
*iface
)
208 dbinit
*This
= impl_from_IDBInitialize(iface
);
210 FIXME("(%p) stub\n", This
);
215 static const IDBInitializeVtbl dbinit_vtbl
=
217 dbinit_QueryInterface
,
224 static HRESULT
create_db_init(IUnknown
**obj
)
232 This
= malloc(sizeof(*This
));
233 if(!This
) return E_OUTOFMEMORY
;
235 This
->IDBInitialize_iface
.lpVtbl
= &dbinit_vtbl
;
236 This
->IDBProperties_iface
.lpVtbl
= &dbprops_vtbl
;
239 *obj
= (IUnknown
*)&This
->IDBInitialize_iface
;
244 static HRESULT WINAPI
datainit_QueryInterface(IDataInitialize
*iface
, REFIID riid
, void **obj
)
246 datainit
*This
= impl_from_IDataInitialize(iface
);
247 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
251 if(IsEqualIID(riid
, &IID_IUnknown
) ||
252 IsEqualIID(riid
, &IID_IDataInitialize
))
254 *obj
= &This
->IDataInitialize_iface
;
258 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
259 return E_NOINTERFACE
;
262 IDataInitialize_AddRef(iface
);
266 static ULONG WINAPI
datainit_AddRef(IDataInitialize
*iface
)
268 datainit
*This
= impl_from_IDataInitialize(iface
);
269 TRACE("(%p)\n", This
);
271 return InterlockedIncrement(&This
->ref
);
274 static ULONG WINAPI
datainit_Release(IDataInitialize
*iface
)
276 datainit
*This
= impl_from_IDataInitialize(iface
);
279 TRACE("(%p)\n", This
);
281 ref
= InterlockedDecrement(&This
->ref
);
288 static void free_dbpropset(ULONG count
, DBPROPSET
*propset
)
292 for (i
= 0; i
< count
; i
++)
296 for (p
= 0; p
< propset
[i
].cProperties
; p
++)
297 VariantClear(&propset
[i
].rgProperties
[p
].vValue
);
299 CoTaskMemFree(propset
[i
].rgProperties
);
301 CoTaskMemFree(propset
);
307 DBPROPOPTIONS options
;
309 HRESULT (*convert_dbproperty
)(const WCHAR
*src
, VARIANT
*dest
);
318 static int __cdecl
dbmodeprop_compare(const void *a
, const void *b
)
320 const WCHAR
*src
= a
;
321 const struct mode_propval
*propval
= b
;
322 return wcsicmp(src
, propval
->name
);
325 static HRESULT
convert_dbproperty_mode(const WCHAR
*src
, VARIANT
*dest
)
327 static const struct mode_propval mode_propvals
[] =
329 { L
"Read", DB_MODE_READ
},
330 { L
"ReadWrite", DB_MODE_READWRITE
},
331 { L
"Share Deny None", DB_MODE_SHARE_DENY_NONE
},
332 { L
"Share Deny Read", DB_MODE_SHARE_DENY_READ
},
333 { L
"Share Deny Write", DB_MODE_SHARE_DENY_WRITE
},
334 { L
"Share Exclusive", DB_MODE_SHARE_EXCLUSIVE
},
335 { L
"Write", DB_MODE_WRITE
},
337 struct mode_propval
*prop
;
339 if ((prop
= bsearch(src
, mode_propvals
, ARRAY_SIZE(mode_propvals
),
340 sizeof(struct mode_propval
), dbmodeprop_compare
)))
343 V_I4(dest
) = prop
->value
;
344 TRACE("%s = %#lx\n", debugstr_w(src
), prop
->value
);
351 static const struct dbproperty dbproperties
[] =
353 { L
"Asynchronous Processing", DBPROP_INIT_ASYNCH
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
354 { L
"Bind Flags", DBPROP_INIT_BINDFLAGS
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
355 { L
"Cache Authentication", DBPROP_AUTH_CACHE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
356 { L
"Connect Timeout", DBPROP_INIT_TIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
357 { L
"Data Source", DBPROP_INIT_DATASOURCE
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
358 { L
"Extended Properties", DBPROP_INIT_PROVIDERSTRING
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
359 { L
"Encrypt Password", DBPROP_AUTH_ENCRYPT_PASSWORD
, DBPROPOPTIONS_REQUIRED
, VT_BOOL
},
360 { L
"General Timeout", DBPROP_INIT_GENERALTIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
361 { L
"Impersonation Level", DBPROP_INIT_IMPERSONATION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
362 { L
"Initial Catalog", DBPROP_INIT_CATALOG
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
363 { L
"Integrated Security", DBPROP_AUTH_INTEGRATED
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
364 { L
"Locale Identifier", DBPROP_INIT_LCID
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
365 { L
"Location", DBPROP_INIT_LOCATION
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
366 { L
"Lock Owner", DBPROP_INIT_LOCKOWNER
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
367 { L
"Mask Password", DBPROP_AUTH_MASK_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
368 { L
"Mode", DBPROP_INIT_MODE
, DBPROPOPTIONS_OPTIONAL
, VT_I4
, convert_dbproperty_mode
},
369 { L
"OLE DB Services", DBPROP_INIT_OLEDBSERVICES
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
370 { L
"Password", DBPROP_AUTH_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
371 { L
"Persist Encrypted", DBPROP_AUTH_PERSIST_ENCRYPTED
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
372 { L
"Persist Security Info", DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
373 { L
"Prompt", DBPROP_INIT_PROMPT
, DBPROPOPTIONS_OPTIONAL
, VT_I2
},
374 { L
"Protection level", DBPROP_INIT_PROTECTION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
375 { L
"User ID", DBPROP_AUTH_USERID
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
377 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
379 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I8
},
396 /* name/value strings are reused, so they shouldn't be freed after this call */
397 static HRESULT
add_dbprop_to_list(struct dbprops
*props
, BSTR name
, BSTR value
)
399 struct dbprop_pair
*pair
;
401 pair
= malloc(sizeof(*pair
));
403 return E_OUTOFMEMORY
;
407 list_add_tail(&props
->props
, &pair
->entry
);
412 static void free_dbprop_list(struct dbprops
*props
)
414 struct dbprop_pair
*p
, *p2
;
415 LIST_FOR_EACH_ENTRY_SAFE(p
, p2
, &props
->props
, struct dbprop_pair
, entry
)
417 list_remove(&p
->entry
);
418 SysFreeString(p
->name
);
419 SysFreeString(p
->value
);
424 static HRESULT
parse_init_string(const WCHAR
*initstring
, struct dbprops
*props
)
430 list_init(&props
->props
);
434 while (start
&& (eq
= wcschr(start
, '=')))
439 name
= SysAllocStringLen(start
, eq
- start
);
440 /* skip equal sign to get value */
443 quote
= (*eq
== '"' || *eq
== '\'') ? *eq
: 0;
446 /* for quoted value string, skip opening mark, look for terminating one */
448 delim
= wcschr(eq
, quote
);
451 delim
= wcschr(eq
, ';');
454 value
= SysAllocStringLen(eq
, delim
- eq
);
456 value
= SysAllocString(eq
);
458 /* skip semicolon if present */
468 if (!wcsicmp(name
, L
"Provider"))
471 SysFreeString(value
);
475 TRACE("property (name=%s, value=%s)\n", debugstr_w(name
), debugstr_w(value
));
477 hr
= add_dbprop_to_list(props
, name
, value
);
481 SysFreeString(value
);
487 free_dbprop_list(props
);
492 static const struct dbproperty
*get_known_dprop_descr(BSTR name
)
497 max
= ARRAY_SIZE(dbproperties
) - 1;
505 r
= wcsicmp(dbproperties
[n
].name
, name
);
515 return (min
<= max
) ? &dbproperties
[n
] : NULL
;
518 static HRESULT
get_dbpropset_from_proplist(struct dbprops
*props
, DBPROPSET
**propset
)
520 BSTR provider_string
= NULL
;
521 struct dbprop_pair
*pair
;
525 *propset
= CoTaskMemAlloc(sizeof(DBPROPSET
));
527 return E_OUTOFMEMORY
;
529 (*propset
)->rgProperties
= CoTaskMemAlloc(props
->count
*sizeof(DBPROP
));
530 if (!(*propset
)->rgProperties
)
532 CoTaskMemFree(*propset
);
534 return E_OUTOFMEMORY
;
537 (*propset
)->cProperties
= 0;
538 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
539 LIST_FOR_EACH_ENTRY(pair
, &props
->props
, struct dbprop_pair
, entry
)
541 const struct dbproperty
*descr
= get_known_dprop_descr(pair
->name
);
548 len
= SysStringLen(pair
->name
) + SysStringLen(pair
->value
) + 1; /* for '=' */
549 if (!provider_string
)
551 provider_string
= SysAllocStringLen(NULL
, len
);
555 BSTR old_string
= provider_string
;
557 len
+= SysStringLen(provider_string
) + 1; /* for ';' separator */
558 provider_string
= SysAllocStringLen(NULL
, len
);
559 lstrcpyW(provider_string
, old_string
);
560 lstrcatW(provider_string
, L
";");
561 SysFreeString(old_string
);
563 lstrcatW(provider_string
, pair
->name
);
564 lstrcatW(provider_string
, L
"=");
565 lstrcatW(provider_string
, pair
->value
);
569 V_VT(&src
) = VT_BSTR
;
570 V_BSTR(&src
) = pair
->value
;
573 hr
= VariantChangeType(&dest
, &src
, 0, descr
->type
);
574 if (FAILED(hr
) && descr
->convert_dbproperty
)
575 hr
= descr
->convert_dbproperty(pair
->value
, &dest
);
579 ERR("failed to init property %s value as type %d\n", debugstr_w(pair
->name
), descr
->type
);
580 free_dbpropset(1, *propset
);
585 (*propset
)->cProperties
++;
586 (*propset
)->rgProperties
[i
].dwPropertyID
= descr
->id
;
587 (*propset
)->rgProperties
[i
].dwOptions
= descr
->options
;
588 (*propset
)->rgProperties
[i
].dwStatus
= 0;
589 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
590 (*propset
)->rgProperties
[i
].vValue
= dest
;
594 /* Provider specific property is always VT_BSTR */
595 /* DBPROP_INIT_PROVIDERSTRING should be specified only once. Otherwise, it will be considered as
596 * provider-specific rather than an initialization property */
599 (*propset
)->cProperties
++;
600 (*propset
)->rgProperties
[i
].dwPropertyID
= DBPROP_INIT_PROVIDERSTRING
;
601 (*propset
)->rgProperties
[i
].dwOptions
= DBPROPOPTIONS_REQUIRED
;
602 (*propset
)->rgProperties
[i
].dwStatus
= 0;
603 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
604 V_VT(&(*propset
)->rgProperties
[i
].vValue
) = VT_BSTR
;
605 V_BSTR(&(*propset
)->rgProperties
[i
].vValue
) = provider_string
;
611 /*** IDataInitialize methods ***/
612 static void datasource_release(BOOL created
, IUnknown
**datasource
)
617 IUnknown_Release(*datasource
);
621 static WCHAR
*strstriW(const WCHAR
*str
, const WCHAR
*sub
)
623 LPWSTR strlower
, sublower
, r
;
624 strlower
= CharLowerW(wcsdup(str
));
625 sublower
= CharLowerW(wcsdup(sub
));
626 r
= wcsstr(strlower
, sublower
);
628 r
= (LPWSTR
)str
+ (r
- strlower
);
634 HRESULT
get_data_source(IUnknown
*outer
, DWORD clsctx
, LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
636 static const WCHAR providerW
[] = L
"Provider=";
637 BOOL datasource_created
= FALSE
;
638 IDBProperties
*dbprops
;
645 /* first get provider name */
646 provclsid
= IID_NULL
;
647 if (initstring
&& (prov
= strstriW(initstring
, providerW
)))
649 WCHAR
*start
, *progid
;
652 prov
+= ARRAY_SIZE(providerW
)-1;
654 while (*prov
&& *prov
!= ';')
656 TRACE("got provider %s\n", debugstr_wn(start
, prov
-start
));
659 progid
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
660 if (!progid
) return E_OUTOFMEMORY
;
662 memcpy(progid
, start
, len
*sizeof(WCHAR
));
665 hr
= CLSIDFromProgID(progid
, &provclsid
);
666 CoTaskMemFree(progid
);
669 ERR("provider %s not registered\n", debugstr_wn(start
, prov
-start
));
675 hr
= CLSIDFromProgID(L
"MSDASQL", &provclsid
);
677 ERR("ODBC provider for OLE DB not registered\n");
680 /* check for provider mismatch if it was specified in init string */
681 if (*datasource
&& prov
)
683 DBPROPIDSET propidset
;
688 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
691 WARN("provider doesn't support IDBProperties\n");
695 prop
= DBPROP_INIT_DATASOURCE
;
696 propidset
.rgPropertyIDs
= &prop
;
697 propidset
.cPropertyIDs
= 1;
698 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
701 hr
= IDBProperties_GetProperties(dbprops
, 1, &propidset
, &count
, &propset
);
702 IDBProperties_Release(dbprops
);
705 WARN("GetProperties failed for datasource, 0x%08lx\n", hr
);
709 TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset
->rgProperties
[0].vValue
)));
711 hr
= CLSIDFromProgID(V_BSTR(&propset
->rgProperties
[0].vValue
), &initprov
);
712 free_dbpropset(count
, propset
);
714 if (FAILED(hr
) || !IsEqualIID(&provclsid
, &initprov
)) return DB_E_MISMATCHEDPROVIDER
;
719 if (!IsEqualIID(&provclsid
, &IID_NULL
))
720 hr
= CoCreateInstance(&provclsid
, outer
, clsctx
, riid
, (void**)datasource
);
722 if (FAILED(hr
) && IsEqualIID(riid
, &IID_IDBInitialize
))
723 hr
= create_db_init(datasource
);
725 datasource_created
= *datasource
!= NULL
;
728 /* now set properties */
731 struct dbprops props
;
733 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
736 ERR("provider doesn't support IDBProperties\n");
737 datasource_release(datasource_created
, datasource
);
741 hr
= parse_init_string(initstring
, &props
);
744 datasource_release(datasource_created
, datasource
);
748 hr
= get_dbpropset_from_proplist(&props
, &propset
);
749 free_dbprop_list(&props
);
752 datasource_release(datasource_created
, datasource
);
756 hr
= IDBProperties_SetProperties(dbprops
, 1, propset
);
757 IDBProperties_Release(dbprops
);
758 free_dbpropset(1, propset
);
761 ERR("SetProperties failed, 0x%08lx\n", hr
);
762 datasource_release(datasource_created
, datasource
);
770 static HRESULT WINAPI
datainit_GetDataSource(IDataInitialize
*iface
, IUnknown
*outer
, DWORD clsctx
,
771 LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
773 datainit
*This
= impl_from_IDataInitialize(iface
);
775 TRACE("(%p)->(%p 0x%lx %s %s %p)\n", This
, outer
, clsctx
, debugstr_w(initstring
), debugstr_guid(riid
), datasource
);
777 return get_data_source(outer
, clsctx
, initstring
, riid
, datasource
);
780 /* returns character length of string representation */
781 static int get_propvalue_length(DBPROP
*prop
)
786 if (V_VT(&prop
->vValue
) == VT_BSTR
) return SysStringLen(V_BSTR(&prop
->vValue
));
789 hr
= VariantChangeType(&str
, &prop
->vValue
, 0, VT_BSTR
);
792 int len
= SysStringLen(V_BSTR(&str
));
800 static void write_propvalue_str(WCHAR
*str
, DBPROP
*prop
)
802 VARIANT
*v
= &prop
->vValue
;
806 if (V_VT(v
) == VT_BSTR
)
808 lstrcatW(str
, V_BSTR(v
));
813 hr
= VariantChangeType(&vstr
, v
, VARIANT_ALPHABOOL
, VT_BSTR
);
816 lstrcatW(str
, V_BSTR(&vstr
));
821 static WCHAR
*get_propinfo_descr(DBPROP
*prop
, DBPROPINFOSET
*propinfoset
)
825 for (i
= 0; i
< propinfoset
->cPropertyInfos
; i
++)
826 if (propinfoset
->rgPropertyInfos
[i
].dwPropertyID
== prop
->dwPropertyID
)
827 return propinfoset
->rgPropertyInfos
[i
].pwszDescription
;
832 static void free_dbpropinfoset(ULONG count
, DBPROPINFOSET
*propinfoset
)
836 for (i
= 0; i
< count
; i
++)
840 for (p
= 0; p
< propinfoset
[i
].cPropertyInfos
; p
++)
841 VariantClear(&propinfoset
[i
].rgPropertyInfos
[p
].vValues
);
843 CoTaskMemFree(propinfoset
[i
].rgPropertyInfos
);
845 CoTaskMemFree(propinfoset
);
848 static HRESULT WINAPI
datainit_GetInitializationString(IDataInitialize
*iface
, IUnknown
*datasource
,
849 boolean include_pass
, LPWSTR
*init_string
)
851 static const WCHAR providerW
[] = L
"Provider=";
852 datainit
*This
= impl_from_IDataInitialize(iface
);
853 DBPROPINFOSET
*propinfoset
;
854 IDBProperties
*props
;
855 DBPROPIDSET propidset
;
856 ULONG count
, infocount
;
857 WCHAR
*progid
, *desc
;
864 TRACE("(%p)->(%p %d %p)\n", This
, datasource
, include_pass
, init_string
);
866 /* IPersist support is mandatory for data sources */
867 hr
= IUnknown_QueryInterface(datasource
, &IID_IPersist
, (void**)&persist
);
868 if (FAILED(hr
)) return hr
;
870 memset(&clsid
, 0, sizeof(clsid
));
871 hr
= IPersist_GetClassID(persist
, &clsid
);
872 IPersist_Release(persist
);
873 if (FAILED(hr
)) return hr
;
876 ProgIDFromCLSID(&clsid
, &progid
);
877 TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid
), debugstr_w(progid
));
879 /* now get initialization properties */
880 hr
= IUnknown_QueryInterface(datasource
, &IID_IDBProperties
, (void**)&props
);
883 WARN("IDBProperties not supported\n");
884 CoTaskMemFree(progid
);
888 propidset
.rgPropertyIDs
= NULL
;
889 propidset
.cPropertyIDs
= 0;
890 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
893 hr
= IDBProperties_GetProperties(props
, 1, &propidset
, &count
, &propset
);
896 WARN("failed to get data source properties, 0x%08lx\n", hr
);
897 CoTaskMemFree(progid
);
902 IDBProperties_GetPropertyInfo(props
, 1, &propidset
, &infocount
, &propinfoset
, &desc
);
903 IDBProperties_Release(props
);
905 /* check if we need to skip password */
906 len
= lstrlenW(progid
) + lstrlenW(providerW
) + 1; /* including ';' */
907 for (i
= 0; i
< count
; i
++)
909 WCHAR
*descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
912 /* include '=' and ';' */
913 len
+= lstrlenW(descr
) + 2;
914 len
+= get_propvalue_length(&propset
->rgProperties
[i
]);
917 if ((propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
) &&
918 (V_BOOL(&propset
->rgProperties
[i
].vValue
) == VARIANT_FALSE
))
919 include_pass
= FALSE
;
922 len
*= sizeof(WCHAR
);
923 *init_string
= CoTaskMemAlloc(len
);
927 lstrcatW(*init_string
, providerW
);
928 lstrcatW(*init_string
, progid
);
929 lstrcatW(*init_string
, L
";");
930 CoTaskMemFree(progid
);
932 for (i
= 0; i
< count
; i
++)
936 if (!include_pass
&& propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PASSWORD
) continue;
938 descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
941 lstrcatW(*init_string
, descr
);
942 lstrcatW(*init_string
, L
"=");
943 write_propvalue_str(*init_string
, &propset
->rgProperties
[i
]);
944 lstrcatW(*init_string
, L
";");
948 free_dbpropset(count
, propset
);
949 free_dbpropinfoset(infocount
, propinfoset
);
953 TRACE("%s\n", debugstr_w(*init_string
));
957 static HRESULT WINAPI
datainit_CreateDBInstance(IDataInitialize
*iface
, REFCLSID provider
,
958 IUnknown
*outer
, DWORD clsctx
, LPWSTR reserved
, REFIID riid
,
959 IUnknown
**datasource
)
961 datainit
*This
= impl_from_IDataInitialize(iface
);
963 TRACE("(%p)->(%s %p 0x%08lx %s %s %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
, debugstr_w(reserved
),
964 debugstr_guid(riid
), datasource
);
966 return CoCreateInstance(provider
, outer
, clsctx
, riid
, (void**)datasource
);
969 static HRESULT WINAPI
datainit_CreateDBInstanceEx(IDataInitialize
*iface
, REFCLSID provider
, IUnknown
*outer
,
970 DWORD clsctx
, LPWSTR reserved
, COSERVERINFO
*server_info
, DWORD cmq
, MULTI_QI
*results
)
972 datainit
*This
= impl_from_IDataInitialize(iface
);
974 FIXME("(%p)->(%s %p %#lx %s %p %lu %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
,
975 debugstr_w(reserved
), server_info
, cmq
, results
);
980 static HRESULT WINAPI
datainit_LoadStringFromStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
981 LPWSTR
*ppwszInitializationString
)
983 datainit
*This
= impl_from_IDataInitialize(iface
);
985 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pwszFileName
), ppwszInitializationString
);
990 static HRESULT WINAPI
datainit_WriteStringToStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
991 LPWSTR pwszInitializationString
, DWORD dwCreationDisposition
)
993 datainit
*This
= impl_from_IDataInitialize(iface
);
995 FIXME("(%p)->(%s %s %ld)\n", This
, debugstr_w(pwszFileName
), debugstr_w(pwszInitializationString
), dwCreationDisposition
);
1001 static const struct IDataInitializeVtbl datainit_vtbl
=
1003 datainit_QueryInterface
,
1006 datainit_GetDataSource
,
1007 datainit_GetInitializationString
,
1008 datainit_CreateDBInstance
,
1009 datainit_CreateDBInstanceEx
,
1010 datainit_LoadStringFromStorage
,
1011 datainit_WriteStringToStorage
1014 HRESULT
create_data_init(IUnknown
*outer
, void **obj
)
1018 TRACE("(%p)\n", obj
);
1020 if(outer
) return CLASS_E_NOAGGREGATION
;
1024 This
= malloc(sizeof(*This
));
1025 if(!This
) return E_OUTOFMEMORY
;
1027 This
->IDataInitialize_iface
.lpVtbl
= &datainit_vtbl
;
1030 *obj
= &This
->IDataInitialize_iface
;