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(DB_NULLGUID
, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
37 DEFINE_GUID(DBGUID_SESSION
, 0xc8b522f5, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
38 DEFINE_GUID(DBGUID_ROWSET
, 0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
39 DEFINE_GUID(DBGUID_ROW
, 0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
40 DEFINE_GUID(DBGUID_STREAM
, 0xc8b522f9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
42 DEFINE_GUID(DBPROPSET_COLUMN
, 0xc8b522b9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
43 DEFINE_GUID(DBPROPSET_DATASOURCE
, 0xc8b522ba, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
44 DEFINE_GUID(DBPROPSET_DATASOURCEINFO
, 0xc8b522bb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
45 DEFINE_GUID(DBPROPSET_DBINIT
, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
46 DEFINE_GUID(DBPROPSET_INDEX
, 0xc8b522bd, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
47 DEFINE_GUID(DBPROPSET_ROWSET
, 0xc8b522be, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
48 DEFINE_GUID(DBPROPSET_TABLE
, 0xc8b522bf, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
49 DEFINE_GUID(DBPROPSET_DATASOURCEALL
, 0xc8b522c0, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
50 DEFINE_GUID(DBPROPSET_DATASOURCEINFOALL
, 0xc8b522c1, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
51 DEFINE_GUID(DBPROPSET_ROWSETALL
, 0xc8b522c2, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
52 DEFINE_GUID(DBPROPSET_SESSION
, 0xc8b522c6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
53 DEFINE_GUID(DBPROPSET_SESSIONALL
, 0xc8b522c7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
54 DEFINE_GUID(DBPROPSET_DBINITALL
, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
55 DEFINE_GUID(DBPROPSET_PROPERTIESINERROR
, 0xc8b522d4, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
57 typedef struct datainit
59 IDataInitialize IDataInitialize_iface
;
64 static inline datainit
*impl_from_IDataInitialize(IDataInitialize
*iface
)
66 return CONTAINING_RECORD(iface
, datainit
, IDataInitialize_iface
);
71 IDBInitialize IDBInitialize_iface
;
72 IDBProperties IDBProperties_iface
;
77 static inline dbinit
*impl_from_IDBInitialize(IDBInitialize
*iface
)
79 return CONTAINING_RECORD(iface
, dbinit
, IDBInitialize_iface
);
82 static inline dbinit
*impl_from_IDBProperties(IDBProperties
*iface
)
84 return CONTAINING_RECORD(iface
, dbinit
, IDBProperties_iface
);
87 static HRESULT WINAPI
dbprops_QueryInterface(IDBProperties
*iface
, REFIID riid
, void **ppvObject
)
89 dbinit
*This
= impl_from_IDBProperties(iface
);
91 return IDBInitialize_QueryInterface(&This
->IDBInitialize_iface
, riid
, ppvObject
);
94 static ULONG WINAPI
dbprops_AddRef(IDBProperties
*iface
)
96 dbinit
*This
= impl_from_IDBProperties(iface
);
98 return IDBInitialize_AddRef(&This
->IDBInitialize_iface
);
101 static ULONG WINAPI
dbprops_Release(IDBProperties
*iface
)
103 dbinit
*This
= impl_from_IDBProperties(iface
);
105 return IDBInitialize_Release(&This
->IDBInitialize_iface
);
108 static HRESULT WINAPI
dbprops_GetProperties(IDBProperties
*iface
, ULONG cPropertyIDSets
,
109 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertySets
, DBPROPSET
**prgPropertySets
)
111 dbinit
*This
= impl_from_IDBProperties(iface
);
113 FIXME("(%p)->(%ld %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertySets
, prgPropertySets
);
118 static HRESULT WINAPI
dbprops_GetPropertyInfo(IDBProperties
*iface
, ULONG cPropertyIDSets
,
119 const DBPROPIDSET rgPropertyIDSets
[], ULONG
*pcPropertyInfoSets
,
120 DBPROPINFOSET
**prgPropertyInfoSets
, OLECHAR
**ppDescBuffer
)
122 dbinit
*This
= impl_from_IDBProperties(iface
);
124 FIXME("(%p)->(%ld %p %p %p %p)\n", This
, cPropertyIDSets
, rgPropertyIDSets
, pcPropertyInfoSets
,
125 prgPropertyInfoSets
, ppDescBuffer
);
130 static HRESULT WINAPI
dbprops_SetProperties(IDBProperties
*iface
, ULONG cPropertySets
,
131 DBPROPSET rgPropertySets
[])
133 dbinit
*This
= impl_from_IDBProperties(iface
);
135 FIXME("(%p)->(%ld %p)\n", This
, cPropertySets
, rgPropertySets
);
140 static const struct IDBPropertiesVtbl dbprops_vtbl
=
142 dbprops_QueryInterface
,
145 dbprops_GetProperties
,
146 dbprops_GetPropertyInfo
,
147 dbprops_SetProperties
150 static HRESULT WINAPI
dbinit_QueryInterface(IDBInitialize
*iface
, REFIID riid
, void **obj
)
152 dbinit
*This
= impl_from_IDBInitialize(iface
);
153 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
157 if(IsEqualIID(riid
, &IID_IUnknown
) ||
158 IsEqualIID(riid
, &IID_IDBInitialize
))
162 else if(IsEqualIID(riid
, &IID_IDBProperties
))
164 *obj
= &This
->IDBProperties_iface
;
168 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
169 return E_NOINTERFACE
;
172 IDBInitialize_AddRef(iface
);
176 static ULONG WINAPI
dbinit_AddRef(IDBInitialize
*iface
)
178 dbinit
*This
= impl_from_IDBInitialize(iface
);
179 TRACE("(%p)\n", This
);
181 return InterlockedIncrement(&This
->ref
);
184 static ULONG WINAPI
dbinit_Release(IDBInitialize
*iface
)
186 dbinit
*This
= impl_from_IDBInitialize(iface
);
189 TRACE("(%p)\n", This
);
191 ref
= InterlockedDecrement(&This
->ref
);
198 static HRESULT WINAPI
dbinit_Initialize(IDBInitialize
*iface
)
200 dbinit
*This
= impl_from_IDBInitialize(iface
);
202 FIXME("(%p) stub\n", This
);
207 static HRESULT WINAPI
dbinit_Uninitialize(IDBInitialize
*iface
)
209 dbinit
*This
= impl_from_IDBInitialize(iface
);
211 FIXME("(%p) stub\n", This
);
216 static const IDBInitializeVtbl dbinit_vtbl
=
218 dbinit_QueryInterface
,
225 static HRESULT
create_db_init(IUnknown
**obj
)
233 This
= malloc(sizeof(*This
));
234 if(!This
) return E_OUTOFMEMORY
;
236 This
->IDBInitialize_iface
.lpVtbl
= &dbinit_vtbl
;
237 This
->IDBProperties_iface
.lpVtbl
= &dbprops_vtbl
;
240 *obj
= (IUnknown
*)&This
->IDBInitialize_iface
;
245 static HRESULT WINAPI
datainit_QueryInterface(IDataInitialize
*iface
, REFIID riid
, void **obj
)
247 datainit
*This
= impl_from_IDataInitialize(iface
);
248 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
252 if(IsEqualIID(riid
, &IID_IUnknown
) ||
253 IsEqualIID(riid
, &IID_IDataInitialize
))
255 *obj
= &This
->IDataInitialize_iface
;
259 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
260 return E_NOINTERFACE
;
263 IDataInitialize_AddRef(iface
);
267 static ULONG WINAPI
datainit_AddRef(IDataInitialize
*iface
)
269 datainit
*This
= impl_from_IDataInitialize(iface
);
270 TRACE("(%p)\n", This
);
272 return InterlockedIncrement(&This
->ref
);
275 static ULONG WINAPI
datainit_Release(IDataInitialize
*iface
)
277 datainit
*This
= impl_from_IDataInitialize(iface
);
280 TRACE("(%p)\n", This
);
282 ref
= InterlockedDecrement(&This
->ref
);
289 static void free_dbpropset(ULONG count
, DBPROPSET
*propset
)
293 for (i
= 0; i
< count
; i
++)
297 for (p
= 0; p
< propset
[i
].cProperties
; p
++)
298 VariantClear(&propset
[i
].rgProperties
[p
].vValue
);
300 CoTaskMemFree(propset
[i
].rgProperties
);
302 CoTaskMemFree(propset
);
308 DBPROPOPTIONS options
;
310 HRESULT (*convert_dbproperty
)(const WCHAR
*src
, VARIANT
*dest
);
319 static int __cdecl
dbmodeprop_compare(const void *a
, const void *b
)
321 const WCHAR
*src
= a
;
322 const struct mode_propval
*propval
= b
;
323 return wcsicmp(src
, propval
->name
);
326 static HRESULT
convert_dbproperty_mode(const WCHAR
*src
, VARIANT
*dest
)
328 static const struct mode_propval mode_propvals
[] =
330 { L
"Read", DB_MODE_READ
},
331 { L
"ReadWrite", DB_MODE_READWRITE
},
332 { L
"Share Deny None", DB_MODE_SHARE_DENY_NONE
},
333 { L
"Share Deny Read", DB_MODE_SHARE_DENY_READ
},
334 { L
"Share Deny Write", DB_MODE_SHARE_DENY_WRITE
},
335 { L
"Share Exclusive", DB_MODE_SHARE_EXCLUSIVE
},
336 { L
"Write", DB_MODE_WRITE
},
338 struct mode_propval
*prop
;
340 if ((prop
= bsearch(src
, mode_propvals
, ARRAY_SIZE(mode_propvals
),
341 sizeof(struct mode_propval
), dbmodeprop_compare
)))
344 V_I4(dest
) = prop
->value
;
345 TRACE("%s = %#lx\n", debugstr_w(src
), prop
->value
);
352 static const struct dbproperty dbproperties
[] =
354 { L
"Asynchronous Processing", DBPROP_INIT_ASYNCH
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
355 { L
"Bind Flags", DBPROP_INIT_BINDFLAGS
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
356 { L
"Cache Authentication", DBPROP_AUTH_CACHE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
357 { L
"Connect Timeout", DBPROP_INIT_TIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
358 { L
"Data Source", DBPROP_INIT_DATASOURCE
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
359 { L
"Extended Properties", DBPROP_INIT_PROVIDERSTRING
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
360 { L
"Encrypt Password", DBPROP_AUTH_ENCRYPT_PASSWORD
, DBPROPOPTIONS_REQUIRED
, VT_BOOL
},
361 { L
"General Timeout", DBPROP_INIT_GENERALTIMEOUT
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
362 { L
"Impersonation Level", DBPROP_INIT_IMPERSONATION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
363 { L
"Initial Catalog", DBPROP_INIT_CATALOG
, DBPROPOPTIONS_REQUIRED
, VT_BSTR
},
364 { L
"Integrated Security", DBPROP_AUTH_INTEGRATED
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
365 { L
"Locale Identifier", DBPROP_INIT_LCID
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
366 { L
"Location", DBPROP_INIT_LOCATION
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
367 { L
"Lock Owner", DBPROP_INIT_LOCKOWNER
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
368 { L
"Mask Password", DBPROP_AUTH_MASK_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
369 { L
"Mode", DBPROP_INIT_MODE
, DBPROPOPTIONS_OPTIONAL
, VT_I4
, convert_dbproperty_mode
},
370 { L
"OLE DB Services", DBPROP_INIT_OLEDBSERVICES
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
371 { L
"Password", DBPROP_AUTH_PASSWORD
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
372 { L
"Persist Encrypted", DBPROP_AUTH_PERSIST_ENCRYPTED
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
373 { L
"Persist Security Info", DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
, DBPROPOPTIONS_OPTIONAL
, VT_BOOL
},
374 { L
"Prompt", DBPROP_INIT_PROMPT
, DBPROPOPTIONS_OPTIONAL
, VT_I2
},
375 { L
"Protection level", DBPROP_INIT_PROTECTION_LEVEL
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
376 { L
"User ID", DBPROP_AUTH_USERID
, DBPROPOPTIONS_OPTIONAL
, VT_BSTR
},
378 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I4
},
380 { L
"Window Handle", DBPROP_INIT_HWND
, DBPROPOPTIONS_OPTIONAL
, VT_I8
},
397 /* name/value strings are reused, so they shouldn't be freed after this call */
398 static HRESULT
add_dbprop_to_list(struct dbprops
*props
, BSTR name
, BSTR value
)
400 struct dbprop_pair
*pair
;
402 pair
= malloc(sizeof(*pair
));
404 return E_OUTOFMEMORY
;
408 list_add_tail(&props
->props
, &pair
->entry
);
413 static void free_dbprop_list(struct dbprops
*props
)
415 struct dbprop_pair
*p
, *p2
;
416 LIST_FOR_EACH_ENTRY_SAFE(p
, p2
, &props
->props
, struct dbprop_pair
, entry
)
418 list_remove(&p
->entry
);
419 SysFreeString(p
->name
);
420 SysFreeString(p
->value
);
425 static HRESULT
parse_init_string(const WCHAR
*initstring
, struct dbprops
*props
)
431 list_init(&props
->props
);
435 while (start
&& (eq
= wcschr(start
, '=')))
440 name
= SysAllocStringLen(start
, eq
- start
);
441 /* skip equal sign to get value */
444 quote
= (*eq
== '"' || *eq
== '\'') ? *eq
: 0;
447 /* for quoted value string, skip opening mark, look for terminating one */
449 delim
= wcschr(eq
, quote
);
452 delim
= wcschr(eq
, ';');
455 value
= SysAllocStringLen(eq
, delim
- eq
);
457 value
= SysAllocString(eq
);
459 /* skip semicolon if present */
469 if (!wcsicmp(name
, L
"Provider"))
472 SysFreeString(value
);
476 TRACE("property (name=%s, value=%s)\n", debugstr_w(name
), debugstr_w(value
));
478 hr
= add_dbprop_to_list(props
, name
, value
);
482 SysFreeString(value
);
488 free_dbprop_list(props
);
493 static const struct dbproperty
*get_known_dprop_descr(BSTR name
)
498 max
= ARRAY_SIZE(dbproperties
) - 1;
506 r
= wcsicmp(dbproperties
[n
].name
, name
);
516 return (min
<= max
) ? &dbproperties
[n
] : NULL
;
519 static HRESULT
get_dbpropset_from_proplist(struct dbprops
*props
, DBPROPSET
**propset
)
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 LIST_FOR_EACH_ENTRY(pair
, &props
->props
, struct dbprop_pair
, entry
)
540 const struct dbproperty
*descr
= get_known_dprop_descr(pair
->name
);
548 /* provider specific property is always VT_BSTR */
549 len
= SysStringLen(pair
->name
) + SysStringLen(pair
->value
) + 1 /* for '=' */;
550 str
= SysAllocStringLen(NULL
, len
);
551 lstrcpyW(str
, pair
->name
);
553 lstrcatW(str
, pair
->value
);
555 (*propset
)->cProperties
++;
556 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
557 (*propset
)->rgProperties
[i
].dwPropertyID
= DBPROP_INIT_PROVIDERSTRING
;
558 (*propset
)->rgProperties
[i
].dwOptions
= DBPROPOPTIONS_REQUIRED
;
559 (*propset
)->rgProperties
[i
].dwStatus
= 0;
560 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
561 V_VT(&(*propset
)->rgProperties
[i
].vValue
) = VT_BSTR
;
562 V_BSTR(&(*propset
)->rgProperties
[i
].vValue
) = str
;
567 V_VT(&src
) = VT_BSTR
;
568 V_BSTR(&src
) = pair
->value
;
571 hr
= VariantChangeType(&dest
, &src
, 0, descr
->type
);
572 if (FAILED(hr
) && descr
->convert_dbproperty
)
573 hr
= descr
->convert_dbproperty(pair
->value
, &dest
);
577 ERR("failed to init property %s value as type %d\n", debugstr_w(pair
->name
), descr
->type
);
578 free_dbpropset(1, *propset
);
583 (*propset
)->cProperties
++;
584 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
585 (*propset
)->rgProperties
[i
].dwPropertyID
= descr
->id
;
586 (*propset
)->rgProperties
[i
].dwOptions
= descr
->options
;
587 (*propset
)->rgProperties
[i
].dwStatus
= 0;
588 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
589 (*propset
)->rgProperties
[i
].vValue
= dest
;
596 /*** IDataInitialize methods ***/
597 static void datasource_release(BOOL created
, IUnknown
**datasource
)
602 IUnknown_Release(*datasource
);
606 static WCHAR
*strstriW(const WCHAR
*str
, const WCHAR
*sub
)
608 LPWSTR strlower
, sublower
, r
;
609 strlower
= CharLowerW(wcsdup(str
));
610 sublower
= CharLowerW(wcsdup(sub
));
611 r
= wcsstr(strlower
, sublower
);
613 r
= (LPWSTR
)str
+ (r
- strlower
);
619 HRESULT
get_data_source(IUnknown
*outer
, DWORD clsctx
, LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
621 static const WCHAR providerW
[] = L
"Provider=";
622 BOOL datasource_created
= FALSE
;
623 IDBProperties
*dbprops
;
630 /* first get provider name */
631 provclsid
= IID_NULL
;
632 if (initstring
&& (prov
= strstriW(initstring
, providerW
)))
634 WCHAR
*start
, *progid
;
637 prov
+= ARRAY_SIZE(providerW
)-1;
639 while (*prov
&& *prov
!= ';')
641 TRACE("got provider %s\n", debugstr_wn(start
, prov
-start
));
644 progid
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
645 if (!progid
) return E_OUTOFMEMORY
;
647 memcpy(progid
, start
, len
*sizeof(WCHAR
));
650 hr
= CLSIDFromProgID(progid
, &provclsid
);
651 CoTaskMemFree(progid
);
654 ERR("provider %s not registered\n", debugstr_wn(start
, prov
-start
));
660 hr
= CLSIDFromProgID(L
"MSDASQL", &provclsid
);
662 ERR("ODBC provider for OLE DB not registered\n");
665 /* check for provider mismatch if it was specified in init string */
666 if (*datasource
&& prov
)
668 DBPROPIDSET propidset
;
673 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
676 WARN("provider doesn't support IDBProperties\n");
680 prop
= DBPROP_INIT_DATASOURCE
;
681 propidset
.rgPropertyIDs
= &prop
;
682 propidset
.cPropertyIDs
= 1;
683 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
686 hr
= IDBProperties_GetProperties(dbprops
, 1, &propidset
, &count
, &propset
);
687 IDBProperties_Release(dbprops
);
690 WARN("GetProperties failed for datasource, 0x%08lx\n", hr
);
694 TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset
->rgProperties
[0].vValue
)));
696 hr
= CLSIDFromProgID(V_BSTR(&propset
->rgProperties
[0].vValue
), &initprov
);
697 free_dbpropset(count
, propset
);
699 if (FAILED(hr
) || !IsEqualIID(&provclsid
, &initprov
)) return DB_E_MISMATCHEDPROVIDER
;
704 if (!IsEqualIID(&provclsid
, &IID_NULL
))
705 hr
= CoCreateInstance(&provclsid
, outer
, clsctx
, riid
, (void**)datasource
);
707 if (FAILED(hr
) && IsEqualIID(riid
, &IID_IDBInitialize
))
708 hr
= create_db_init(datasource
);
710 datasource_created
= *datasource
!= NULL
;
713 /* now set properties */
716 struct dbprops props
;
718 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
721 ERR("provider doesn't support IDBProperties\n");
722 datasource_release(datasource_created
, datasource
);
726 hr
= parse_init_string(initstring
, &props
);
729 datasource_release(datasource_created
, datasource
);
733 hr
= get_dbpropset_from_proplist(&props
, &propset
);
734 free_dbprop_list(&props
);
737 datasource_release(datasource_created
, datasource
);
741 hr
= IDBProperties_SetProperties(dbprops
, 1, propset
);
742 IDBProperties_Release(dbprops
);
743 free_dbpropset(1, propset
);
746 ERR("SetProperties failed, 0x%08lx\n", hr
);
747 datasource_release(datasource_created
, datasource
);
755 static HRESULT WINAPI
datainit_GetDataSource(IDataInitialize
*iface
, IUnknown
*outer
, DWORD clsctx
,
756 LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
758 datainit
*This
= impl_from_IDataInitialize(iface
);
760 TRACE("(%p)->(%p 0x%lx %s %s %p)\n", This
, outer
, clsctx
, debugstr_w(initstring
), debugstr_guid(riid
), datasource
);
762 return get_data_source(outer
, clsctx
, initstring
, riid
, datasource
);
765 /* returns character length of string representation */
766 static int get_propvalue_length(DBPROP
*prop
)
771 if (V_VT(&prop
->vValue
) == VT_BSTR
) return SysStringLen(V_BSTR(&prop
->vValue
));
774 hr
= VariantChangeType(&str
, &prop
->vValue
, 0, VT_BSTR
);
777 int len
= SysStringLen(V_BSTR(&str
));
785 static void write_propvalue_str(WCHAR
*str
, DBPROP
*prop
)
787 VARIANT
*v
= &prop
->vValue
;
791 if (V_VT(v
) == VT_BSTR
)
793 lstrcatW(str
, V_BSTR(v
));
798 hr
= VariantChangeType(&vstr
, v
, VARIANT_ALPHABOOL
, VT_BSTR
);
801 lstrcatW(str
, V_BSTR(&vstr
));
806 static WCHAR
*get_propinfo_descr(DBPROP
*prop
, DBPROPINFOSET
*propinfoset
)
810 for (i
= 0; i
< propinfoset
->cPropertyInfos
; i
++)
811 if (propinfoset
->rgPropertyInfos
[i
].dwPropertyID
== prop
->dwPropertyID
)
812 return propinfoset
->rgPropertyInfos
[i
].pwszDescription
;
817 static void free_dbpropinfoset(ULONG count
, DBPROPINFOSET
*propinfoset
)
821 for (i
= 0; i
< count
; i
++)
825 for (p
= 0; p
< propinfoset
[i
].cPropertyInfos
; p
++)
826 VariantClear(&propinfoset
[i
].rgPropertyInfos
[p
].vValues
);
828 CoTaskMemFree(propinfoset
[i
].rgPropertyInfos
);
830 CoTaskMemFree(propinfoset
);
833 static HRESULT WINAPI
datainit_GetInitializationString(IDataInitialize
*iface
, IUnknown
*datasource
,
834 boolean include_pass
, LPWSTR
*init_string
)
836 static const WCHAR providerW
[] = L
"Provider=";
837 datainit
*This
= impl_from_IDataInitialize(iface
);
838 DBPROPINFOSET
*propinfoset
;
839 IDBProperties
*props
;
840 DBPROPIDSET propidset
;
841 ULONG count
, infocount
;
842 WCHAR
*progid
, *desc
;
849 TRACE("(%p)->(%p %d %p)\n", This
, datasource
, include_pass
, init_string
);
851 /* IPersist support is mandatory for data sources */
852 hr
= IUnknown_QueryInterface(datasource
, &IID_IPersist
, (void**)&persist
);
853 if (FAILED(hr
)) return hr
;
855 memset(&clsid
, 0, sizeof(clsid
));
856 hr
= IPersist_GetClassID(persist
, &clsid
);
857 IPersist_Release(persist
);
858 if (FAILED(hr
)) return hr
;
861 ProgIDFromCLSID(&clsid
, &progid
);
862 TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid
), debugstr_w(progid
));
864 /* now get initialization properties */
865 hr
= IUnknown_QueryInterface(datasource
, &IID_IDBProperties
, (void**)&props
);
868 WARN("IDBProperties not supported\n");
869 CoTaskMemFree(progid
);
873 propidset
.rgPropertyIDs
= NULL
;
874 propidset
.cPropertyIDs
= 0;
875 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
878 hr
= IDBProperties_GetProperties(props
, 1, &propidset
, &count
, &propset
);
881 WARN("failed to get data source properties, 0x%08lx\n", hr
);
882 CoTaskMemFree(progid
);
887 IDBProperties_GetPropertyInfo(props
, 1, &propidset
, &infocount
, &propinfoset
, &desc
);
888 IDBProperties_Release(props
);
890 /* check if we need to skip password */
891 len
= lstrlenW(progid
) + lstrlenW(providerW
) + 1; /* including ';' */
892 for (i
= 0; i
< count
; i
++)
894 WCHAR
*descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
897 /* include '=' and ';' */
898 len
+= lstrlenW(descr
) + 2;
899 len
+= get_propvalue_length(&propset
->rgProperties
[i
]);
902 if ((propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
) &&
903 (V_BOOL(&propset
->rgProperties
[i
].vValue
) == VARIANT_FALSE
))
904 include_pass
= FALSE
;
907 len
*= sizeof(WCHAR
);
908 *init_string
= CoTaskMemAlloc(len
);
912 lstrcatW(*init_string
, providerW
);
913 lstrcatW(*init_string
, progid
);
914 lstrcatW(*init_string
, L
";");
915 CoTaskMemFree(progid
);
917 for (i
= 0; i
< count
; i
++)
921 if (!include_pass
&& propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PASSWORD
) continue;
923 descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
926 lstrcatW(*init_string
, descr
);
927 lstrcatW(*init_string
, L
"=");
928 write_propvalue_str(*init_string
, &propset
->rgProperties
[i
]);
929 lstrcatW(*init_string
, L
";");
933 free_dbpropset(count
, propset
);
934 free_dbpropinfoset(infocount
, propinfoset
);
938 TRACE("%s\n", debugstr_w(*init_string
));
942 static HRESULT WINAPI
datainit_CreateDBInstance(IDataInitialize
*iface
, REFCLSID provider
,
943 IUnknown
*outer
, DWORD clsctx
, LPWSTR reserved
, REFIID riid
,
944 IUnknown
**datasource
)
946 datainit
*This
= impl_from_IDataInitialize(iface
);
948 TRACE("(%p)->(%s %p 0x%08lx %s %s %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
, debugstr_w(reserved
),
949 debugstr_guid(riid
), datasource
);
951 return CoCreateInstance(provider
, outer
, clsctx
, riid
, (void**)datasource
);
954 static HRESULT WINAPI
datainit_CreateDBInstanceEx(IDataInitialize
*iface
, REFCLSID provider
, IUnknown
*outer
,
955 DWORD clsctx
, LPWSTR reserved
, COSERVERINFO
*server_info
, DWORD cmq
, MULTI_QI
*results
)
957 datainit
*This
= impl_from_IDataInitialize(iface
);
959 FIXME("(%p)->(%s %p %#lx %s %p %lu %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
,
960 debugstr_w(reserved
), server_info
, cmq
, results
);
965 static HRESULT WINAPI
datainit_LoadStringFromStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
966 LPWSTR
*ppwszInitializationString
)
968 datainit
*This
= impl_from_IDataInitialize(iface
);
970 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pwszFileName
), ppwszInitializationString
);
975 static HRESULT WINAPI
datainit_WriteStringToStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
976 LPWSTR pwszInitializationString
, DWORD dwCreationDisposition
)
978 datainit
*This
= impl_from_IDataInitialize(iface
);
980 FIXME("(%p)->(%s %s %ld)\n", This
, debugstr_w(pwszFileName
), debugstr_w(pwszInitializationString
), dwCreationDisposition
);
986 static const struct IDataInitializeVtbl datainit_vtbl
=
988 datainit_QueryInterface
,
991 datainit_GetDataSource
,
992 datainit_GetInitializationString
,
993 datainit_CreateDBInstance
,
994 datainit_CreateDBInstanceEx
,
995 datainit_LoadStringFromStorage
,
996 datainit_WriteStringToStorage
999 HRESULT
create_data_init(IUnknown
*outer
, void **obj
)
1003 TRACE("(%p)\n", obj
);
1005 if(outer
) return CLASS_E_NOAGGREGATION
;
1009 This
= malloc(sizeof(*This
));
1010 if(!This
) return E_OUTOFMEMORY
;
1012 This
->IDataInitialize_iface
.lpVtbl
= &datainit_vtbl
;
1015 *obj
= &This
->IDataInitialize_iface
;