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/heap.h"
33 #include "wine/list.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(oledb
);
37 DEFINE_GUID(DB_NULLGUID
, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
38 DEFINE_GUID(DBGUID_SESSION
, 0xc8b522f5, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
39 DEFINE_GUID(DBGUID_ROWSET
, 0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
40 DEFINE_GUID(DBGUID_ROW
, 0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
41 DEFINE_GUID(DBGUID_STREAM
, 0xc8b522f9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
43 DEFINE_GUID(DBPROPSET_COLUMN
, 0xc8b522b9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
44 DEFINE_GUID(DBPROPSET_DATASOURCE
, 0xc8b522ba, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
45 DEFINE_GUID(DBPROPSET_DATASOURCEINFO
, 0xc8b522bb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
46 DEFINE_GUID(DBPROPSET_DBINIT
, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
47 DEFINE_GUID(DBPROPSET_INDEX
, 0xc8b522bd, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
48 DEFINE_GUID(DBPROPSET_ROWSET
, 0xc8b522be, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
49 DEFINE_GUID(DBPROPSET_TABLE
, 0xc8b522bf, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
50 DEFINE_GUID(DBPROPSET_DATASOURCEALL
, 0xc8b522c0, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
51 DEFINE_GUID(DBPROPSET_DATASOURCEINFOALL
, 0xc8b522c1, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
52 DEFINE_GUID(DBPROPSET_ROWSETALL
, 0xc8b522c2, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
53 DEFINE_GUID(DBPROPSET_SESSION
, 0xc8b522c6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
54 DEFINE_GUID(DBPROPSET_SESSIONALL
, 0xc8b522c7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
55 DEFINE_GUID(DBPROPSET_DBINITALL
, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
56 DEFINE_GUID(DBPROPSET_PROPERTIESINERROR
, 0xc8b522d4, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
58 typedef struct datainit
60 IDataInitialize IDataInitialize_iface
;
65 static inline datainit
*impl_from_IDataInitialize(IDataInitialize
*iface
)
67 return CONTAINING_RECORD(iface
, datainit
, IDataInitialize_iface
);
72 IDBInitialize IDBInitialize_iface
;
73 IDBProperties IDBProperties_iface
;
78 static inline dbinit
*impl_from_IDBInitialize(IDBInitialize
*iface
)
80 return CONTAINING_RECORD(iface
, dbinit
, IDBInitialize_iface
);
83 static inline dbinit
*impl_from_IDBProperties(IDBProperties
*iface
)
85 return CONTAINING_RECORD(iface
, dbinit
, IDBProperties_iface
);
88 static HRESULT WINAPI
dbprops_QueryInterface(IDBProperties
*iface
, REFIID riid
, void **ppvObject
)
90 dbinit
*This
= impl_from_IDBProperties(iface
);
92 return IDBInitialize_QueryInterface(&This
->IDBInitialize_iface
, riid
, ppvObject
);
95 static ULONG WINAPI
dbprops_AddRef(IDBProperties
*iface
)
97 dbinit
*This
= impl_from_IDBProperties(iface
);
99 return IDBInitialize_AddRef(&This
->IDBInitialize_iface
);
102 static ULONG WINAPI
dbprops_Release(IDBProperties
*iface
)
104 dbinit
*This
= impl_from_IDBProperties(iface
);
106 return IDBInitialize_Release(&This
->IDBInitialize_iface
);
109 static HRESULT WINAPI
dbprops_GetProperties(IDBProperties
*iface
, ULONG cPropertyIDSets
,
110 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertySets
, DBPROPSET
**prgPropertySets
)
112 dbinit
*This
= impl_from_IDBProperties(iface
);
114 FIXME("(%p)->(%d %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertySets
, prgPropertySets
);
119 static HRESULT WINAPI
dbprops_GetPropertyInfo(IDBProperties
*iface
, ULONG cPropertyIDSets
,
120 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertyInfoSets
,
121 DBPROPINFOSET
**prgPropertyInfoSets
, OLECHAR
**ppDescBuffer
)
123 dbinit
*This
= impl_from_IDBProperties(iface
);
125 FIXME("(%p)->(%d %p %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertyInfoSets
,
126 prgPropertyInfoSets
, ppDescBuffer
);
131 static HRESULT WINAPI
dbprops_SetProperties(IDBProperties
*iface
, ULONG cPropertySets
,
132 DBPROPSET rgPropertySets
[])
134 dbinit
*This
= impl_from_IDBProperties(iface
);
136 FIXME("(%p)->(%d %p)\n", This
, cPropertySets
, rgPropertySets
);
141 static const struct IDBPropertiesVtbl dbprops_vtbl
=
143 dbprops_QueryInterface
,
146 dbprops_GetProperties
,
147 dbprops_GetPropertyInfo
,
148 dbprops_SetProperties
151 static HRESULT WINAPI
dbinit_QueryInterface(IDBInitialize
*iface
, REFIID riid
, void **obj
)
153 dbinit
*This
= impl_from_IDBInitialize(iface
);
154 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
158 if(IsEqualIID(riid
, &IID_IUnknown
) ||
159 IsEqualIID(riid
, &IID_IDBInitialize
))
163 else if(IsEqualIID(riid
, &IID_IDBProperties
))
165 *obj
= &This
->IDBProperties_iface
;
169 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
170 return E_NOINTERFACE
;
173 IDBInitialize_AddRef(iface
);
177 static ULONG WINAPI
dbinit_AddRef(IDBInitialize
*iface
)
179 dbinit
*This
= impl_from_IDBInitialize(iface
);
180 TRACE("(%p)\n", This
);
182 return InterlockedIncrement(&This
->ref
);
185 static ULONG WINAPI
dbinit_Release(IDBInitialize
*iface
)
187 dbinit
*This
= impl_from_IDBInitialize(iface
);
190 TRACE("(%p)\n", This
);
192 ref
= InterlockedDecrement(&This
->ref
);
199 static HRESULT WINAPI
dbinit_Initialize(IDBInitialize
*iface
)
201 dbinit
*This
= impl_from_IDBInitialize(iface
);
203 FIXME("(%p) stub\n", This
);
208 static HRESULT WINAPI
dbinit_Uninitialize(IDBInitialize
*iface
)
210 dbinit
*This
= impl_from_IDBInitialize(iface
);
212 FIXME("(%p) stub\n", This
);
217 static const IDBInitializeVtbl dbinit_vtbl
=
219 dbinit_QueryInterface
,
226 static HRESULT
create_db_init(IUnknown
**obj
)
234 This
= heap_alloc(sizeof(*This
));
235 if(!This
) return E_OUTOFMEMORY
;
237 This
->IDBInitialize_iface
.lpVtbl
= &dbinit_vtbl
;
238 This
->IDBProperties_iface
.lpVtbl
= &dbprops_vtbl
;
241 *obj
= (IUnknown
*)&This
->IDBInitialize_iface
;
246 static HRESULT WINAPI
datainit_QueryInterface(IDataInitialize
*iface
, REFIID riid
, void **obj
)
248 datainit
*This
= impl_from_IDataInitialize(iface
);
249 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
253 if(IsEqualIID(riid
, &IID_IUnknown
) ||
254 IsEqualIID(riid
, &IID_IDataInitialize
))
256 *obj
= &This
->IDataInitialize_iface
;
260 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
261 return E_NOINTERFACE
;
264 IDataInitialize_AddRef(iface
);
268 static ULONG WINAPI
datainit_AddRef(IDataInitialize
*iface
)
270 datainit
*This
= impl_from_IDataInitialize(iface
);
271 TRACE("(%p)\n", This
);
273 return InterlockedIncrement(&This
->ref
);
276 static ULONG WINAPI
datainit_Release(IDataInitialize
*iface
)
278 datainit
*This
= impl_from_IDataInitialize(iface
);
281 TRACE("(%p)\n", This
);
283 ref
= InterlockedDecrement(&This
->ref
);
290 static void free_dbpropset(ULONG count
, DBPROPSET
*propset
)
294 for (i
= 0; i
< count
; i
++)
298 for (p
= 0; p
< propset
[i
].cProperties
; p
++)
299 VariantClear(&propset
[i
].rgProperties
[p
].vValue
);
301 CoTaskMemFree(propset
[i
].rgProperties
);
303 CoTaskMemFree(propset
);
309 DBPROPOPTIONS options
;
311 HRESULT (*convert_dbproperty
)(const WCHAR
*src
, VARIANT
*dest
);
320 static int __cdecl
dbmodeprop_compare(const void *a
, const void *b
)
322 const WCHAR
*src
= a
;
323 const struct mode_propval
*propval
= b
;
324 return wcsicmp(src
, propval
->name
);
327 static HRESULT
convert_dbproperty_mode(const WCHAR
*src
, VARIANT
*dest
)
329 static const struct mode_propval mode_propvals
[] =
331 { L
"Read", DB_MODE_READ
},
332 { L
"ReadWrite", DB_MODE_READWRITE
},
333 { L
"Share Deny None", DB_MODE_SHARE_DENY_NONE
},
334 { L
"Share Deny Read", DB_MODE_SHARE_DENY_READ
},
335 { L
"Share Deny Write", DB_MODE_SHARE_DENY_WRITE
},
336 { L
"Share Exclusive", DB_MODE_SHARE_EXCLUSIVE
},
337 { L
"Write", DB_MODE_WRITE
},
339 struct mode_propval
*prop
;
341 if ((prop
= bsearch(src
, mode_propvals
, ARRAY_SIZE(mode_propvals
),
342 sizeof(struct mode_propval
), dbmodeprop_compare
)))
345 V_I4(dest
) = prop
->value
;
346 TRACE("%s = %#x\n", debugstr_w(src
), prop
->value
);
353 static const struct dbproperty dbproperties
[] =
355 { L
"Asynchronous Processing", DBPROP_INIT_ASYNCH
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
356 { L
"Bind Flags", DBPROP_INIT_BINDFLAGS
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
357 { L
"Cache Authentication", DBPROP_AUTH_CACHE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
358 { L
"Connect Timeout", DBPROP_INIT_TIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
359 { L
"Data Source", DBPROP_INIT_DATASOURCE
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
360 { L
"Extended Properties", DBPROP_INIT_PROVIDERSTRING
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
361 { L
"Encrypt Password", DBPROP_AUTH_ENCRYPT_PASSWORD
, DBPROPOPTIONS_REQUIRED
, VT_BOOL
},
362 { L
"General Timeout", DBPROP_INIT_GENERALTIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
363 { L
"Impersonation Level", DBPROP_INIT_IMPERSONATION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
364 { L
"Initial Catalog", DBPROP_CATALOGLOCATION
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
365 { L
"Integrated Security", DBPROP_AUTH_INTEGRATED
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
366 { L
"Locale Identifier", DBPROP_INIT_LCID
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
367 { L
"Location", DBPROP_INIT_LOCATION
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
368 { L
"Lock Owner", DBPROP_INIT_LOCKOWNER
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
369 { L
"Mask Password", DBPROP_AUTH_MASK_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
370 { L
"Mode", DBPROP_INIT_MODE
, DBPROPOPTIONS_OPTIONAL
, VT_I4
, convert_dbproperty_mode
},
371 { L
"OLE DB Services", DBPROP_INIT_OLEDBSERVICES
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
372 { L
"Password", DBPROP_AUTH_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
373 { L
"Persist Encrypted", DBPROP_AUTH_PERSIST_ENCRYPTED
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
374 { L
"Persist Security Info", DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
375 { L
"Prompt", DBPROP_INIT_PROMPT
, DBPROPOPTIONS_OPTIONAL
, VT_I2
},
376 { L
"Protection level", DBPROP_INIT_PROTECTION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
377 { L
"User ID", DBPROP_AUTH_USERID
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
379 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
381 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I8
},
398 /* name/value strings are reused, so they shouldn't be freed after this call */
399 static HRESULT
add_dbprop_to_list(struct dbprops
*props
, BSTR name
, BSTR value
)
401 struct dbprop_pair
*pair
;
403 pair
= heap_alloc(sizeof(*pair
));
405 return E_OUTOFMEMORY
;
409 list_add_tail(&props
->props
, &pair
->entry
);
414 static void free_dbprop_list(struct dbprops
*props
)
416 struct dbprop_pair
*p
, *p2
;
417 LIST_FOR_EACH_ENTRY_SAFE(p
, p2
, &props
->props
, struct dbprop_pair
, entry
)
419 list_remove(&p
->entry
);
420 SysFreeString(p
->name
);
421 SysFreeString(p
->value
);
426 static HRESULT
parse_init_string(const WCHAR
*initstring
, struct dbprops
*props
)
432 list_init(&props
->props
);
436 while (start
&& (eq
= wcschr(start
, '=')))
441 name
= SysAllocStringLen(start
, eq
- start
);
442 /* skip equal sign to get value */
445 quote
= (*eq
== '"' || *eq
== '\'') ? *eq
: 0;
448 /* for quoted value string, skip opening mark, look for terminating one */
450 delim
= wcschr(eq
, quote
);
453 delim
= wcschr(eq
, ';');
456 value
= SysAllocStringLen(eq
, delim
- eq
);
458 value
= SysAllocString(eq
);
460 /* skip semicolon if present */
470 if (!wcsicmp(name
, L
"Provider"))
473 SysFreeString(value
);
477 TRACE("property (name=%s, value=%s)\n", debugstr_w(name
), debugstr_w(value
));
479 hr
= add_dbprop_to_list(props
, name
, value
);
483 SysFreeString(value
);
489 free_dbprop_list(props
);
494 static const struct dbproperty
*get_known_dprop_descr(BSTR name
)
499 max
= ARRAY_SIZE(dbproperties
) - 1;
507 r
= wcsicmp(dbproperties
[n
].name
, name
);
517 return (min
<= max
) ? &dbproperties
[n
] : NULL
;
520 static HRESULT
get_dbpropset_from_proplist(struct dbprops
*props
, DBPROPSET
**propset
)
522 struct dbprop_pair
*pair
;
526 *propset
= CoTaskMemAlloc(sizeof(DBPROPSET
));
528 return E_OUTOFMEMORY
;
530 (*propset
)->rgProperties
= CoTaskMemAlloc(props
->count
*sizeof(DBPROP
));
531 if (!(*propset
)->rgProperties
)
533 CoTaskMemFree(*propset
);
535 return E_OUTOFMEMORY
;
538 (*propset
)->cProperties
= 0;
539 LIST_FOR_EACH_ENTRY(pair
, &props
->props
, struct dbprop_pair
, entry
)
541 const struct dbproperty
*descr
= get_known_dprop_descr(pair
->name
);
549 /* provider specific property is always VT_BSTR */
550 len
= SysStringLen(pair
->name
) + SysStringLen(pair
->value
) + 1 /* for '=' */;
551 str
= SysAllocStringLen(NULL
, len
);
552 lstrcpyW(str
, pair
->name
);
554 lstrcatW(str
, pair
->value
);
556 (*propset
)->cProperties
++;
557 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
558 (*propset
)->rgProperties
[i
].dwPropertyID
= DBPROP_INIT_PROVIDERSTRING
;
559 (*propset
)->rgProperties
[i
].dwOptions
= DBPROPOPTIONS_REQUIRED
;
560 (*propset
)->rgProperties
[i
].dwStatus
= 0;
561 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
562 V_VT(&(*propset
)->rgProperties
[i
].vValue
) = VT_BSTR
;
563 V_BSTR(&(*propset
)->rgProperties
[i
].vValue
) = str
;
568 V_VT(&src
) = VT_BSTR
;
569 V_BSTR(&src
) = pair
->value
;
572 hr
= VariantChangeType(&dest
, &src
, 0, descr
->type
);
573 if (FAILED(hr
) && descr
->convert_dbproperty
)
574 hr
= descr
->convert_dbproperty(pair
->value
, &dest
);
578 ERR("failed to init property %s value as type %d\n", debugstr_w(pair
->name
), descr
->type
);
579 free_dbpropset(1, *propset
);
584 (*propset
)->cProperties
++;
585 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
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
;
597 /*** IDataInitialize methods ***/
598 static void datasource_release(BOOL created
, IUnknown
**datasource
)
603 IUnknown_Release(*datasource
);
607 static inline WCHAR
*strdupW(const WCHAR
*src
)
610 if (!src
) return NULL
;
611 dest
= heap_alloc((lstrlenW(src
)+1)*sizeof(WCHAR
));
617 static WCHAR
*strstriW(const WCHAR
*str
, const WCHAR
*sub
)
619 LPWSTR strlower
, sublower
, r
;
620 strlower
= CharLowerW(strdupW(str
));
621 sublower
= CharLowerW(strdupW(sub
));
622 r
= wcsstr(strlower
, sublower
);
624 r
= (LPWSTR
)str
+ (r
- strlower
);
630 HRESULT
get_data_source(IUnknown
*outer
, DWORD clsctx
, LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
632 static const WCHAR providerW
[] = L
"Provider=";
633 BOOL datasource_created
= FALSE
;
634 IDBProperties
*dbprops
;
641 /* first get provider name */
642 provclsid
= IID_NULL
;
643 if (initstring
&& (prov
= strstriW(initstring
, providerW
)))
645 WCHAR
*start
, *progid
;
648 prov
+= ARRAY_SIZE(providerW
)-1;
650 while (*prov
&& *prov
!= ';')
652 TRACE("got provider %s\n", debugstr_wn(start
, prov
-start
));
655 progid
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
656 if (!progid
) return E_OUTOFMEMORY
;
658 memcpy(progid
, start
, len
*sizeof(WCHAR
));
661 hr
= CLSIDFromProgID(progid
, &provclsid
);
662 CoTaskMemFree(progid
);
665 ERR("provider %s not registered\n", debugstr_wn(start
, prov
-start
));
671 hr
= CLSIDFromProgID(L
"MSDASQL", &provclsid
);
673 ERR("ODBC provider for OLE DB not registered\n");
676 /* check for provider mismatch if it was specified in init string */
677 if (*datasource
&& prov
)
679 DBPROPIDSET propidset
;
680 enum DBPROPENUM prop
;
684 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
687 WARN("provider doesn't support IDBProperties\n");
691 prop
= DBPROP_INIT_DATASOURCE
;
692 propidset
.rgPropertyIDs
= &prop
;
693 propidset
.cPropertyIDs
= 1;
694 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
697 hr
= IDBProperties_GetProperties(dbprops
, 1, &propidset
, &count
, &propset
);
698 IDBProperties_Release(dbprops
);
701 WARN("GetProperties failed for datasource, 0x%08x\n", hr
);
705 TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset
->rgProperties
[0].vValue
)));
707 hr
= CLSIDFromProgID(V_BSTR(&propset
->rgProperties
[0].vValue
), &initprov
);
708 free_dbpropset(count
, propset
);
710 if (FAILED(hr
) || !IsEqualIID(&provclsid
, &initprov
)) return DB_E_MISMATCHEDPROVIDER
;
715 if (!IsEqualIID(&provclsid
, &IID_NULL
))
716 hr
= CoCreateInstance(&provclsid
, outer
, clsctx
, riid
, (void**)datasource
);
718 if (FAILED(hr
) && IsEqualIID(riid
, &IID_IDBInitialize
))
719 hr
= create_db_init(datasource
);
721 datasource_created
= *datasource
!= NULL
;
724 /* now set properties */
727 struct dbprops props
;
729 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
732 ERR("provider doesn't support IDBProperties\n");
733 datasource_release(datasource_created
, datasource
);
737 hr
= parse_init_string(initstring
, &props
);
740 datasource_release(datasource_created
, datasource
);
744 hr
= get_dbpropset_from_proplist(&props
, &propset
);
745 free_dbprop_list(&props
);
748 datasource_release(datasource_created
, datasource
);
752 hr
= IDBProperties_SetProperties(dbprops
, 1, propset
);
753 IDBProperties_Release(dbprops
);
754 free_dbpropset(1, propset
);
757 ERR("SetProperties failed, 0x%08x\n", hr
);
758 datasource_release(datasource_created
, datasource
);
766 static HRESULT WINAPI
datainit_GetDataSource(IDataInitialize
*iface
, IUnknown
*outer
, DWORD clsctx
,
767 LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
769 datainit
*This
= impl_from_IDataInitialize(iface
);
771 TRACE("(%p)->(%p 0x%x %s %s %p)\n", This
, outer
, clsctx
, debugstr_w(initstring
), debugstr_guid(riid
), datasource
);
773 return get_data_source(outer
, clsctx
, initstring
, riid
, datasource
);
776 /* returns character length of string representation */
777 static int get_propvalue_length(DBPROP
*prop
)
782 if (V_VT(&prop
->vValue
) == VT_BSTR
) return SysStringLen(V_BSTR(&prop
->vValue
));
785 hr
= VariantChangeType(&str
, &prop
->vValue
, 0, VT_BSTR
);
788 int len
= SysStringLen(V_BSTR(&str
));
796 static void write_propvalue_str(WCHAR
*str
, DBPROP
*prop
)
798 VARIANT
*v
= &prop
->vValue
;
802 if (V_VT(v
) == VT_BSTR
)
804 lstrcatW(str
, V_BSTR(v
));
809 hr
= VariantChangeType(&vstr
, v
, VARIANT_ALPHABOOL
, VT_BSTR
);
812 lstrcatW(str
, V_BSTR(&vstr
));
817 static WCHAR
*get_propinfo_descr(DBPROP
*prop
, DBPROPINFOSET
*propinfoset
)
821 for (i
= 0; i
< propinfoset
->cPropertyInfos
; i
++)
822 if (propinfoset
->rgPropertyInfos
[i
].dwPropertyID
== prop
->dwPropertyID
)
823 return propinfoset
->rgPropertyInfos
[i
].pwszDescription
;
828 static void free_dbpropinfoset(ULONG count
, DBPROPINFOSET
*propinfoset
)
832 for (i
= 0; i
< count
; i
++)
836 for (p
= 0; p
< propinfoset
[i
].cPropertyInfos
; p
++)
837 VariantClear(&propinfoset
[i
].rgPropertyInfos
[p
].vValues
);
839 CoTaskMemFree(propinfoset
[i
].rgPropertyInfos
);
841 CoTaskMemFree(propinfoset
);
844 static HRESULT WINAPI
datainit_GetInitializationString(IDataInitialize
*iface
, IUnknown
*datasource
,
845 boolean include_pass
, LPWSTR
*init_string
)
847 static const WCHAR providerW
[] = L
"Provider=";
848 datainit
*This
= impl_from_IDataInitialize(iface
);
849 DBPROPINFOSET
*propinfoset
;
850 IDBProperties
*props
;
851 DBPROPIDSET propidset
;
852 ULONG count
, infocount
;
853 WCHAR
*progid
, *desc
;
860 TRACE("(%p)->(%p %d %p)\n", This
, datasource
, include_pass
, init_string
);
862 /* IPersist support is mandatory for data sources */
863 hr
= IUnknown_QueryInterface(datasource
, &IID_IPersist
, (void**)&persist
);
864 if (FAILED(hr
)) return hr
;
866 memset(&clsid
, 0, sizeof(clsid
));
867 hr
= IPersist_GetClassID(persist
, &clsid
);
868 IPersist_Release(persist
);
869 if (FAILED(hr
)) return hr
;
872 ProgIDFromCLSID(&clsid
, &progid
);
873 TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid
), debugstr_w(progid
));
875 /* now get initialization properties */
876 hr
= IUnknown_QueryInterface(datasource
, &IID_IDBProperties
, (void**)&props
);
879 WARN("IDBProperties not supported\n");
880 CoTaskMemFree(progid
);
884 propidset
.rgPropertyIDs
= NULL
;
885 propidset
.cPropertyIDs
= 0;
886 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
889 hr
= IDBProperties_GetProperties(props
, 1, &propidset
, &count
, &propset
);
892 WARN("failed to get data source properties, 0x%08x\n", hr
);
893 CoTaskMemFree(progid
);
898 IDBProperties_GetPropertyInfo(props
, 1, &propidset
, &infocount
, &propinfoset
, &desc
);
899 IDBProperties_Release(props
);
901 /* check if we need to skip password */
902 len
= lstrlenW(progid
) + lstrlenW(providerW
) + 1; /* including ';' */
903 for (i
= 0; i
< count
; i
++)
905 WCHAR
*descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
908 /* include '=' and ';' */
909 len
+= lstrlenW(descr
) + 2;
910 len
+= get_propvalue_length(&propset
->rgProperties
[i
]);
913 if ((propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
) &&
914 (V_BOOL(&propset
->rgProperties
[i
].vValue
) == VARIANT_FALSE
))
915 include_pass
= FALSE
;
918 len
*= sizeof(WCHAR
);
919 *init_string
= CoTaskMemAlloc(len
);
923 lstrcatW(*init_string
, providerW
);
924 lstrcatW(*init_string
, progid
);
925 lstrcatW(*init_string
, L
";");
926 CoTaskMemFree(progid
);
928 for (i
= 0; i
< count
; i
++)
932 if (!include_pass
&& propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PASSWORD
) continue;
934 descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
937 lstrcatW(*init_string
, descr
);
938 lstrcatW(*init_string
, L
"=");
939 write_propvalue_str(*init_string
, &propset
->rgProperties
[i
]);
940 lstrcatW(*init_string
, L
";");
944 free_dbpropset(count
, propset
);
945 free_dbpropinfoset(infocount
, propinfoset
);
949 TRACE("%s\n", debugstr_w(*init_string
));
953 static HRESULT WINAPI
datainit_CreateDBInstance(IDataInitialize
*iface
, REFCLSID provider
,
954 IUnknown
*outer
, DWORD clsctx
, LPWSTR reserved
, REFIID riid
,
955 IUnknown
**datasource
)
957 datainit
*This
= impl_from_IDataInitialize(iface
);
959 TRACE("(%p)->(%s %p 0x%08x %s %s %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
, debugstr_w(reserved
),
960 debugstr_guid(riid
), datasource
);
962 return CoCreateInstance(provider
, outer
, clsctx
, riid
, (void**)datasource
);
965 static HRESULT WINAPI
datainit_CreateDBInstanceEx(IDataInitialize
*iface
, REFCLSID provider
, IUnknown
*outer
,
966 DWORD clsctx
, LPWSTR reserved
, COSERVERINFO
*server_info
, DWORD cmq
, MULTI_QI
*results
)
968 datainit
*This
= impl_from_IDataInitialize(iface
);
970 FIXME("(%p)->(%s %p %#x %s %p %u %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
,
971 debugstr_w(reserved
), server_info
, cmq
, results
);
976 static HRESULT WINAPI
datainit_LoadStringFromStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
977 LPWSTR
*ppwszInitializationString
)
979 datainit
*This
= impl_from_IDataInitialize(iface
);
981 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pwszFileName
), ppwszInitializationString
);
986 static HRESULT WINAPI
datainit_WriteStringToStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
987 LPWSTR pwszInitializationString
, DWORD dwCreationDisposition
)
989 datainit
*This
= impl_from_IDataInitialize(iface
);
991 FIXME("(%p)->(%s %s %d)\n", This
, debugstr_w(pwszFileName
), debugstr_w(pwszInitializationString
), dwCreationDisposition
);
997 static const struct IDataInitializeVtbl datainit_vtbl
=
999 datainit_QueryInterface
,
1002 datainit_GetDataSource
,
1003 datainit_GetInitializationString
,
1004 datainit_CreateDBInstance
,
1005 datainit_CreateDBInstanceEx
,
1006 datainit_LoadStringFromStorage
,
1007 datainit_WriteStringToStorage
1010 HRESULT
create_data_init(IUnknown
*outer
, void **obj
)
1014 TRACE("(%p)\n", obj
);
1016 if(outer
) return CLASS_E_NOAGGREGATION
;
1020 This
= heap_alloc(sizeof(*This
));
1021 if(!This
) return E_OUTOFMEMORY
;
1023 This
->IDataInitialize_iface
.lpVtbl
= &datainit_vtbl
;
1026 *obj
= &This
->IDataInitialize_iface
;