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 BSTR provider_string
= NULL
;
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 (*propset
)->guidPropertySet
= DBPROPSET_DBINIT
;
540 LIST_FOR_EACH_ENTRY(pair
, &props
->props
, struct dbprop_pair
, entry
)
542 const struct dbproperty
*descr
= get_known_dprop_descr(pair
->name
);
549 len
= SysStringLen(pair
->name
) + SysStringLen(pair
->value
) + 1; /* for '=' */
550 if (!provider_string
)
552 provider_string
= SysAllocStringLen(NULL
, len
);
556 BSTR old_string
= provider_string
;
558 len
+= SysStringLen(provider_string
) + 1; /* for ';' separator */
559 provider_string
= SysAllocStringLen(NULL
, len
);
560 lstrcpyW(provider_string
, old_string
);
561 lstrcatW(provider_string
, L
";");
562 SysFreeString(old_string
);
564 lstrcatW(provider_string
, pair
->name
);
565 lstrcatW(provider_string
, L
"=");
566 lstrcatW(provider_string
, pair
->value
);
570 V_VT(&src
) = VT_BSTR
;
571 V_BSTR(&src
) = pair
->value
;
574 hr
= VariantChangeType(&dest
, &src
, 0, descr
->type
);
575 if (FAILED(hr
) && descr
->convert_dbproperty
)
576 hr
= descr
->convert_dbproperty(pair
->value
, &dest
);
580 ERR("failed to init property %s value as type %d\n", debugstr_w(pair
->name
), descr
->type
);
581 free_dbpropset(1, *propset
);
586 (*propset
)->cProperties
++;
587 (*propset
)->rgProperties
[i
].dwPropertyID
= descr
->id
;
588 (*propset
)->rgProperties
[i
].dwOptions
= descr
->options
;
589 (*propset
)->rgProperties
[i
].dwStatus
= 0;
590 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
591 (*propset
)->rgProperties
[i
].vValue
= dest
;
595 /* Provider specific property is always VT_BSTR */
596 /* DBPROP_INIT_PROVIDERSTRING should be specified only once. Otherwise, it will be considered as
597 * provider-specific rather than an initialization property */
600 (*propset
)->cProperties
++;
601 (*propset
)->rgProperties
[i
].dwPropertyID
= DBPROP_INIT_PROVIDERSTRING
;
602 (*propset
)->rgProperties
[i
].dwOptions
= DBPROPOPTIONS_REQUIRED
;
603 (*propset
)->rgProperties
[i
].dwStatus
= 0;
604 memset(&(*propset
)->rgProperties
[i
].colid
, 0, sizeof(DBID
));
605 V_VT(&(*propset
)->rgProperties
[i
].vValue
) = VT_BSTR
;
606 V_BSTR(&(*propset
)->rgProperties
[i
].vValue
) = provider_string
;
612 /*** IDataInitialize methods ***/
613 static void datasource_release(BOOL created
, IUnknown
**datasource
)
618 IUnknown_Release(*datasource
);
622 static WCHAR
*strstriW(const WCHAR
*str
, const WCHAR
*sub
)
624 LPWSTR strlower
, sublower
, r
;
625 strlower
= CharLowerW(wcsdup(str
));
626 sublower
= CharLowerW(wcsdup(sub
));
627 r
= wcsstr(strlower
, sublower
);
629 r
= (LPWSTR
)str
+ (r
- strlower
);
635 HRESULT
get_data_source(IUnknown
*outer
, DWORD clsctx
, LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
637 static const WCHAR providerW
[] = L
"Provider=";
638 BOOL datasource_created
= FALSE
;
639 IDBProperties
*dbprops
;
646 /* first get provider name */
647 provclsid
= IID_NULL
;
648 if (initstring
&& (prov
= strstriW(initstring
, providerW
)))
650 WCHAR
*start
, *progid
;
653 prov
+= ARRAY_SIZE(providerW
)-1;
655 while (*prov
&& *prov
!= ';')
657 TRACE("got provider %s\n", debugstr_wn(start
, prov
-start
));
660 progid
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
661 if (!progid
) return E_OUTOFMEMORY
;
663 memcpy(progid
, start
, len
*sizeof(WCHAR
));
666 hr
= CLSIDFromProgID(progid
, &provclsid
);
667 CoTaskMemFree(progid
);
670 ERR("provider %s not registered\n", debugstr_wn(start
, prov
-start
));
676 hr
= CLSIDFromProgID(L
"MSDASQL", &provclsid
);
678 ERR("ODBC provider for OLE DB not registered\n");
681 /* check for provider mismatch if it was specified in init string */
682 if (*datasource
&& prov
)
684 DBPROPIDSET propidset
;
689 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
692 WARN("provider doesn't support IDBProperties\n");
696 prop
= DBPROP_INIT_DATASOURCE
;
697 propidset
.rgPropertyIDs
= &prop
;
698 propidset
.cPropertyIDs
= 1;
699 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
702 hr
= IDBProperties_GetProperties(dbprops
, 1, &propidset
, &count
, &propset
);
703 IDBProperties_Release(dbprops
);
706 WARN("GetProperties failed for datasource, 0x%08lx\n", hr
);
710 TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset
->rgProperties
[0].vValue
)));
712 hr
= CLSIDFromProgID(V_BSTR(&propset
->rgProperties
[0].vValue
), &initprov
);
713 free_dbpropset(count
, propset
);
715 if (FAILED(hr
) || !IsEqualIID(&provclsid
, &initprov
)) return DB_E_MISMATCHEDPROVIDER
;
720 if (!IsEqualIID(&provclsid
, &IID_NULL
))
721 hr
= CoCreateInstance(&provclsid
, outer
, clsctx
, riid
, (void**)datasource
);
723 if (FAILED(hr
) && IsEqualIID(riid
, &IID_IDBInitialize
))
724 hr
= create_db_init(datasource
);
726 datasource_created
= *datasource
!= NULL
;
729 /* now set properties */
732 struct dbprops props
;
734 hr
= IUnknown_QueryInterface(*datasource
, &IID_IDBProperties
, (void**)&dbprops
);
737 ERR("provider doesn't support IDBProperties\n");
738 datasource_release(datasource_created
, datasource
);
742 hr
= parse_init_string(initstring
, &props
);
745 datasource_release(datasource_created
, datasource
);
749 hr
= get_dbpropset_from_proplist(&props
, &propset
);
750 free_dbprop_list(&props
);
753 datasource_release(datasource_created
, datasource
);
757 hr
= IDBProperties_SetProperties(dbprops
, 1, propset
);
758 IDBProperties_Release(dbprops
);
759 free_dbpropset(1, propset
);
762 ERR("SetProperties failed, 0x%08lx\n", hr
);
763 datasource_release(datasource_created
, datasource
);
771 static HRESULT WINAPI
datainit_GetDataSource(IDataInitialize
*iface
, IUnknown
*outer
, DWORD clsctx
,
772 LPWSTR initstring
, REFIID riid
, IUnknown
**datasource
)
774 datainit
*This
= impl_from_IDataInitialize(iface
);
776 TRACE("(%p)->(%p 0x%lx %s %s %p)\n", This
, outer
, clsctx
, debugstr_w(initstring
), debugstr_guid(riid
), datasource
);
778 return get_data_source(outer
, clsctx
, initstring
, riid
, datasource
);
781 /* returns character length of string representation */
782 static int get_propvalue_length(DBPROP
*prop
)
787 if (V_VT(&prop
->vValue
) == VT_BSTR
) return SysStringLen(V_BSTR(&prop
->vValue
));
790 hr
= VariantChangeType(&str
, &prop
->vValue
, 0, VT_BSTR
);
793 int len
= SysStringLen(V_BSTR(&str
));
801 static void write_propvalue_str(WCHAR
*str
, DBPROP
*prop
)
803 VARIANT
*v
= &prop
->vValue
;
807 if (V_VT(v
) == VT_BSTR
)
809 lstrcatW(str
, V_BSTR(v
));
814 hr
= VariantChangeType(&vstr
, v
, VARIANT_ALPHABOOL
, VT_BSTR
);
817 lstrcatW(str
, V_BSTR(&vstr
));
822 static WCHAR
*get_propinfo_descr(DBPROP
*prop
, DBPROPINFOSET
*propinfoset
)
826 for (i
= 0; i
< propinfoset
->cPropertyInfos
; i
++)
827 if (propinfoset
->rgPropertyInfos
[i
].dwPropertyID
== prop
->dwPropertyID
)
828 return propinfoset
->rgPropertyInfos
[i
].pwszDescription
;
833 static void free_dbpropinfoset(ULONG count
, DBPROPINFOSET
*propinfoset
)
837 for (i
= 0; i
< count
; i
++)
841 for (p
= 0; p
< propinfoset
[i
].cPropertyInfos
; p
++)
842 VariantClear(&propinfoset
[i
].rgPropertyInfos
[p
].vValues
);
844 CoTaskMemFree(propinfoset
[i
].rgPropertyInfos
);
846 CoTaskMemFree(propinfoset
);
849 static HRESULT WINAPI
datainit_GetInitializationString(IDataInitialize
*iface
, IUnknown
*datasource
,
850 boolean include_pass
, LPWSTR
*init_string
)
852 static const WCHAR providerW
[] = L
"Provider=";
853 datainit
*This
= impl_from_IDataInitialize(iface
);
854 DBPROPINFOSET
*propinfoset
;
855 IDBProperties
*props
;
856 DBPROPIDSET propidset
;
857 ULONG count
, infocount
;
858 WCHAR
*progid
, *desc
;
865 TRACE("(%p)->(%p %d %p)\n", This
, datasource
, include_pass
, init_string
);
867 /* IPersist support is mandatory for data sources */
868 hr
= IUnknown_QueryInterface(datasource
, &IID_IPersist
, (void**)&persist
);
869 if (FAILED(hr
)) return hr
;
871 memset(&clsid
, 0, sizeof(clsid
));
872 hr
= IPersist_GetClassID(persist
, &clsid
);
873 IPersist_Release(persist
);
874 if (FAILED(hr
)) return hr
;
877 ProgIDFromCLSID(&clsid
, &progid
);
878 TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid
), debugstr_w(progid
));
880 /* now get initialization properties */
881 hr
= IUnknown_QueryInterface(datasource
, &IID_IDBProperties
, (void**)&props
);
884 WARN("IDBProperties not supported\n");
885 CoTaskMemFree(progid
);
889 propidset
.rgPropertyIDs
= NULL
;
890 propidset
.cPropertyIDs
= 0;
891 propidset
.guidPropertySet
= DBPROPSET_DBINIT
;
894 hr
= IDBProperties_GetProperties(props
, 1, &propidset
, &count
, &propset
);
897 WARN("failed to get data source properties, 0x%08lx\n", hr
);
898 CoTaskMemFree(progid
);
903 IDBProperties_GetPropertyInfo(props
, 1, &propidset
, &infocount
, &propinfoset
, &desc
);
904 IDBProperties_Release(props
);
906 /* check if we need to skip password */
907 len
= lstrlenW(progid
) + lstrlenW(providerW
) + 1; /* including ';' */
908 for (i
= 0; i
< count
; i
++)
910 WCHAR
*descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
913 /* include '=' and ';' */
914 len
+= lstrlenW(descr
) + 2;
915 len
+= get_propvalue_length(&propset
->rgProperties
[i
]);
918 if ((propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO
) &&
919 (V_BOOL(&propset
->rgProperties
[i
].vValue
) == VARIANT_FALSE
))
920 include_pass
= FALSE
;
923 len
*= sizeof(WCHAR
);
924 *init_string
= CoTaskMemAlloc(len
);
928 lstrcatW(*init_string
, providerW
);
929 lstrcatW(*init_string
, progid
);
930 lstrcatW(*init_string
, L
";");
931 CoTaskMemFree(progid
);
933 for (i
= 0; i
< count
; i
++)
937 if (!include_pass
&& propset
->rgProperties
[i
].dwPropertyID
== DBPROP_AUTH_PASSWORD
) continue;
939 descr
= get_propinfo_descr(&propset
->rgProperties
[i
], propinfoset
);
942 lstrcatW(*init_string
, descr
);
943 lstrcatW(*init_string
, L
"=");
944 write_propvalue_str(*init_string
, &propset
->rgProperties
[i
]);
945 lstrcatW(*init_string
, L
";");
949 free_dbpropset(count
, propset
);
950 free_dbpropinfoset(infocount
, propinfoset
);
954 TRACE("%s\n", debugstr_w(*init_string
));
958 static HRESULT WINAPI
datainit_CreateDBInstance(IDataInitialize
*iface
, REFCLSID provider
,
959 IUnknown
*outer
, DWORD clsctx
, LPWSTR reserved
, REFIID riid
,
960 IUnknown
**datasource
)
962 datainit
*This
= impl_from_IDataInitialize(iface
);
964 TRACE("(%p)->(%s %p 0x%08lx %s %s %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
, debugstr_w(reserved
),
965 debugstr_guid(riid
), datasource
);
967 return CoCreateInstance(provider
, outer
, clsctx
, riid
, (void**)datasource
);
970 static HRESULT WINAPI
datainit_CreateDBInstanceEx(IDataInitialize
*iface
, REFCLSID provider
, IUnknown
*outer
,
971 DWORD clsctx
, LPWSTR reserved
, COSERVERINFO
*server_info
, DWORD cmq
, MULTI_QI
*results
)
973 datainit
*This
= impl_from_IDataInitialize(iface
);
975 FIXME("(%p)->(%s %p %#lx %s %p %lu %p)\n", This
, debugstr_guid(provider
), outer
, clsctx
,
976 debugstr_w(reserved
), server_info
, cmq
, results
);
981 static HRESULT WINAPI
datainit_LoadStringFromStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
982 LPWSTR
*ppwszInitializationString
)
984 datainit
*This
= impl_from_IDataInitialize(iface
);
986 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(pwszFileName
), ppwszInitializationString
);
991 static HRESULT WINAPI
datainit_WriteStringToStorage(IDataInitialize
*iface
, LPWSTR pwszFileName
,
992 LPWSTR pwszInitializationString
, DWORD dwCreationDisposition
)
994 datainit
*This
= impl_from_IDataInitialize(iface
);
996 FIXME("(%p)->(%s %s %ld)\n", This
, debugstr_w(pwszFileName
), debugstr_w(pwszInitializationString
), dwCreationDisposition
);
1002 static const struct IDataInitializeVtbl datainit_vtbl
=
1004 datainit_QueryInterface
,
1007 datainit_GetDataSource
,
1008 datainit_GetInitializationString
,
1009 datainit_CreateDBInstance
,
1010 datainit_CreateDBInstanceEx
,
1011 datainit_LoadStringFromStorage
,
1012 datainit_WriteStringToStorage
1015 HRESULT
create_data_init(IUnknown
*outer
, void **obj
)
1019 TRACE("(%p)\n", obj
);
1021 if(outer
) return CLASS_E_NOAGGREGATION
;
1025 This
= malloc(sizeof(*This
));
1026 if(!This
) return E_OUTOFMEMORY
;
1028 This
->IDataInitialize_iface
.lpVtbl
= &datainit_vtbl
;
1031 *obj
= &This
->IDataInitialize_iface
;