1 /* OLE DB Conversion library
3 * Copyright 2009 Huw Davies
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
33 #include "oledb_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(oledb
);
41 IDataConvert IDataConvert_iface
;
42 IDCInfo IDCInfo_iface
;
46 UINT version
; /* Set by IDCInfo_SetInfo */
49 static inline convert
*impl_from_IDataConvert(IDataConvert
*iface
)
51 return CONTAINING_RECORD(iface
, convert
, IDataConvert_iface
);
54 static inline convert
*impl_from_IDCInfo(IDCInfo
*iface
)
56 return CONTAINING_RECORD(iface
, convert
, IDCInfo_iface
);
59 static HRESULT WINAPI
convert_QueryInterface(IDataConvert
* iface
,
63 convert
*This
= impl_from_IDataConvert(iface
);
64 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
68 if(IsEqualIID(riid
, &IID_IUnknown
) ||
69 IsEqualIID(riid
, &IID_IDataConvert
))
73 else if(IsEqualIID(riid
, &IID_IDCInfo
))
75 *obj
= &This
->IDCInfo_iface
;
79 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
83 IDataConvert_AddRef(iface
);
88 static ULONG WINAPI
convert_AddRef(IDataConvert
* iface
)
90 convert
*This
= impl_from_IDataConvert(iface
);
91 TRACE("(%p)\n", This
);
93 return InterlockedIncrement(&This
->ref
);
97 static ULONG WINAPI
convert_Release(IDataConvert
* iface
)
99 convert
*This
= impl_from_IDataConvert(iface
);
102 TRACE("(%p)\n", This
);
104 ref
= InterlockedDecrement(&This
->ref
);
111 static int get_length(DBTYPE type
)
122 return sizeof(VARIANT_BOOL
);
133 return sizeof(DBDATE
);
134 case DBTYPE_DBTIMESTAMP
:
135 return sizeof(DBTIMESTAMP
);
140 case DBTYPE_FILETIME
:
141 return sizeof(FILETIME
);
147 case DBTYPE_BYREF
| DBTYPE_WSTR
:
150 return sizeof(VARIANT
);
152 FIXME("Unhandled type %04x\n", type
);
157 static HRESULT WINAPI
convert_DataConvert(IDataConvert
* iface
,
158 DBTYPE src_type
, DBTYPE dst_type
,
159 DBLENGTH src_len
, DBLENGTH
*dst_len
,
160 void *src
, void *dst
,
161 DBLENGTH dst_max_len
,
162 DBSTATUS src_status
, DBSTATUS
*dst_status
,
163 BYTE precision
, BYTE scale
,
166 convert
*This
= impl_from_IDataConvert(iface
);
167 DBLENGTH dst_len_loc
;
168 DBSTATUS dst_status_loc
;
172 TRACE("(%p)->(%d, %d, %ld, %p, %p, %p, %ld, %d, %p, %d, %d, %x)\n", This
,
173 src_type
, dst_type
, src_len
, dst_len
, src
, dst
, dst_max_len
,
174 src_status
, dst_status
, precision
, scale
, flags
);
176 if (!dst_len
) dst_len
= &dst_len_loc
;
177 if (!dst_status
) dst_status
= &dst_status_loc
;
179 *dst_status
= DBSTATUS_E_BADACCESSOR
;
181 if(src_status
== DBSTATUS_S_ISNULL
)
183 *dst_status
= DBSTATUS_S_ISNULL
;
188 if(IDataConvert_CanConvert(iface
, src_type
, dst_type
) != S_OK
)
190 return DB_E_UNSUPPORTEDCONVERSION
;
193 if(dst
== NULL
&& get_length(dst_type
) != 0)
195 *dst_len
= get_length(src_type
);
196 *dst_status
= DBSTATUS_S_OK
;
200 if(src_type
== DBTYPE_STR
)
205 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
206 len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0) - 1;
208 len
= MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, NULL
, 0);
209 b
= SysAllocStringLen(NULL
, len
);
210 if(!b
) return E_OUTOFMEMORY
;
211 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
212 MultiByteToWideChar(CP_ACP
, 0, src
, -1, b
, len
+ 1);
214 MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, b
, len
);
216 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
217 &b
, dst
, dst_max_len
, src_status
, dst_status
,
218 precision
, scale
, flags
);
224 if(src_type
== DBTYPE_WSTR
)
228 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
229 b
= SysAllocString(src
);
231 b
= SysAllocStringLen(src
, src_len
/ 2);
232 if(!b
) return E_OUTOFMEMORY
;
233 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
234 &b
, dst
, dst_max_len
, src_status
, dst_status
,
235 precision
, scale
, flags
);
244 signed short *d
= dst
;
247 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
248 case DBTYPE_I2
: *d
= *(signed short*)src
; hr
= S_OK
; break;
249 case DBTYPE_I4
: hr
= VarI2FromI4(*(signed int*)src
, d
); break;
250 case DBTYPE_R4
: hr
= VarI2FromR4(*(FLOAT
*)src
, d
); break;
251 case DBTYPE_R8
: hr
= VarI2FromR8(*(double*)src
, d
); break;
252 case DBTYPE_CY
: hr
= VarI2FromCy(*(CY
*)src
, d
); break;
253 case DBTYPE_DATE
: hr
= VarI2FromDate(*(DATE
*)src
, d
); break;
254 case DBTYPE_BSTR
: hr
= VarI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
255 case DBTYPE_BOOL
: hr
= VarI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
256 case DBTYPE_DECIMAL
: hr
= VarI2FromDec((DECIMAL
*)src
, d
); break;
257 case DBTYPE_I1
: hr
= VarI2FromI1(*(signed char*)src
, d
); break;
258 case DBTYPE_UI1
: hr
= VarI2FromUI1(*(BYTE
*)src
, d
); break;
259 case DBTYPE_UI2
: hr
= VarI2FromUI2(*(WORD
*)src
, d
); break;
260 case DBTYPE_UI4
: hr
= VarI2FromUI4(*(DWORD
*)src
, d
); break;
261 case DBTYPE_I8
: hr
= VarI2FromI8(*(LONGLONG
*)src
, d
); break;
262 case DBTYPE_UI8
: hr
= VarI2FromUI8(*(ULONGLONG
*)src
, d
); break;
265 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_I2
)) == S_OK
)
268 default: FIXME("Unimplemented conversion %04x -> I2\n", src_type
); return E_NOTIMPL
;
278 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
279 case DBTYPE_I2
: hr
= VarI4FromI2(*(signed short*)src
, d
); break;
280 case DBTYPE_I4
: *d
= *(signed int*)src
; hr
= S_OK
; break;
281 case DBTYPE_R4
: hr
= VarI4FromR4(*(FLOAT
*)src
, d
); break;
282 case DBTYPE_R8
: hr
= VarI4FromR8(*(double*)src
, d
); break;
283 case DBTYPE_CY
: hr
= VarI4FromCy(*(CY
*)src
, d
); break;
284 case DBTYPE_DATE
: hr
= VarI4FromDate(*(DATE
*)src
, d
); break;
285 case DBTYPE_BSTR
: hr
= VarI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
286 case DBTYPE_BOOL
: hr
= VarI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
287 case DBTYPE_DECIMAL
: hr
= VarI4FromDec((DECIMAL
*)src
, d
); break;
288 case DBTYPE_I1
: hr
= VarI4FromI1(*(signed char*)src
, d
); break;
289 case DBTYPE_UI1
: hr
= VarI4FromUI1(*(BYTE
*)src
, d
); break;
290 case DBTYPE_UI2
: hr
= VarI4FromUI2(*(WORD
*)src
, d
); break;
291 case DBTYPE_UI4
: hr
= VarI4FromUI4(*(DWORD
*)src
, d
); break;
292 case DBTYPE_I8
: hr
= VarI4FromI8(*(LONGLONG
*)src
, d
); break;
293 case DBTYPE_UI8
: hr
= VarI4FromUI8(*(ULONGLONG
*)src
, d
); break;
296 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_I4
)) == S_OK
)
299 default: FIXME("Unimplemented conversion %04x -> I4\n", src_type
); return E_NOTIMPL
;
309 case DBTYPE_BSTR
: hr
= VarI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
310 case DBTYPE_I8
: *d
= *(LONGLONG
*)src
; hr
= S_OK
; break;
311 default: FIXME("Unimplemented conversion %04x -> I8\n", src_type
); return E_NOTIMPL
;
321 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
322 case DBTYPE_I2
: hr
= VarR4FromI2(*(signed short*)src
, d
); break;
323 case DBTYPE_I4
: hr
= VarR4FromI4(*(signed int*)src
, d
); break;
324 case DBTYPE_R4
: *d
= *(FLOAT
*)src
; hr
= S_OK
; break;
325 case DBTYPE_R8
: hr
= VarR4FromR8(*(double*)src
, d
); break;
326 case DBTYPE_CY
: hr
= VarR4FromCy(*(CY
*)src
, d
); break;
327 case DBTYPE_DATE
: hr
= VarR4FromDate(*(DATE
*)src
, d
); break;
328 case DBTYPE_BSTR
: hr
= VarR4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
329 case DBTYPE_BOOL
: hr
= VarR4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
330 case DBTYPE_DECIMAL
: hr
= VarR4FromDec((DECIMAL
*)src
, d
); break;
331 case DBTYPE_I1
: hr
= VarR4FromI1(*(signed char*)src
, d
); break;
332 case DBTYPE_UI1
: hr
= VarR4FromUI1(*(BYTE
*)src
, d
); break;
333 case DBTYPE_UI2
: hr
= VarR4FromUI2(*(WORD
*)src
, d
); break;
334 case DBTYPE_UI4
: hr
= VarR4FromUI4(*(DWORD
*)src
, d
); break;
335 case DBTYPE_I8
: hr
= VarR4FromI8(*(LONGLONG
*)src
, d
); break;
336 case DBTYPE_UI8
: hr
= VarR4FromUI8(*(ULONGLONG
*)src
, d
); break;
337 default: FIXME("Unimplemented conversion %04x -> R4\n", src_type
); return E_NOTIMPL
;
346 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
347 case DBTYPE_I1
: hr
= VarR8FromI1(*(signed char*)src
, d
); break;
348 case DBTYPE_I2
: hr
= VarR8FromI2(*(signed short*)src
, d
); break;
349 case DBTYPE_I4
: hr
= VarR8FromI4(*(signed int*)src
, d
); break;
350 case DBTYPE_I8
: hr
= VarR8FromI8(*(LONGLONG
*)src
, d
); break;
351 case DBTYPE_UI1
: hr
= VarR8FromUI1(*(BYTE
*)src
, d
); break;
352 case DBTYPE_UI2
: hr
= VarR8FromUI2(*(WORD
*)src
, d
); break;
353 case DBTYPE_UI4
: hr
= VarR8FromUI4(*(DWORD
*)src
, d
); break;
354 case DBTYPE_UI8
: hr
= VarR8FromUI8(*(ULONGLONG
*)src
, d
); break;
355 case DBTYPE_R4
: hr
= VarR8FromR4(*(FLOAT
*)src
, d
); break;
356 case DBTYPE_R8
: *d
= *(DOUBLE
*)src
; hr
= S_OK
; break;
357 case DBTYPE_CY
: hr
= VarR8FromCy(*(CY
*)src
, d
); break;
358 case DBTYPE_DATE
: hr
= VarR8FromDate(*(DATE
*)src
, d
); break;
359 case DBTYPE_BSTR
: hr
= VarR8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
360 case DBTYPE_BOOL
: hr
= VarR8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
361 case DBTYPE_DECIMAL
: hr
= VarR8FromDec((DECIMAL
*)src
, d
); break;
364 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_R8
)) == S_OK
)
367 default: FIXME("Unimplemented conversion %04x -> R8\n", src_type
); return E_NOTIMPL
;
376 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
377 case DBTYPE_I1
: hr
= VarBoolFromI1(*(signed char*)src
, d
); break;
378 case DBTYPE_I2
: hr
= VarBoolFromI2(*(signed short*)src
, d
); break;
379 case DBTYPE_I4
: hr
= VarBoolFromI4(*(signed int*)src
, d
); break;
380 case DBTYPE_I8
: hr
= VarBoolFromI8(*(LONGLONG
*)src
, d
); break;
381 case DBTYPE_UI1
: hr
= VarBoolFromUI1(*(BYTE
*)src
, d
); break;
382 case DBTYPE_UI2
: hr
= VarBoolFromUI2(*(WORD
*)src
, d
); break;
383 case DBTYPE_UI4
: hr
= VarBoolFromUI4(*(DWORD
*)src
, d
); break;
384 case DBTYPE_UI8
: hr
= VarBoolFromUI8(*(ULONGLONG
*)src
, d
); break;
385 case DBTYPE_R4
: hr
= VarBoolFromR4(*(FLOAT
*)src
, d
); break;
386 case DBTYPE_R8
: hr
= VarBoolFromR8(*(DOUBLE
*)src
, d
); break;
387 case DBTYPE_CY
: hr
= VarBoolFromCy(*(CY
*)src
, d
); break;
388 case DBTYPE_DATE
: hr
= VarBoolFromDate(*(DATE
*)src
, d
); break;
389 case DBTYPE_BSTR
: hr
= VarBoolFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
390 case DBTYPE_BOOL
: *d
= *(VARIANT_BOOL
*)src
; hr
= S_OK
; break;
391 case DBTYPE_DECIMAL
: hr
= VarBoolFromDec((DECIMAL
*)src
, d
); break;
392 default: FIXME("Unimplemented conversion %04x -> BOOL\n", src_type
); return E_NOTIMPL
;
401 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
402 case DBTYPE_I1
: hr
= VarDateFromI1(*(signed char*)src
, d
); break;
403 case DBTYPE_I2
: hr
= VarDateFromI2(*(signed short*)src
, d
); break;
404 case DBTYPE_I4
: hr
= VarDateFromI4(*(signed int*)src
, d
); break;
405 case DBTYPE_I8
: hr
= VarDateFromI8(*(LONGLONG
*)src
, d
); break;
406 case DBTYPE_UI1
: hr
= VarDateFromUI1(*(BYTE
*)src
, d
); break;
407 case DBTYPE_UI2
: hr
= VarDateFromUI2(*(WORD
*)src
, d
); break;
408 case DBTYPE_UI4
: hr
= VarDateFromUI4(*(DWORD
*)src
, d
); break;
409 case DBTYPE_UI8
: hr
= VarDateFromUI8(*(ULONGLONG
*)src
, d
); break;
410 case DBTYPE_R4
: hr
= VarDateFromR4(*(FLOAT
*)src
, d
); break;
411 case DBTYPE_R8
: hr
= VarDateFromR8(*(DOUBLE
*)src
, d
); break;
412 case DBTYPE_CY
: hr
= VarDateFromCy(*(CY
*)src
, d
); break;
413 case DBTYPE_DATE
: *d
= *(DATE
*)src
; hr
= S_OK
; break;
414 case DBTYPE_BSTR
: hr
= VarDateFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
415 case DBTYPE_BOOL
: hr
= VarDateFromBool(*(VARIANT_BOOL
*)src
, d
); break;
416 case DBTYPE_DECIMAL
: hr
= VarDateFromDec((DECIMAL
*)src
, d
); break;
417 case DBTYPE_DBTIMESTAMP
:
420 DBTIMESTAMP
*ts
=(DBTIMESTAMP
*)src
;
423 st
.wMonth
= ts
->month
;
426 st
.wMinute
= ts
->minute
;
427 st
.wSecond
= ts
->second
;
428 st
.wMilliseconds
= ts
->fraction
/1000000;
429 hr
= (SystemTimeToVariantTime(&st
, d
) ? S_OK
: E_FAIL
);
432 default: FIXME("Unimplemented conversion %04x -> DATE\n", src_type
); return E_NOTIMPL
;
441 case DBTYPE_DBDATE
: memcpy(d
, src
, sizeof(DBDATE
)); hr
= S_OK
; break;
445 BSTR s
= *(WCHAR
**)src
;
448 V_VT(&var
) = VT_BSTR
;
449 V_BSTR(&var
) = SysAllocString(s
);
451 if ((hr
= VariantChangeType(&var
, &var
, 0, VT_DATE
)) == S_OK
)
454 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
456 d
->month
= st
.wMonth
;
464 if( V_VT((VARIANT
*)src
) == VT_DATE
)
467 hr
= (VariantTimeToSystemTime( V_DATE((VARIANT
*)src
), &st
) ? S_OK
: E_FAIL
);
469 d
->month
= st
.wMonth
;
474 FIXME("Unimplemented variant type %d -> DBDATE\n", V_VT((VARIANT
*)src
));
478 default: FIXME("Unimplemented conversion %04x -> DBDATE\n", src_type
); return E_NOTIMPL
;
482 case DBTYPE_DBTIMESTAMP
:
487 case DBTYPE_EMPTY
: memset(d
, 0, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
488 case DBTYPE_DBTIMESTAMP
: memcpy(d
, src
, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
492 BSTR s
= *(WCHAR
**)src
;
495 V_VT(&var
) = VT_BSTR
;
496 V_BSTR(&var
) = SysAllocString(s
);
498 if ((hr
= VariantChangeType(&var
, &var
, 0, VT_DATE
)) == S_OK
)
502 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
504 d
->month
= st
.wMonth
;
507 d
->minute
= st
.wMinute
;
508 d
->second
= st
.wSecond
;
509 d
->fraction
= st
.wMilliseconds
* 1000000;
518 hr
= (VariantTimeToSystemTime(*(double*)src
, &st
) ? S_OK
: E_FAIL
);
520 d
->month
= st
.wMonth
;
523 d
->minute
= st
.wMinute
;
524 d
->second
= st
.wSecond
;
525 d
->fraction
= st
.wMilliseconds
* 1000000;
529 if( V_VT((VARIANT
*)src
) == VT_DATE
)
532 hr
= (VariantTimeToSystemTime( V_DATE((VARIANT
*)src
), &st
) ? S_OK
: E_FAIL
);
534 d
->month
= st
.wMonth
;
537 d
->minute
= st
.wMinute
;
538 d
->second
= st
.wSecond
;
539 d
->fraction
= st
.wMilliseconds
* 1000000;
543 FIXME("Unimplemented variant type %d -> DBTIMESTAMP\n", V_VT((VARIANT
*)src
));
547 default: FIXME("Unimplemented conversion %04x -> DBTIMESTAMP\n", src_type
); return E_NOTIMPL
;
557 case DBTYPE_EMPTY
: d
->int64
= 0; hr
= S_OK
; break;
558 case DBTYPE_I2
: hr
= VarCyFromI2(*(signed short*)src
, d
); break;
559 case DBTYPE_I4
: hr
= VarCyFromI4(*(signed int*)src
, d
); break;
560 case DBTYPE_R4
: hr
= VarCyFromR4(*(FLOAT
*)src
, d
); break;
561 case DBTYPE_R8
: hr
= VarCyFromR8(*(double*)src
, d
); break;
562 case DBTYPE_CY
: *d
= *(CY
*)src
; hr
= S_OK
; break;
563 case DBTYPE_DATE
: hr
= VarCyFromDate(*(DATE
*)src
, d
); break;
564 case DBTYPE_BSTR
: hr
= VarCyFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
565 case DBTYPE_BOOL
: hr
= VarCyFromBool(*(VARIANT_BOOL
*)src
, d
); break;
566 case DBTYPE_DECIMAL
: hr
= VarCyFromDec((DECIMAL
*)src
, d
); break;
567 case DBTYPE_I1
: hr
= VarCyFromI1(*(signed char*)src
, d
); break;
568 case DBTYPE_UI1
: hr
= VarCyFromUI1(*(BYTE
*)src
, d
); break;
569 case DBTYPE_UI2
: hr
= VarCyFromUI2(*(WORD
*)src
, d
); break;
570 case DBTYPE_UI4
: hr
= VarCyFromUI4(*(DWORD
*)src
, d
); break;
571 case DBTYPE_I8
: hr
= VarCyFromI8(*(LONGLONG
*)src
, d
); break;
572 case DBTYPE_UI8
: hr
= VarCyFromUI8(*(ULONGLONG
*)src
, d
); break;
573 default: FIXME("Unimplemented conversion %04x -> CY\n", src_type
); return E_NOTIMPL
;
583 case DBTYPE_EMPTY
: *d
= SysAllocStringLen(NULL
, 0); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
584 case DBTYPE_I2
: hr
= VarBstrFromI2(*(signed short*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
585 case DBTYPE_I4
: hr
= VarBstrFromI4(*(signed int*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
586 case DBTYPE_R4
: hr
= VarBstrFromR4(*(FLOAT
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
587 case DBTYPE_R8
: hr
= VarBstrFromR8(*(double*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
588 case DBTYPE_CY
: hr
= VarBstrFromCy(*(CY
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
589 case DBTYPE_DATE
: hr
= VarBstrFromDate(*(DATE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
590 case DBTYPE_BSTR
: *d
= SysAllocStringLen(*(BSTR
*)src
, SysStringLen(*(BSTR
*)src
)); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
591 case DBTYPE_BOOL
: hr
= VarBstrFromBool(*(VARIANT_BOOL
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
592 case DBTYPE_DECIMAL
: hr
= VarBstrFromDec((DECIMAL
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
593 case DBTYPE_I1
: hr
= VarBstrFromI1(*(signed char*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
594 case DBTYPE_UI1
: hr
= VarBstrFromUI1(*(BYTE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
595 case DBTYPE_UI2
: hr
= VarBstrFromUI2(*(WORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
596 case DBTYPE_UI4
: hr
= VarBstrFromUI4(*(DWORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
597 case DBTYPE_I8
: hr
= VarBstrFromI8(*(LONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
598 case DBTYPE_UI8
: hr
= VarBstrFromUI8(*(ULONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
602 const GUID
*id
= (const GUID
*)src
;
604 '{','%','0','8','X','-','%','0','4','X','-','%','0','4','X','-',
605 '%','0','2','X','%','0','2','X','-',
606 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','}',0};
607 wsprintfW(szBuff
, format
,
608 id
->Data1
, id
->Data2
, id
->Data3
,
609 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
610 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
611 *d
= SysAllocString(szBuff
);
612 hr
= *d
? S_OK
: E_OUTOFMEMORY
;
617 *d
= SysAllocStringLen(NULL
, 2 * src_len
);
622 const char hexchars
[] = "0123456789ABCDEF";
624 unsigned char *p
= src
;
627 *s
++ = hexchars
[(*p
>> 4) & 0x0F];
628 *s
++ = hexchars
[(*p
) & 0x0F];
636 if(V_VT((VARIANT
*)src
) == VT_NULL
)
638 *dst_status
= DBSTATUS_S_ISNULL
;
639 *dst_len
= get_length(DBTYPE_BSTR
);
645 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_BSTR
)) == S_OK
)
649 default: FIXME("Unimplemented conversion %04x -> BSTR\n", src_type
); return E_NOTIMPL
;
659 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
660 case DBTYPE_I2
: hr
= VarUI1FromI2(*(signed short*)src
, d
); break;
661 case DBTYPE_I4
: hr
= VarUI1FromI4(*(signed int*)src
, d
); break;
662 case DBTYPE_R4
: hr
= VarUI1FromR4(*(FLOAT
*)src
, d
); break;
663 case DBTYPE_R8
: hr
= VarUI1FromR8(*(double*)src
, d
); break;
664 case DBTYPE_CY
: hr
= VarUI1FromCy(*(CY
*)src
, d
); break;
665 case DBTYPE_DATE
: hr
= VarUI1FromDate(*(DATE
*)src
, d
); break;
666 case DBTYPE_BSTR
: hr
= VarUI1FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
667 case DBTYPE_BOOL
: hr
= VarUI1FromBool(*(VARIANT_BOOL
*)src
, d
); break;
668 case DBTYPE_DECIMAL
: hr
= VarUI1FromDec((DECIMAL
*)src
, d
); break;
669 case DBTYPE_I1
: hr
= VarUI1FromI1(*(signed char*)src
, d
); break;
670 case DBTYPE_UI1
: *d
= *(BYTE
*)src
; hr
= S_OK
; break;
671 case DBTYPE_UI2
: hr
= VarUI1FromUI2(*(WORD
*)src
, d
); break;
672 case DBTYPE_UI4
: hr
= VarUI1FromUI4(*(DWORD
*)src
, d
); break;
673 case DBTYPE_I8
: hr
= VarUI1FromI8(*(LONGLONG
*)src
, d
); break;
674 case DBTYPE_UI8
: hr
= VarUI1FromUI8(*(ULONGLONG
*)src
, d
); break;
675 default: FIXME("Unimplemented conversion %04x -> UI1\n", src_type
); return E_NOTIMPL
;
684 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
685 case DBTYPE_I2
: hr
= VarUI2FromI2(*(signed short*)src
, d
); break;
686 case DBTYPE_I4
: hr
= VarUI2FromI4(*(signed int*)src
, d
); break;
687 case DBTYPE_R4
: hr
= VarUI2FromR4(*(FLOAT
*)src
, d
); break;
688 case DBTYPE_R8
: hr
= VarUI2FromR8(*(double*)src
, d
); break;
689 case DBTYPE_CY
: hr
= VarUI2FromCy(*(CY
*)src
, d
); break;
690 case DBTYPE_DATE
: hr
= VarUI2FromDate(*(DATE
*)src
, d
); break;
691 case DBTYPE_BSTR
: hr
= VarUI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
692 case DBTYPE_BOOL
: hr
= VarUI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
693 case DBTYPE_DECIMAL
: hr
= VarUI2FromDec((DECIMAL
*)src
, d
); break;
694 case DBTYPE_I1
: hr
= VarUI2FromI1(*(signed char*)src
, d
); break;
695 case DBTYPE_UI1
: hr
= VarUI2FromUI1(*(BYTE
*)src
, d
); break;
696 case DBTYPE_UI2
: *d
= *(WORD
*)src
; hr
= S_OK
; break;
697 case DBTYPE_UI4
: hr
= VarUI2FromUI4(*(DWORD
*)src
, d
); break;
698 case DBTYPE_I8
: hr
= VarUI2FromI8(*(LONGLONG
*)src
, d
); break;
699 case DBTYPE_UI8
: hr
= VarUI2FromUI8(*(ULONGLONG
*)src
, d
); break;
700 default: FIXME("Unimplemented conversion %04x -> UI2\n", src_type
); return E_NOTIMPL
;
710 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
711 case DBTYPE_I2
: hr
= VarUI4FromI2(*(signed short*)src
, d
); break;
712 case DBTYPE_I4
: hr
= VarUI4FromI4(*(signed int*)src
, d
); break;
713 case DBTYPE_R4
: hr
= VarUI4FromR4(*(FLOAT
*)src
, d
); break;
714 case DBTYPE_R8
: hr
= VarUI4FromR8(*(double*)src
, d
); break;
715 case DBTYPE_CY
: hr
= VarUI4FromCy(*(CY
*)src
, d
); break;
716 case DBTYPE_DATE
: hr
= VarUI4FromDate(*(DATE
*)src
, d
); break;
717 case DBTYPE_BSTR
: hr
= VarUI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
718 case DBTYPE_BOOL
: hr
= VarUI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
719 case DBTYPE_DECIMAL
: hr
= VarUI4FromDec((DECIMAL
*)src
, d
); break;
720 case DBTYPE_I1
: hr
= VarUI4FromI1(*(signed char*)src
, d
); break;
721 case DBTYPE_UI1
: hr
= VarUI4FromUI1(*(BYTE
*)src
, d
); break;
722 case DBTYPE_UI2
: hr
= VarUI4FromUI2(*(WORD
*)src
, d
); break;
723 case DBTYPE_UI4
: *d
= *(DWORD
*)src
; hr
= S_OK
; break;
724 case DBTYPE_I8
: hr
= VarUI4FromI8(*(LONGLONG
*)src
, d
); break;
725 case DBTYPE_UI8
: hr
= VarUI4FromUI8(*(ULONGLONG
*)src
, d
); break;
728 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_UI4
)) == S_OK
)
731 default: FIXME("Unimplemented conversion %04x -> UI4\n", src_type
); return E_NOTIMPL
;
741 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
742 case DBTYPE_I2
: hr
= VarUI8FromI2(*(signed short*)src
, d
); break;
743 case DBTYPE_I4
: {LONGLONG s
= *(signed int*)src
; hr
= VarUI8FromI8(s
, d
); break;}
744 case DBTYPE_R4
: hr
= VarUI8FromR4(*(FLOAT
*)src
, d
); break;
745 case DBTYPE_R8
: hr
= VarUI8FromR8(*(double*)src
, d
); break;
746 case DBTYPE_CY
: hr
= VarUI8FromCy(*(CY
*)src
, d
); break;
747 case DBTYPE_DATE
: hr
= VarUI8FromDate(*(DATE
*)src
, d
); break;
748 case DBTYPE_BSTR
: hr
= VarUI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
749 case DBTYPE_BOOL
: hr
= VarUI8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
750 case DBTYPE_DECIMAL
: hr
= VarUI8FromDec((DECIMAL
*)src
, d
); break;
751 case DBTYPE_I1
: hr
= VarUI8FromI1(*(signed char*)src
, d
); break;
752 case DBTYPE_UI1
: hr
= VarUI8FromUI1(*(BYTE
*)src
, d
); break;
753 case DBTYPE_UI2
: hr
= VarUI8FromUI2(*(WORD
*)src
, d
); break;
754 case DBTYPE_UI4
: hr
= VarUI8FromUI4(*(DWORD
*)src
, d
); break;
755 case DBTYPE_I8
: hr
= VarUI8FromI8(*(LONGLONG
*)src
, d
); break;
756 case DBTYPE_UI8
: *d
= *(ULONGLONG
*)src
; hr
= S_OK
; break;
757 default: FIXME("Unimplemented conversion %04x -> UI8\n", src_type
); return E_NOTIMPL
;
762 case DBTYPE_FILETIME
:
767 case DBTYPE_EMPTY
: d
->dwLowDateTime
= d
->dwHighDateTime
= 0; hr
= S_OK
; break;
768 case DBTYPE_FILETIME
: *d
= *(FILETIME
*)src
; hr
= S_OK
; break;
769 default: FIXME("Unimplemented conversion %04x -> FILETIME\n", src_type
); return E_NOTIMPL
;
779 case DBTYPE_EMPTY
: *d
= GUID_NULL
; hr
= S_OK
; break;
780 case DBTYPE_GUID
: *d
= *(GUID
*)src
; hr
= S_OK
; break;
781 default: FIXME("Unimplemented conversion %04x -> GUID\n", src_type
); return E_NOTIMPL
;
791 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
792 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
793 precision
, scale
, flags
);
794 if(hr
!= S_OK
|| *dst_status
== DBSTATUS_S_ISNULL
)
796 bstr_len
= SysStringLen(b
);
797 *dst_len
= bstr_len
* sizeof(WCHAR
); /* Doesn't include size for '\0' */
798 *dst_status
= DBSTATUS_S_OK
;
799 bytes_to_copy
= min(*dst_len
+ sizeof(WCHAR
), dst_max_len
);
802 if(bytes_to_copy
>= sizeof(WCHAR
))
804 memcpy(dst
, b
, bytes_to_copy
- sizeof(WCHAR
));
805 *((WCHAR
*)dst
+ bytes_to_copy
/ sizeof(WCHAR
) - 1) = 0;
806 if(bytes_to_copy
< *dst_len
+ sizeof(WCHAR
))
807 *dst_status
= DBSTATUS_S_TRUNCATED
;
811 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
812 hr
= DB_E_ERRORSOCCURRED
;
823 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
824 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
825 precision
, scale
, flags
);
826 if(hr
!= S_OK
) return hr
;
827 bstr_len
= SysStringLen(b
);
828 *dst_len
= bstr_len
* sizeof(char); /* Doesn't include size for '\0' */
829 *dst_status
= DBSTATUS_S_OK
;
830 bytes_to_copy
= min(*dst_len
+ sizeof(char), dst_max_len
);
833 if(bytes_to_copy
>= sizeof(char))
835 WideCharToMultiByte(CP_ACP
, 0, b
, bytes_to_copy
- sizeof(char), dst
, dst_max_len
, NULL
, NULL
);
836 *((char *)dst
+ bytes_to_copy
/ sizeof(char) - 1) = 0;
837 if(bytes_to_copy
< *dst_len
+ sizeof(char))
838 *dst_status
= DBSTATUS_S_TRUNCATED
;
842 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
843 hr
= DB_E_ERRORSOCCURRED
;
850 case DBTYPE_BYREF
| DBTYPE_WSTR
:
855 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
856 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
857 precision
, scale
, flags
);
858 if(hr
!= S_OK
) return hr
;
860 bstr_len
= SysStringLen(b
) * sizeof(WCHAR
);
861 *dst_len
= bstr_len
; /* Doesn't include size for '\0' */
863 *d
= CoTaskMemAlloc(bstr_len
+ sizeof(WCHAR
));
864 if(*d
) memcpy(*d
, b
, bstr_len
+ sizeof(WCHAR
));
865 else hr
= E_OUTOFMEMORY
;
878 V_BOOL(v
) = *(VARIANT_BOOL
*)src
;
883 V_I2(v
) = *(signed short*)src
;
888 V_I4(v
) = *(signed int*)src
;
892 V_VT(v
) = VT_DECIMAL
;
893 hr
= VarDecFromI8( *(LONGLONG
*)src
, &V_DECIMAL(v
));
897 V_R4(v
) = *(FLOAT
*)src
;
902 V_R8(v
) = *(double*)src
;
907 BSTR s
= *(WCHAR
**)src
;
908 TRACE("%s\n", debugstr_w(s
));
910 V_BSTR(v
) = SysAllocString(s
);
911 hr
= V_BSTR(v
) ? S_OK
: E_OUTOFMEMORY
;
916 V_DATE(v
) = *(DATE
*)src
;
922 DBDATE
*ts
=(DBDATE
*)src
;
927 st
.wMonth
= ts
->month
;
932 st
.wMilliseconds
= 0;
933 hr
= (SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
);
936 case DBTYPE_DBTIMESTAMP
:
939 DBTIMESTAMP
*ts
= (DBTIMESTAMP
*)src
;
944 st
.wMonth
= ts
->month
;
947 st
.wMinute
= ts
->minute
;
948 st
.wSecond
= ts
->second
;
949 st
.wMilliseconds
= ts
->fraction
/1000000;
950 hr
= SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
;
961 SAFEARRAY
*psa
= NULL
;
962 SAFEARRAYBOUND rgsabound
[1];
963 unsigned char *p
= src
;
965 rgsabound
[0].lLbound
= 0;
966 rgsabound
[0].cElements
= src_len
;
968 psa
= SafeArrayCreate(VT_UI1
,1,rgsabound
);
969 for(i
=0; i
< src_len
; i
++,p
++)
971 hr
= SafeArrayPutElement(psa
, &i
, p
);
973 SafeArrayDestroy (psa
);
978 V_VT(v
) = VT_ARRAY
|VT_UI1
;
983 default: FIXME("Unimplemented conversion %04x -> VARIANT\n", src_type
); return E_NOTIMPL
;
994 if( src_len
> dst_max_len
)
995 *dst_status
= DBSTATUS_S_TRUNCATED
;
997 *dst_status
= DBSTATUS_S_OK
;
1000 memcpy(d
, src
, min(src_len
, dst_max_len
));
1003 case DBTYPE_VARIANT
:
1005 if(V_VT((VARIANT
*)src
) == VT_NULL
)
1007 *dst_status
= DBSTATUS_S_ISNULL
;
1013 switch(V_VT((VARIANT
*)src
))
1015 case VT_UI1
| VT_ARRAY
:
1020 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1024 hr
= SafeArrayAccessData(V_ARRAY((VARIANT
*)src
), (VOID
**)&data
);
1027 ERR("SafeArrayAccessData Failed = 0x%08x\n", hr
);
1032 *dst_status
= DBSTATUS_S_OK
;
1033 memcpy(d
, data
, *dst_len
);
1035 SafeArrayUnaccessData(V_ARRAY((VARIANT
*)src
));
1040 FIXME("Unimplemented variant type %d -> BYTES\n", V_VT((VARIANT
*)src
));
1046 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES\n", src_type
); return E_NOTIMPL
;
1050 case DBTYPE_BYTES
| DBTYPE_BYREF
:
1057 *d
= CoTaskMemAlloc(src_len
);
1058 if(*d
) memcpy(*d
, src
, src_len
);
1059 else hr
= E_OUTOFMEMORY
;
1062 *dst_status
= DBSTATUS_S_OK
;
1064 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES | DBTYPE_BYREF\n", src_type
); return E_NOTIMPL
;
1071 FIXME("Unimplemented conversion %04x -> %04x\n", src_type
, dst_type
);
1075 if(hr
== DISP_E_OVERFLOW
)
1077 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
1078 *dst_len
= get_length(dst_type
);
1079 hr
= DB_E_ERRORSOCCURRED
;
1083 *dst_status
= DBSTATUS_S_OK
;
1084 *dst_len
= get_length(dst_type
);
1090 static inline WORD
get_dbtype_class(DBTYPE type
)
1117 case DBTYPE_DBTIMESTAMP
:
1118 return DBTYPE_DBDATE
;
1123 /* Many src types will convert to this group of dst types */
1124 static inline BOOL
common_class(WORD dst_class
)
1134 case DBTYPE_VARIANT
:
1137 case DBTYPE_DECIMAL
:
1138 case DBTYPE_NUMERIC
:
1144 static inline BOOL
array_type(DBTYPE type
)
1146 return (type
>= DBTYPE_I2
&& type
<= DBTYPE_UI4
);
1149 static HRESULT WINAPI
convert_CanConvert(IDataConvert
* iface
,
1150 DBTYPE src_type
, DBTYPE dst_type
)
1152 convert
*This
= impl_from_IDataConvert(iface
);
1153 DBTYPE src_base_type
= src_type
& 0x1ff;
1154 DBTYPE dst_base_type
= dst_type
& 0x1ff;
1155 WORD dst_class
= get_dbtype_class(dst_base_type
);
1157 TRACE("(%p)->(%d, %d)\n", This
, src_type
, dst_type
);
1159 if(src_type
& DBTYPE_VECTOR
|| dst_type
& DBTYPE_VECTOR
) return S_FALSE
;
1161 if(src_type
& DBTYPE_ARRAY
)
1163 if(!array_type(src_base_type
)) return S_FALSE
;
1164 if(dst_type
& DBTYPE_ARRAY
)
1166 if(src_type
== dst_type
) return S_OK
;
1169 if(dst_type
== DBTYPE_VARIANT
) return S_OK
;
1173 if(dst_type
& DBTYPE_ARRAY
)
1175 if(!array_type(dst_base_type
)) return S_FALSE
;
1176 if(src_type
== DBTYPE_IDISPATCH
|| src_type
== DBTYPE_VARIANT
) return S_OK
;
1180 if(dst_type
& DBTYPE_BYREF
)
1181 if(dst_base_type
!= DBTYPE_BYTES
&& dst_base_type
!= DBTYPE_STR
&& dst_base_type
!= DBTYPE_WSTR
)
1184 switch(get_dbtype_class(src_base_type
))
1187 if(common_class(dst_class
)) return S_OK
;
1192 case DBTYPE_FILETIME
:
1195 if(dst_base_type
== DBTYPE_DBTIMESTAMP
) return S_OK
;
1200 switch(dst_base_type
)
1203 case DBTYPE_VARIANT
:
1204 case DBTYPE_FILETIME
: return S_OK
;
1205 default: return S_FALSE
;
1209 if(dst_base_type
== DBTYPE_BYTES
) return S_OK
;
1212 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1214 case DBTYPE_DECIMAL
:
1215 if(common_class(dst_class
)) return S_OK
;
1216 if(dst_class
== DBTYPE_DBDATE
) return S_OK
;
1220 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1222 case DBTYPE_NUMERIC
:
1224 if(common_class(dst_class
)) return S_OK
;
1228 if(common_class(dst_class
)) return S_OK
;
1229 switch(dst_base_type
)
1232 case DBTYPE_FILETIME
: return S_OK
;
1233 default: return S_FALSE
;
1245 case DBTYPE_VARIANT
:
1249 case DBTYPE_FILETIME
:
1251 default: return S_FALSE
;
1254 case DBTYPE_IDISPATCH
:
1255 case DBTYPE_VARIANT
:
1256 switch(dst_base_type
)
1258 case DBTYPE_IDISPATCH
:
1260 case DBTYPE_IUNKNOWN
:
1265 if(common_class(dst_class
)) return S_OK
;
1272 case DBTYPE_FILETIME
:
1274 default: return S_FALSE
;
1278 switch(dst_base_type
)
1282 case DBTYPE_VARIANT
:
1285 default: return S_FALSE
;
1288 case DBTYPE_IUNKNOWN
:
1289 switch(dst_base_type
)
1293 case DBTYPE_IDISPATCH
:
1294 case DBTYPE_VARIANT
:
1295 case DBTYPE_IUNKNOWN
:
1297 default: return S_FALSE
;
1301 if(dst_class
== DBTYPE_I4
|| dst_class
== DBTYPE_I8
) return S_OK
;
1309 case DBTYPE_VARIANT
:
1313 default: return S_FALSE
;
1316 case DBTYPE_FILETIME
:
1317 if(dst_class
== DBTYPE_I8
) return S_OK
;
1326 case DBTYPE_VARIANT
:
1328 case DBTYPE_FILETIME
:
1330 default: return S_FALSE
;
1337 static HRESULT WINAPI
convert_GetConversionSize(IDataConvert
* iface
,
1338 DBTYPE src_type
, DBTYPE dst_type
,
1339 DBLENGTH
*src_len
, DBLENGTH
*dst_len
,
1342 convert
*This
= impl_from_IDataConvert(iface
);
1345 TRACE("(%p)->(%d, %d, %p, %p, %p)\n", This
, src_type
, dst_type
, src_len
, dst_len
, src
);
1347 hr
= IDataConvert_CanConvert(iface
, src_type
, dst_type
);
1349 return DB_E_UNSUPPORTEDCONVERSION
;
1352 return E_INVALIDARG
;
1354 /* for some types we don't need to look into source data */
1355 if ((*dst_len
= get_length(dst_type
)))
1363 case DBTYPE_VARIANT
:
1368 if ((hr
= VariantChangeType(&v
, (VARIANT
*)src
, 0, VT_BSTR
)) == S_OK
)
1370 *dst_len
= WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), -1, NULL
, 0, NULL
, NULL
);
1378 FIXME("unimplemented for %04x -> DBTYPE_STR\n", src_type
);
1385 case DBTYPE_VARIANT
:
1386 if(V_VT((VARIANT
*)src
) == VT_BSTR
)
1387 *dst_len
= (SysStringLen(V_BSTR((VARIANT
*)src
))+1) * sizeof(WCHAR
);
1389 WARN("DBTYPE_VARIANT(%d)->DBTYPE_WSTR unimplemented\n", V_VT((VARIANT
*)src
));
1393 *dst_len
= (*src_len
+ 1) * sizeof(WCHAR
);
1395 *dst_len
= (strlen(src
) + 1) * sizeof(WCHAR
);
1399 *dst_len
= (*src_len
) + sizeof(WCHAR
);
1401 *dst_len
= (lstrlenW(src
) + 1) * sizeof(WCHAR
);
1404 FIXME("unimplemented for %04x -> DBTYPE_WSTR\n", src_type
);
1411 case DBTYPE_VARIANT
:
1412 if(V_VT((VARIANT
*)src
) == VT_BSTR
)
1413 *dst_len
= (SysStringLen(V_BSTR((VARIANT
*)src
))) / sizeof(WCHAR
);
1416 switch(V_VT((VARIANT
*)src
))
1418 case VT_UI1
| VT_ARRAY
:
1422 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1430 WARN("DBTYPE_VARIANT(%d)->DBTYPE_BYTES unimplemented\n", V_VT((VARIANT
*)src
));
1435 FIXME("unimplemented for %04x -> DBTYPE_BYTES\n", src_type
);
1440 FIXME("unimplemented for conversion %d->%d\n", src_type
, dst_type
);
1447 static const struct IDataConvertVtbl convert_vtbl
=
1449 convert_QueryInterface
,
1452 convert_DataConvert
,
1454 convert_GetConversionSize
1457 static HRESULT WINAPI
dcinfo_QueryInterface(IDCInfo
* iface
, REFIID riid
, void **obj
)
1459 convert
*This
= impl_from_IDCInfo(iface
);
1461 return IDataConvert_QueryInterface(&This
->IDataConvert_iface
, riid
, obj
);
1464 static ULONG WINAPI
dcinfo_AddRef(IDCInfo
* iface
)
1466 convert
*This
= impl_from_IDCInfo(iface
);
1468 return IDataConvert_AddRef(&This
->IDataConvert_iface
);
1471 static ULONG WINAPI
dcinfo_Release(IDCInfo
* iface
)
1473 convert
*This
= impl_from_IDCInfo(iface
);
1475 return IDataConvert_Release(&This
->IDataConvert_iface
);
1478 static HRESULT WINAPI
dcinfo_GetInfo(IDCInfo
*iface
, ULONG num
, DCINFOTYPE types
[], DCINFO
**info_ptr
)
1480 convert
*This
= impl_from_IDCInfo(iface
);
1484 TRACE("(%p)->(%d, %p, %p)\n", This
, num
, types
, info_ptr
);
1486 *info_ptr
= infos
= CoTaskMemAlloc(num
* sizeof(*infos
));
1487 if(!infos
) return E_OUTOFMEMORY
;
1489 for(i
= 0; i
< num
; i
++)
1491 infos
[i
].eInfoType
= types
[i
];
1492 VariantInit(&infos
[i
].vData
);
1496 case DCINFOTYPE_VERSION
:
1497 V_VT(&infos
[i
].vData
) = VT_UI4
;
1498 V_UI4(&infos
[i
].vData
) = This
->version
;
1506 static HRESULT WINAPI
dcinfo_SetInfo(IDCInfo
* iface
, ULONG num
, DCINFO info
[])
1508 convert
*This
= impl_from_IDCInfo(iface
);
1512 TRACE("(%p)->(%d, %p)\n", This
, num
, info
);
1514 for(i
= 0; i
< num
; i
++)
1516 switch(info
[i
].eInfoType
)
1518 case DCINFOTYPE_VERSION
:
1519 if(V_VT(&info
[i
].vData
) != VT_UI4
)
1521 FIXME("VERSION with vt %x\n", V_VT(&info
[i
].vData
));
1522 hr
= DB_S_ERRORSOCCURRED
;
1525 This
->version
= V_UI4(&info
[i
].vData
);
1529 FIXME("Unhandled info type %d (vt %x)\n", info
[i
].eInfoType
, V_VT(&info
[i
].vData
));
1535 static const struct IDCInfoVtbl dcinfo_vtbl
=
1537 dcinfo_QueryInterface
,
1544 HRESULT
create_oledb_convert(IUnknown
*outer
, void **obj
)
1548 TRACE("(%p, %p)\n", outer
, obj
);
1552 if(outer
) return CLASS_E_NOAGGREGATION
;
1554 This
= heap_alloc(sizeof(*This
));
1555 if(!This
) return E_OUTOFMEMORY
;
1557 This
->IDataConvert_iface
.lpVtbl
= &convert_vtbl
;
1558 This
->IDCInfo_iface
.lpVtbl
= &dcinfo_vtbl
;
1560 This
->version
= 0x110;
1562 *obj
= &This
->IDataConvert_iface
;