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
31 #include "oledb_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(oledb
);
39 IDataConvert IDataConvert_iface
;
40 IDCInfo IDCInfo_iface
;
44 UINT version
; /* Set by IDCInfo_SetInfo */
47 static inline convert
*impl_from_IDataConvert(IDataConvert
*iface
)
49 return CONTAINING_RECORD(iface
, convert
, IDataConvert_iface
);
52 static inline convert
*impl_from_IDCInfo(IDCInfo
*iface
)
54 return CONTAINING_RECORD(iface
, convert
, IDCInfo_iface
);
57 static HRESULT WINAPI
convert_QueryInterface(IDataConvert
* iface
,
61 convert
*This
= impl_from_IDataConvert(iface
);
62 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
66 if(IsEqualIID(riid
, &IID_IUnknown
) ||
67 IsEqualIID(riid
, &IID_IDataConvert
))
71 else if(IsEqualIID(riid
, &IID_IDCInfo
))
73 *obj
= &This
->IDCInfo_iface
;
77 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
81 IDataConvert_AddRef(iface
);
86 static ULONG WINAPI
convert_AddRef(IDataConvert
* iface
)
88 convert
*This
= impl_from_IDataConvert(iface
);
89 TRACE("(%p)\n", This
);
91 return InterlockedIncrement(&This
->ref
);
95 static ULONG WINAPI
convert_Release(IDataConvert
* iface
)
97 convert
*This
= impl_from_IDataConvert(iface
);
100 TRACE("(%p)\n", This
);
102 ref
= InterlockedDecrement(&This
->ref
);
109 static int get_length(DBTYPE type
)
120 return sizeof(VARIANT_BOOL
);
131 return sizeof(DBDATE
);
132 case DBTYPE_DBTIMESTAMP
:
133 return sizeof(DBTIMESTAMP
);
138 case DBTYPE_FILETIME
:
139 return sizeof(FILETIME
);
145 case DBTYPE_BYREF
| DBTYPE_WSTR
:
148 return sizeof(VARIANT
);
150 FIXME("Unhandled type %04x\n", type
);
155 static HRESULT WINAPI
convert_DataConvert(IDataConvert
* iface
,
156 DBTYPE src_type
, DBTYPE dst_type
,
157 DBLENGTH src_len
, DBLENGTH
*dst_len
,
158 void *src
, void *dst
,
159 DBLENGTH dst_max_len
,
160 DBSTATUS src_status
, DBSTATUS
*dst_status
,
161 BYTE precision
, BYTE scale
,
164 convert
*This
= impl_from_IDataConvert(iface
);
165 DBLENGTH dst_len_loc
;
166 DBSTATUS dst_status_loc
;
170 TRACE("(%p)->(%d, %d, %ld, %p, %p, %p, %ld, %d, %p, %d, %d, %x)\n", This
,
171 src_type
, dst_type
, src_len
, dst_len
, src
, dst
, dst_max_len
,
172 src_status
, dst_status
, precision
, scale
, flags
);
174 if (!dst_len
) dst_len
= &dst_len_loc
;
175 if (!dst_status
) dst_status
= &dst_status_loc
;
177 *dst_status
= DBSTATUS_E_BADACCESSOR
;
179 if(src_status
== DBSTATUS_S_ISNULL
)
181 *dst_status
= DBSTATUS_S_ISNULL
;
186 if(src_type
== DBTYPE_VARIANT
&& V_VT((VARIANT
*)src
) == VT_NULL
)
188 if(dst_type
== DBTYPE_VARIANT
)
189 *dst_len
= sizeof(VARIANT
);
191 *dst_status
= DBSTATUS_S_ISNULL
;
195 if(IDataConvert_CanConvert(iface
, src_type
, dst_type
) != S_OK
)
197 return DB_E_UNSUPPORTEDCONVERSION
;
200 if(dst
== NULL
&& get_length(dst_type
) != 0)
202 *dst_len
= get_length(src_type
);
203 *dst_status
= DBSTATUS_S_OK
;
207 if(src_type
== DBTYPE_STR
)
212 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
213 len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0) - 1;
215 len
= MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, NULL
, 0);
216 b
= SysAllocStringLen(NULL
, len
);
217 if(!b
) return E_OUTOFMEMORY
;
218 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
219 MultiByteToWideChar(CP_ACP
, 0, src
, -1, b
, len
+ 1);
221 MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, b
, len
);
223 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
224 &b
, dst
, dst_max_len
, src_status
, dst_status
,
225 precision
, scale
, flags
);
231 if(src_type
== DBTYPE_WSTR
)
235 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
236 b
= SysAllocString(src
);
238 b
= SysAllocStringLen(src
, src_len
/ 2);
239 if(!b
) return E_OUTOFMEMORY
;
240 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
241 &b
, dst
, dst_max_len
, src_status
, dst_status
,
242 precision
, scale
, flags
);
251 signed short *d
= dst
;
254 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
255 case DBTYPE_I2
: *d
= *(signed short*)src
; hr
= S_OK
; break;
256 case DBTYPE_I4
: hr
= VarI2FromI4(*(signed int*)src
, d
); break;
257 case DBTYPE_R4
: hr
= VarI2FromR4(*(FLOAT
*)src
, d
); break;
258 case DBTYPE_R8
: hr
= VarI2FromR8(*(double*)src
, d
); break;
259 case DBTYPE_CY
: hr
= VarI2FromCy(*(CY
*)src
, d
); break;
260 case DBTYPE_DATE
: hr
= VarI2FromDate(*(DATE
*)src
, d
); break;
261 case DBTYPE_BSTR
: hr
= VarI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
262 case DBTYPE_BOOL
: hr
= VarI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
263 case DBTYPE_DECIMAL
: hr
= VarI2FromDec((DECIMAL
*)src
, d
); break;
264 case DBTYPE_I1
: hr
= VarI2FromI1(*(signed char*)src
, d
); break;
265 case DBTYPE_UI1
: hr
= VarI2FromUI1(*(BYTE
*)src
, d
); break;
266 case DBTYPE_UI2
: hr
= VarI2FromUI2(*(WORD
*)src
, d
); break;
267 case DBTYPE_UI4
: hr
= VarI2FromUI4(*(DWORD
*)src
, d
); break;
268 case DBTYPE_I8
: hr
= VarI2FromI8(*(LONGLONG
*)src
, d
); break;
269 case DBTYPE_UI8
: hr
= VarI2FromUI8(*(ULONGLONG
*)src
, d
); break;
272 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_I2
)) == S_OK
)
275 default: FIXME("Unimplemented conversion %04x -> I2\n", src_type
); return E_NOTIMPL
;
285 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
286 case DBTYPE_I2
: hr
= VarI4FromI2(*(signed short*)src
, d
); break;
287 case DBTYPE_I4
: *d
= *(signed int*)src
; hr
= S_OK
; break;
288 case DBTYPE_R4
: hr
= VarI4FromR4(*(FLOAT
*)src
, d
); break;
289 case DBTYPE_R8
: hr
= VarI4FromR8(*(double*)src
, d
); break;
290 case DBTYPE_CY
: hr
= VarI4FromCy(*(CY
*)src
, d
); break;
291 case DBTYPE_DATE
: hr
= VarI4FromDate(*(DATE
*)src
, d
); break;
292 case DBTYPE_BSTR
: hr
= VarI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
293 case DBTYPE_BOOL
: hr
= VarI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
294 case DBTYPE_DECIMAL
: hr
= VarI4FromDec((DECIMAL
*)src
, d
); break;
295 case DBTYPE_I1
: hr
= VarI4FromI1(*(signed char*)src
, d
); break;
296 case DBTYPE_UI1
: hr
= VarI4FromUI1(*(BYTE
*)src
, d
); break;
297 case DBTYPE_UI2
: hr
= VarI4FromUI2(*(WORD
*)src
, d
); break;
298 case DBTYPE_UI4
: hr
= VarI4FromUI4(*(DWORD
*)src
, d
); break;
299 case DBTYPE_I8
: hr
= VarI4FromI8(*(LONGLONG
*)src
, d
); break;
300 case DBTYPE_UI8
: hr
= VarI4FromUI8(*(ULONGLONG
*)src
, d
); break;
303 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_I4
)) == S_OK
)
306 default: FIXME("Unimplemented conversion %04x -> I4\n", src_type
); return E_NOTIMPL
;
316 case DBTYPE_BSTR
: hr
= VarI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
317 case DBTYPE_I8
: *d
= *(LONGLONG
*)src
; hr
= S_OK
; break;
318 default: FIXME("Unimplemented conversion %04x -> I8\n", src_type
); return E_NOTIMPL
;
328 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
329 case DBTYPE_I2
: hr
= VarR4FromI2(*(signed short*)src
, d
); break;
330 case DBTYPE_I4
: hr
= VarR4FromI4(*(signed int*)src
, d
); break;
331 case DBTYPE_R4
: *d
= *(FLOAT
*)src
; hr
= S_OK
; break;
332 case DBTYPE_R8
: hr
= VarR4FromR8(*(double*)src
, d
); break;
333 case DBTYPE_CY
: hr
= VarR4FromCy(*(CY
*)src
, d
); break;
334 case DBTYPE_DATE
: hr
= VarR4FromDate(*(DATE
*)src
, d
); break;
335 case DBTYPE_BSTR
: hr
= VarR4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
336 case DBTYPE_BOOL
: hr
= VarR4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
337 case DBTYPE_DECIMAL
: hr
= VarR4FromDec((DECIMAL
*)src
, d
); break;
338 case DBTYPE_I1
: hr
= VarR4FromI1(*(signed char*)src
, d
); break;
339 case DBTYPE_UI1
: hr
= VarR4FromUI1(*(BYTE
*)src
, d
); break;
340 case DBTYPE_UI2
: hr
= VarR4FromUI2(*(WORD
*)src
, d
); break;
341 case DBTYPE_UI4
: hr
= VarR4FromUI4(*(DWORD
*)src
, d
); break;
342 case DBTYPE_I8
: hr
= VarR4FromI8(*(LONGLONG
*)src
, d
); break;
343 case DBTYPE_UI8
: hr
= VarR4FromUI8(*(ULONGLONG
*)src
, d
); break;
344 default: FIXME("Unimplemented conversion %04x -> R4\n", src_type
); return E_NOTIMPL
;
353 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
354 case DBTYPE_I1
: hr
= VarR8FromI1(*(signed char*)src
, d
); break;
355 case DBTYPE_I2
: hr
= VarR8FromI2(*(signed short*)src
, d
); break;
356 case DBTYPE_I4
: hr
= VarR8FromI4(*(signed int*)src
, d
); break;
357 case DBTYPE_I8
: hr
= VarR8FromI8(*(LONGLONG
*)src
, d
); break;
358 case DBTYPE_UI1
: hr
= VarR8FromUI1(*(BYTE
*)src
, d
); break;
359 case DBTYPE_UI2
: hr
= VarR8FromUI2(*(WORD
*)src
, d
); break;
360 case DBTYPE_UI4
: hr
= VarR8FromUI4(*(DWORD
*)src
, d
); break;
361 case DBTYPE_UI8
: hr
= VarR8FromUI8(*(ULONGLONG
*)src
, d
); break;
362 case DBTYPE_R4
: hr
= VarR8FromR4(*(FLOAT
*)src
, d
); break;
363 case DBTYPE_R8
: *d
= *(DOUBLE
*)src
; hr
= S_OK
; break;
364 case DBTYPE_CY
: hr
= VarR8FromCy(*(CY
*)src
, d
); break;
365 case DBTYPE_DATE
: hr
= VarR8FromDate(*(DATE
*)src
, d
); break;
366 case DBTYPE_BSTR
: hr
= VarR8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
367 case DBTYPE_BOOL
: hr
= VarR8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
368 case DBTYPE_DECIMAL
: hr
= VarR8FromDec((DECIMAL
*)src
, d
); break;
371 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_R8
)) == S_OK
)
374 default: FIXME("Unimplemented conversion %04x -> R8\n", src_type
); return E_NOTIMPL
;
383 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
384 case DBTYPE_I1
: hr
= VarBoolFromI1(*(signed char*)src
, d
); break;
385 case DBTYPE_I2
: hr
= VarBoolFromI2(*(signed short*)src
, d
); break;
386 case DBTYPE_I4
: hr
= VarBoolFromI4(*(signed int*)src
, d
); break;
387 case DBTYPE_I8
: hr
= VarBoolFromI8(*(LONGLONG
*)src
, d
); break;
388 case DBTYPE_UI1
: hr
= VarBoolFromUI1(*(BYTE
*)src
, d
); break;
389 case DBTYPE_UI2
: hr
= VarBoolFromUI2(*(WORD
*)src
, d
); break;
390 case DBTYPE_UI4
: hr
= VarBoolFromUI4(*(DWORD
*)src
, d
); break;
391 case DBTYPE_UI8
: hr
= VarBoolFromUI8(*(ULONGLONG
*)src
, d
); break;
392 case DBTYPE_R4
: hr
= VarBoolFromR4(*(FLOAT
*)src
, d
); break;
393 case DBTYPE_R8
: hr
= VarBoolFromR8(*(DOUBLE
*)src
, d
); break;
394 case DBTYPE_CY
: hr
= VarBoolFromCy(*(CY
*)src
, d
); break;
395 case DBTYPE_DATE
: hr
= VarBoolFromDate(*(DATE
*)src
, d
); break;
396 case DBTYPE_BSTR
: hr
= VarBoolFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
397 case DBTYPE_BOOL
: *d
= *(VARIANT_BOOL
*)src
; hr
= S_OK
; break;
398 case DBTYPE_DECIMAL
: hr
= VarBoolFromDec((DECIMAL
*)src
, d
); break;
399 default: FIXME("Unimplemented conversion %04x -> BOOL\n", src_type
); return E_NOTIMPL
;
408 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
409 case DBTYPE_I1
: hr
= VarDateFromI1(*(signed char*)src
, d
); break;
410 case DBTYPE_I2
: hr
= VarDateFromI2(*(signed short*)src
, d
); break;
411 case DBTYPE_I4
: hr
= VarDateFromI4(*(signed int*)src
, d
); break;
412 case DBTYPE_I8
: hr
= VarDateFromI8(*(LONGLONG
*)src
, d
); break;
413 case DBTYPE_UI1
: hr
= VarDateFromUI1(*(BYTE
*)src
, d
); break;
414 case DBTYPE_UI2
: hr
= VarDateFromUI2(*(WORD
*)src
, d
); break;
415 case DBTYPE_UI4
: hr
= VarDateFromUI4(*(DWORD
*)src
, d
); break;
416 case DBTYPE_UI8
: hr
= VarDateFromUI8(*(ULONGLONG
*)src
, d
); break;
417 case DBTYPE_R4
: hr
= VarDateFromR4(*(FLOAT
*)src
, d
); break;
418 case DBTYPE_R8
: hr
= VarDateFromR8(*(DOUBLE
*)src
, d
); break;
419 case DBTYPE_CY
: hr
= VarDateFromCy(*(CY
*)src
, d
); break;
420 case DBTYPE_DATE
: *d
= *(DATE
*)src
; hr
= S_OK
; break;
421 case DBTYPE_BSTR
: hr
= VarDateFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
422 case DBTYPE_BOOL
: hr
= VarDateFromBool(*(VARIANT_BOOL
*)src
, d
); break;
423 case DBTYPE_DECIMAL
: hr
= VarDateFromDec((DECIMAL
*)src
, d
); break;
424 case DBTYPE_DBTIMESTAMP
:
427 DBTIMESTAMP
*ts
=(DBTIMESTAMP
*)src
;
430 st
.wMonth
= ts
->month
;
433 st
.wMinute
= ts
->minute
;
434 st
.wSecond
= ts
->second
;
435 st
.wMilliseconds
= ts
->fraction
/1000000;
436 hr
= (SystemTimeToVariantTime(&st
, d
) ? S_OK
: E_FAIL
);
439 default: FIXME("Unimplemented conversion %04x -> DATE\n", src_type
); return E_NOTIMPL
;
448 case DBTYPE_DBDATE
: memcpy(d
, src
, sizeof(DBDATE
)); hr
= S_OK
; break;
452 BSTR s
= *(WCHAR
**)src
;
455 V_VT(&var
) = VT_BSTR
;
456 V_BSTR(&var
) = SysAllocString(s
);
458 if ((hr
= VariantChangeType(&var
, &var
, 0, VT_DATE
)) == S_OK
)
461 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
463 d
->month
= st
.wMonth
;
471 if( V_VT((VARIANT
*)src
) == VT_DATE
)
474 hr
= (VariantTimeToSystemTime( V_DATE((VARIANT
*)src
), &st
) ? S_OK
: E_FAIL
);
476 d
->month
= st
.wMonth
;
481 FIXME("Unimplemented variant type %d -> DBDATE\n", V_VT((VARIANT
*)src
));
485 default: FIXME("Unimplemented conversion %04x -> DBDATE\n", src_type
); return E_NOTIMPL
;
489 case DBTYPE_DBTIMESTAMP
:
494 case DBTYPE_EMPTY
: memset(d
, 0, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
495 case DBTYPE_DBTIMESTAMP
: memcpy(d
, src
, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
499 BSTR s
= *(WCHAR
**)src
;
502 V_VT(&var
) = VT_BSTR
;
503 V_BSTR(&var
) = SysAllocString(s
);
505 if ((hr
= VariantChangeType(&var
, &var
, 0, VT_DATE
)) == S_OK
)
509 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
511 d
->month
= st
.wMonth
;
514 d
->minute
= st
.wMinute
;
515 d
->second
= st
.wSecond
;
516 d
->fraction
= st
.wMilliseconds
* 1000000;
525 hr
= (VariantTimeToSystemTime(*(double*)src
, &st
) ? S_OK
: E_FAIL
);
527 d
->month
= st
.wMonth
;
530 d
->minute
= st
.wMinute
;
531 d
->second
= st
.wSecond
;
532 d
->fraction
= st
.wMilliseconds
* 1000000;
536 if( V_VT((VARIANT
*)src
) == VT_DATE
)
539 hr
= (VariantTimeToSystemTime( V_DATE((VARIANT
*)src
), &st
) ? S_OK
: E_FAIL
);
541 d
->month
= st
.wMonth
;
544 d
->minute
= st
.wMinute
;
545 d
->second
= st
.wSecond
;
546 d
->fraction
= st
.wMilliseconds
* 1000000;
550 FIXME("Unimplemented variant type %d -> DBTIMESTAMP\n", V_VT((VARIANT
*)src
));
554 default: FIXME("Unimplemented conversion %04x -> DBTIMESTAMP\n", src_type
); return E_NOTIMPL
;
564 case DBTYPE_EMPTY
: d
->int64
= 0; hr
= S_OK
; break;
565 case DBTYPE_I2
: hr
= VarCyFromI2(*(signed short*)src
, d
); break;
566 case DBTYPE_I4
: hr
= VarCyFromI4(*(signed int*)src
, d
); break;
567 case DBTYPE_R4
: hr
= VarCyFromR4(*(FLOAT
*)src
, d
); break;
568 case DBTYPE_R8
: hr
= VarCyFromR8(*(double*)src
, d
); break;
569 case DBTYPE_CY
: *d
= *(CY
*)src
; hr
= S_OK
; break;
570 case DBTYPE_DATE
: hr
= VarCyFromDate(*(DATE
*)src
, d
); break;
571 case DBTYPE_BSTR
: hr
= VarCyFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
572 case DBTYPE_BOOL
: hr
= VarCyFromBool(*(VARIANT_BOOL
*)src
, d
); break;
573 case DBTYPE_DECIMAL
: hr
= VarCyFromDec((DECIMAL
*)src
, d
); break;
574 case DBTYPE_I1
: hr
= VarCyFromI1(*(signed char*)src
, d
); break;
575 case DBTYPE_UI1
: hr
= VarCyFromUI1(*(BYTE
*)src
, d
); break;
576 case DBTYPE_UI2
: hr
= VarCyFromUI2(*(WORD
*)src
, d
); break;
577 case DBTYPE_UI4
: hr
= VarCyFromUI4(*(DWORD
*)src
, d
); break;
578 case DBTYPE_I8
: hr
= VarCyFromI8(*(LONGLONG
*)src
, d
); break;
579 case DBTYPE_UI8
: hr
= VarCyFromUI8(*(ULONGLONG
*)src
, d
); break;
580 default: FIXME("Unimplemented conversion %04x -> CY\n", src_type
); return E_NOTIMPL
;
590 case DBTYPE_EMPTY
: *d
= SysAllocStringLen(NULL
, 0); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
591 case DBTYPE_I2
: hr
= VarBstrFromI2(*(signed short*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
592 case DBTYPE_I4
: hr
= VarBstrFromI4(*(signed int*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
593 case DBTYPE_R4
: hr
= VarBstrFromR4(*(FLOAT
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
594 case DBTYPE_R8
: hr
= VarBstrFromR8(*(double*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
595 case DBTYPE_CY
: hr
= VarBstrFromCy(*(CY
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
596 case DBTYPE_DATE
: hr
= VarBstrFromDate(*(DATE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
597 case DBTYPE_BSTR
: *d
= SysAllocStringLen(*(BSTR
*)src
, SysStringLen(*(BSTR
*)src
)); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
598 case DBTYPE_BOOL
: hr
= VarBstrFromBool(*(VARIANT_BOOL
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
599 case DBTYPE_DECIMAL
: hr
= VarBstrFromDec((DECIMAL
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
600 case DBTYPE_I1
: hr
= VarBstrFromI1(*(signed char*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
601 case DBTYPE_UI1
: hr
= VarBstrFromUI1(*(BYTE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
602 case DBTYPE_UI2
: hr
= VarBstrFromUI2(*(WORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
603 case DBTYPE_UI4
: hr
= VarBstrFromUI4(*(DWORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
604 case DBTYPE_I8
: hr
= VarBstrFromI8(*(LONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
605 case DBTYPE_UI8
: hr
= VarBstrFromUI8(*(ULONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
609 const GUID
*id
= (const GUID
*)src
;
611 '{','%','0','8','X','-','%','0','4','X','-','%','0','4','X','-',
612 '%','0','2','X','%','0','2','X','-',
613 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','}',0};
614 wsprintfW(szBuff
, format
,
615 id
->Data1
, id
->Data2
, id
->Data3
,
616 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
617 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
618 *d
= SysAllocString(szBuff
);
619 hr
= *d
? S_OK
: E_OUTOFMEMORY
;
624 *d
= SysAllocStringLen(NULL
, 2 * src_len
);
629 const char hexchars
[] = "0123456789ABCDEF";
631 unsigned char *p
= src
;
634 *s
++ = hexchars
[(*p
>> 4) & 0x0F];
635 *s
++ = hexchars
[(*p
) & 0x0F];
644 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_BSTR
)) == S_OK
)
647 default: FIXME("Unimplemented conversion %04x -> BSTR\n", src_type
); return E_NOTIMPL
;
657 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
658 case DBTYPE_I2
: hr
= VarUI1FromI2(*(signed short*)src
, d
); break;
659 case DBTYPE_I4
: hr
= VarUI1FromI4(*(signed int*)src
, d
); break;
660 case DBTYPE_R4
: hr
= VarUI1FromR4(*(FLOAT
*)src
, d
); break;
661 case DBTYPE_R8
: hr
= VarUI1FromR8(*(double*)src
, d
); break;
662 case DBTYPE_CY
: hr
= VarUI1FromCy(*(CY
*)src
, d
); break;
663 case DBTYPE_DATE
: hr
= VarUI1FromDate(*(DATE
*)src
, d
); break;
664 case DBTYPE_BSTR
: hr
= VarUI1FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
665 case DBTYPE_BOOL
: hr
= VarUI1FromBool(*(VARIANT_BOOL
*)src
, d
); break;
666 case DBTYPE_DECIMAL
: hr
= VarUI1FromDec((DECIMAL
*)src
, d
); break;
667 case DBTYPE_I1
: hr
= VarUI1FromI1(*(signed char*)src
, d
); break;
668 case DBTYPE_UI1
: *d
= *(BYTE
*)src
; hr
= S_OK
; break;
669 case DBTYPE_UI2
: hr
= VarUI1FromUI2(*(WORD
*)src
, d
); break;
670 case DBTYPE_UI4
: hr
= VarUI1FromUI4(*(DWORD
*)src
, d
); break;
671 case DBTYPE_I8
: hr
= VarUI1FromI8(*(LONGLONG
*)src
, d
); break;
672 case DBTYPE_UI8
: hr
= VarUI1FromUI8(*(ULONGLONG
*)src
, d
); break;
673 default: FIXME("Unimplemented conversion %04x -> UI1\n", src_type
); return E_NOTIMPL
;
682 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
683 case DBTYPE_I2
: hr
= VarUI2FromI2(*(signed short*)src
, d
); break;
684 case DBTYPE_I4
: hr
= VarUI2FromI4(*(signed int*)src
, d
); break;
685 case DBTYPE_R4
: hr
= VarUI2FromR4(*(FLOAT
*)src
, d
); break;
686 case DBTYPE_R8
: hr
= VarUI2FromR8(*(double*)src
, d
); break;
687 case DBTYPE_CY
: hr
= VarUI2FromCy(*(CY
*)src
, d
); break;
688 case DBTYPE_DATE
: hr
= VarUI2FromDate(*(DATE
*)src
, d
); break;
689 case DBTYPE_BSTR
: hr
= VarUI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
690 case DBTYPE_BOOL
: hr
= VarUI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
691 case DBTYPE_DECIMAL
: hr
= VarUI2FromDec((DECIMAL
*)src
, d
); break;
692 case DBTYPE_I1
: hr
= VarUI2FromI1(*(signed char*)src
, d
); break;
693 case DBTYPE_UI1
: hr
= VarUI2FromUI1(*(BYTE
*)src
, d
); break;
694 case DBTYPE_UI2
: *d
= *(WORD
*)src
; hr
= S_OK
; break;
695 case DBTYPE_UI4
: hr
= VarUI2FromUI4(*(DWORD
*)src
, d
); break;
696 case DBTYPE_I8
: hr
= VarUI2FromI8(*(LONGLONG
*)src
, d
); break;
697 case DBTYPE_UI8
: hr
= VarUI2FromUI8(*(ULONGLONG
*)src
, d
); break;
698 default: FIXME("Unimplemented conversion %04x -> UI2\n", src_type
); return E_NOTIMPL
;
708 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
709 case DBTYPE_I2
: hr
= VarUI4FromI2(*(signed short*)src
, d
); break;
710 case DBTYPE_I4
: hr
= VarUI4FromI4(*(signed int*)src
, d
); break;
711 case DBTYPE_R4
: hr
= VarUI4FromR4(*(FLOAT
*)src
, d
); break;
712 case DBTYPE_R8
: hr
= VarUI4FromR8(*(double*)src
, d
); break;
713 case DBTYPE_CY
: hr
= VarUI4FromCy(*(CY
*)src
, d
); break;
714 case DBTYPE_DATE
: hr
= VarUI4FromDate(*(DATE
*)src
, d
); break;
715 case DBTYPE_BSTR
: hr
= VarUI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
716 case DBTYPE_BOOL
: hr
= VarUI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
717 case DBTYPE_DECIMAL
: hr
= VarUI4FromDec((DECIMAL
*)src
, d
); break;
718 case DBTYPE_I1
: hr
= VarUI4FromI1(*(signed char*)src
, d
); break;
719 case DBTYPE_UI1
: hr
= VarUI4FromUI1(*(BYTE
*)src
, d
); break;
720 case DBTYPE_UI2
: hr
= VarUI4FromUI2(*(WORD
*)src
, d
); break;
721 case DBTYPE_UI4
: *d
= *(DWORD
*)src
; hr
= S_OK
; break;
722 case DBTYPE_I8
: hr
= VarUI4FromI8(*(LONGLONG
*)src
, d
); break;
723 case DBTYPE_UI8
: hr
= VarUI4FromUI8(*(ULONGLONG
*)src
, d
); break;
726 if ((hr
= VariantChangeType(&tmp
, (VARIANT
*)src
, 0, VT_UI4
)) == S_OK
)
729 default: FIXME("Unimplemented conversion %04x -> UI4\n", src_type
); return E_NOTIMPL
;
739 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
740 case DBTYPE_I2
: hr
= VarUI8FromI2(*(signed short*)src
, d
); break;
741 case DBTYPE_I4
: {LONGLONG s
= *(signed int*)src
; hr
= VarUI8FromI8(s
, d
); break;}
742 case DBTYPE_R4
: hr
= VarUI8FromR4(*(FLOAT
*)src
, d
); break;
743 case DBTYPE_R8
: hr
= VarUI8FromR8(*(double*)src
, d
); break;
744 case DBTYPE_CY
: hr
= VarUI8FromCy(*(CY
*)src
, d
); break;
745 case DBTYPE_DATE
: hr
= VarUI8FromDate(*(DATE
*)src
, d
); break;
746 case DBTYPE_BSTR
: hr
= VarUI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
747 case DBTYPE_BOOL
: hr
= VarUI8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
748 case DBTYPE_DECIMAL
: hr
= VarUI8FromDec((DECIMAL
*)src
, d
); break;
749 case DBTYPE_I1
: hr
= VarUI8FromI1(*(signed char*)src
, d
); break;
750 case DBTYPE_UI1
: hr
= VarUI8FromUI1(*(BYTE
*)src
, d
); break;
751 case DBTYPE_UI2
: hr
= VarUI8FromUI2(*(WORD
*)src
, d
); break;
752 case DBTYPE_UI4
: hr
= VarUI8FromUI4(*(DWORD
*)src
, d
); break;
753 case DBTYPE_I8
: hr
= VarUI8FromI8(*(LONGLONG
*)src
, d
); break;
754 case DBTYPE_UI8
: *d
= *(ULONGLONG
*)src
; hr
= S_OK
; break;
755 default: FIXME("Unimplemented conversion %04x -> UI8\n", src_type
); return E_NOTIMPL
;
760 case DBTYPE_FILETIME
:
765 case DBTYPE_EMPTY
: d
->dwLowDateTime
= d
->dwHighDateTime
= 0; hr
= S_OK
; break;
766 case DBTYPE_FILETIME
: *d
= *(FILETIME
*)src
; hr
= S_OK
; break;
767 default: FIXME("Unimplemented conversion %04x -> FILETIME\n", src_type
); return E_NOTIMPL
;
777 case DBTYPE_EMPTY
: *d
= GUID_NULL
; hr
= S_OK
; break;
778 case DBTYPE_GUID
: *d
= *(GUID
*)src
; hr
= S_OK
; break;
779 default: FIXME("Unimplemented conversion %04x -> GUID\n", src_type
); return E_NOTIMPL
;
789 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
790 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
791 precision
, scale
, flags
);
792 if(hr
!= S_OK
|| *dst_status
== DBSTATUS_S_ISNULL
)
794 bstr_len
= SysStringLen(b
);
795 *dst_len
= bstr_len
* sizeof(WCHAR
); /* Doesn't include size for '\0' */
796 *dst_status
= DBSTATUS_S_OK
;
797 bytes_to_copy
= min(*dst_len
+ sizeof(WCHAR
), dst_max_len
);
800 if(bytes_to_copy
>= sizeof(WCHAR
))
802 memcpy(dst
, b
, bytes_to_copy
- sizeof(WCHAR
));
803 *((WCHAR
*)dst
+ bytes_to_copy
/ sizeof(WCHAR
) - 1) = 0;
804 if(bytes_to_copy
< *dst_len
+ sizeof(WCHAR
))
805 *dst_status
= DBSTATUS_S_TRUNCATED
;
809 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
810 hr
= DB_E_ERRORSOCCURRED
;
821 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
822 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
823 precision
, scale
, flags
);
824 if(hr
!= S_OK
) return hr
;
825 bstr_len
= SysStringLen(b
);
826 *dst_len
= bstr_len
* sizeof(char); /* Doesn't include size for '\0' */
827 *dst_status
= DBSTATUS_S_OK
;
828 bytes_to_copy
= min(*dst_len
+ sizeof(char), dst_max_len
);
831 if(bytes_to_copy
>= sizeof(char))
833 WideCharToMultiByte(CP_ACP
, 0, b
, bytes_to_copy
- sizeof(char), dst
, dst_max_len
, NULL
, NULL
);
834 *((char *)dst
+ bytes_to_copy
/ sizeof(char) - 1) = 0;
835 if(bytes_to_copy
< *dst_len
+ sizeof(char))
836 *dst_status
= DBSTATUS_S_TRUNCATED
;
840 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
841 hr
= DB_E_ERRORSOCCURRED
;
848 case DBTYPE_BYREF
| DBTYPE_WSTR
:
853 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
854 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
855 precision
, scale
, flags
);
856 if(hr
!= S_OK
) return hr
;
858 bstr_len
= SysStringLen(b
) * sizeof(WCHAR
);
859 *dst_len
= bstr_len
; /* Doesn't include size for '\0' */
861 *d
= CoTaskMemAlloc(bstr_len
+ sizeof(WCHAR
));
862 if(*d
) memcpy(*d
, b
, bstr_len
+ sizeof(WCHAR
));
863 else hr
= E_OUTOFMEMORY
;
876 V_BOOL(v
) = *(VARIANT_BOOL
*)src
;
881 V_I2(v
) = *(signed short*)src
;
886 V_I4(v
) = *(signed int*)src
;
890 V_VT(v
) = VT_DECIMAL
;
891 hr
= VarDecFromI8( *(LONGLONG
*)src
, &V_DECIMAL(v
));
895 V_R4(v
) = *(FLOAT
*)src
;
900 V_R8(v
) = *(double*)src
;
905 BSTR s
= *(WCHAR
**)src
;
906 TRACE("%s\n", debugstr_w(s
));
908 V_BSTR(v
) = SysAllocString(s
);
909 hr
= V_BSTR(v
) ? S_OK
: E_OUTOFMEMORY
;
914 V_DATE(v
) = *(DATE
*)src
;
920 DBDATE
*ts
=(DBDATE
*)src
;
925 st
.wMonth
= ts
->month
;
930 st
.wMilliseconds
= 0;
931 hr
= (SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
);
934 case DBTYPE_DBTIMESTAMP
:
937 DBTIMESTAMP
*ts
= (DBTIMESTAMP
*)src
;
942 st
.wMonth
= ts
->month
;
945 st
.wMinute
= ts
->minute
;
946 st
.wSecond
= ts
->second
;
947 st
.wMilliseconds
= ts
->fraction
/1000000;
948 hr
= SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
;
959 SAFEARRAY
*psa
= NULL
;
960 SAFEARRAYBOUND rgsabound
[1];
961 unsigned char *p
= src
;
963 rgsabound
[0].lLbound
= 0;
964 rgsabound
[0].cElements
= src_len
;
966 psa
= SafeArrayCreate(VT_UI1
,1,rgsabound
);
967 for(i
=0; i
< src_len
; i
++,p
++)
969 hr
= SafeArrayPutElement(psa
, &i
, p
);
971 SafeArrayDestroy (psa
);
976 V_VT(v
) = VT_ARRAY
|VT_UI1
;
981 default: FIXME("Unimplemented conversion %04x -> VARIANT\n", src_type
); return E_NOTIMPL
;
992 if( src_len
> dst_max_len
)
993 *dst_status
= DBSTATUS_S_TRUNCATED
;
995 *dst_status
= DBSTATUS_S_OK
;
998 memcpy(d
, src
, min(src_len
, dst_max_len
));
1001 case DBTYPE_VARIANT
:
1003 switch(V_VT((VARIANT
*)src
))
1005 case VT_UI1
| VT_ARRAY
:
1010 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1014 hr
= SafeArrayAccessData(V_ARRAY((VARIANT
*)src
), (VOID
**)&data
);
1017 ERR("SafeArrayAccessData Failed = 0x%08x\n", hr
);
1022 *dst_status
= DBSTATUS_S_OK
;
1023 memcpy(d
, data
, *dst_len
);
1025 SafeArrayUnaccessData(V_ARRAY((VARIANT
*)src
));
1030 FIXME("Unimplemented variant type %d -> BYTES\n", V_VT((VARIANT
*)src
));
1035 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES\n", src_type
); return E_NOTIMPL
;
1039 case DBTYPE_BYTES
| DBTYPE_BYREF
:
1046 *d
= CoTaskMemAlloc(src_len
);
1047 if(*d
) memcpy(*d
, src
, src_len
);
1048 else hr
= E_OUTOFMEMORY
;
1051 *dst_status
= DBSTATUS_S_OK
;
1053 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES | DBTYPE_BYREF\n", src_type
); return E_NOTIMPL
;
1060 FIXME("Unimplemented conversion %04x -> %04x\n", src_type
, dst_type
);
1064 if(hr
== DISP_E_OVERFLOW
)
1066 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
1067 *dst_len
= get_length(dst_type
);
1068 hr
= DB_E_ERRORSOCCURRED
;
1072 *dst_status
= DBSTATUS_S_OK
;
1073 *dst_len
= get_length(dst_type
);
1079 static inline WORD
get_dbtype_class(DBTYPE type
)
1106 case DBTYPE_DBTIMESTAMP
:
1107 return DBTYPE_DBDATE
;
1112 /* Many src types will convert to this group of dst types */
1113 static inline BOOL
common_class(WORD dst_class
)
1123 case DBTYPE_VARIANT
:
1126 case DBTYPE_DECIMAL
:
1127 case DBTYPE_NUMERIC
:
1133 static inline BOOL
array_type(DBTYPE type
)
1135 return (type
>= DBTYPE_I2
&& type
<= DBTYPE_UI4
);
1138 static HRESULT WINAPI
convert_CanConvert(IDataConvert
* iface
,
1139 DBTYPE src_type
, DBTYPE dst_type
)
1141 convert
*This
= impl_from_IDataConvert(iface
);
1142 DBTYPE src_base_type
= src_type
& 0x1ff;
1143 DBTYPE dst_base_type
= dst_type
& 0x1ff;
1144 WORD dst_class
= get_dbtype_class(dst_base_type
);
1146 TRACE("(%p)->(%d, %d)\n", This
, src_type
, dst_type
);
1148 if(src_type
& DBTYPE_VECTOR
|| dst_type
& DBTYPE_VECTOR
) return S_FALSE
;
1150 if(src_type
& DBTYPE_ARRAY
)
1152 if(!array_type(src_base_type
)) return S_FALSE
;
1153 if(dst_type
& DBTYPE_ARRAY
)
1155 if(src_type
== dst_type
) return S_OK
;
1158 if(dst_type
== DBTYPE_VARIANT
) return S_OK
;
1162 if(dst_type
& DBTYPE_ARRAY
)
1164 if(!array_type(dst_base_type
)) return S_FALSE
;
1165 if(src_type
== DBTYPE_IDISPATCH
|| src_type
== DBTYPE_VARIANT
) return S_OK
;
1169 if(dst_type
& DBTYPE_BYREF
)
1170 if(dst_base_type
!= DBTYPE_BYTES
&& dst_base_type
!= DBTYPE_STR
&& dst_base_type
!= DBTYPE_WSTR
)
1173 switch(get_dbtype_class(src_base_type
))
1176 if(common_class(dst_class
)) return S_OK
;
1181 case DBTYPE_FILETIME
:
1184 if(dst_base_type
== DBTYPE_DBTIMESTAMP
) return S_OK
;
1189 switch(dst_base_type
)
1192 case DBTYPE_VARIANT
:
1193 case DBTYPE_FILETIME
: return S_OK
;
1194 default: return S_FALSE
;
1198 if(dst_base_type
== DBTYPE_BYTES
) return S_OK
;
1201 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1203 case DBTYPE_DECIMAL
:
1204 if(common_class(dst_class
)) return S_OK
;
1205 if(dst_class
== DBTYPE_DBDATE
) return S_OK
;
1209 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1211 case DBTYPE_NUMERIC
:
1213 if(common_class(dst_class
)) return S_OK
;
1217 if(common_class(dst_class
)) return S_OK
;
1218 switch(dst_base_type
)
1221 case DBTYPE_FILETIME
: return S_OK
;
1222 default: return S_FALSE
;
1234 case DBTYPE_VARIANT
:
1238 case DBTYPE_FILETIME
:
1240 default: return S_FALSE
;
1243 case DBTYPE_IDISPATCH
:
1244 case DBTYPE_VARIANT
:
1245 switch(dst_base_type
)
1247 case DBTYPE_IDISPATCH
:
1249 case DBTYPE_IUNKNOWN
:
1254 if(common_class(dst_class
)) return S_OK
;
1261 case DBTYPE_FILETIME
:
1263 default: return S_FALSE
;
1267 switch(dst_base_type
)
1271 case DBTYPE_VARIANT
:
1274 default: return S_FALSE
;
1277 case DBTYPE_IUNKNOWN
:
1278 switch(dst_base_type
)
1282 case DBTYPE_IDISPATCH
:
1283 case DBTYPE_VARIANT
:
1284 case DBTYPE_IUNKNOWN
:
1286 default: return S_FALSE
;
1290 if(dst_class
== DBTYPE_I4
|| dst_class
== DBTYPE_I8
) return S_OK
;
1298 case DBTYPE_VARIANT
:
1302 default: return S_FALSE
;
1305 case DBTYPE_FILETIME
:
1306 if(dst_class
== DBTYPE_I8
) return S_OK
;
1315 case DBTYPE_VARIANT
:
1317 case DBTYPE_FILETIME
:
1319 default: return S_FALSE
;
1326 static HRESULT WINAPI
convert_GetConversionSize(IDataConvert
* iface
,
1327 DBTYPE src_type
, DBTYPE dst_type
,
1328 DBLENGTH
*src_len
, DBLENGTH
*dst_len
,
1331 convert
*This
= impl_from_IDataConvert(iface
);
1334 TRACE("(%p)->(%d, %d, %p, %p, %p)\n", This
, src_type
, dst_type
, src_len
, dst_len
, src
);
1336 hr
= IDataConvert_CanConvert(iface
, src_type
, dst_type
);
1338 return DB_E_UNSUPPORTEDCONVERSION
;
1341 return E_INVALIDARG
;
1343 /* for some types we don't need to look into source data */
1344 if ((*dst_len
= get_length(dst_type
)))
1347 if(src_type
== DBTYPE_VARIANT
&& V_VT((VARIANT
*)src
) == VT_NULL
)
1355 case DBTYPE_VARIANT
:
1360 if ((hr
= VariantChangeType(&v
, (VARIANT
*)src
, 0, VT_BSTR
)) == S_OK
)
1362 *dst_len
= WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), -1, NULL
, 0, NULL
, NULL
);
1370 FIXME("unimplemented for %04x -> DBTYPE_STR\n", src_type
);
1377 case DBTYPE_VARIANT
:
1382 if ((hr
= VariantChangeType(&v
, (VARIANT
*)src
, 0, VT_BSTR
)) == S_OK
)
1384 *dst_len
= (SysStringLen(V_BSTR(&v
))+1) * sizeof(WCHAR
);
1391 *dst_len
= (*src_len
+ 1) * sizeof(WCHAR
);
1393 *dst_len
= (strlen(src
) + 1) * sizeof(WCHAR
);
1397 *dst_len
= (*src_len
) + sizeof(WCHAR
);
1399 *dst_len
= (lstrlenW(src
) + 1) * sizeof(WCHAR
);
1402 FIXME("unimplemented for %04x -> DBTYPE_WSTR\n", src_type
);
1409 case DBTYPE_VARIANT
:
1410 if(V_VT((VARIANT
*)src
) == VT_BSTR
)
1411 *dst_len
= (SysStringLen(V_BSTR((VARIANT
*)src
))) / sizeof(WCHAR
);
1414 switch(V_VT((VARIANT
*)src
))
1416 case VT_UI1
| VT_ARRAY
:
1420 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1428 WARN("DBTYPE_VARIANT(%d)->DBTYPE_BYTES unimplemented\n", V_VT((VARIANT
*)src
));
1433 FIXME("unimplemented for %04x -> DBTYPE_BYTES\n", src_type
);
1438 FIXME("unimplemented for conversion %d->%d\n", src_type
, dst_type
);
1445 static const struct IDataConvertVtbl convert_vtbl
=
1447 convert_QueryInterface
,
1450 convert_DataConvert
,
1452 convert_GetConversionSize
1455 static HRESULT WINAPI
dcinfo_QueryInterface(IDCInfo
* iface
, REFIID riid
, void **obj
)
1457 convert
*This
= impl_from_IDCInfo(iface
);
1459 return IDataConvert_QueryInterface(&This
->IDataConvert_iface
, riid
, obj
);
1462 static ULONG WINAPI
dcinfo_AddRef(IDCInfo
* iface
)
1464 convert
*This
= impl_from_IDCInfo(iface
);
1466 return IDataConvert_AddRef(&This
->IDataConvert_iface
);
1469 static ULONG WINAPI
dcinfo_Release(IDCInfo
* iface
)
1471 convert
*This
= impl_from_IDCInfo(iface
);
1473 return IDataConvert_Release(&This
->IDataConvert_iface
);
1476 static HRESULT WINAPI
dcinfo_GetInfo(IDCInfo
*iface
, ULONG num
, DCINFOTYPE types
[], DCINFO
**info_ptr
)
1478 convert
*This
= impl_from_IDCInfo(iface
);
1482 TRACE("(%p)->(%d, %p, %p)\n", This
, num
, types
, info_ptr
);
1484 *info_ptr
= infos
= CoTaskMemAlloc(num
* sizeof(*infos
));
1485 if(!infos
) return E_OUTOFMEMORY
;
1487 for(i
= 0; i
< num
; i
++)
1489 infos
[i
].eInfoType
= types
[i
];
1490 VariantInit(&infos
[i
].vData
);
1494 case DCINFOTYPE_VERSION
:
1495 V_VT(&infos
[i
].vData
) = VT_UI4
;
1496 V_UI4(&infos
[i
].vData
) = This
->version
;
1504 static HRESULT WINAPI
dcinfo_SetInfo(IDCInfo
* iface
, ULONG num
, DCINFO info
[])
1506 convert
*This
= impl_from_IDCInfo(iface
);
1510 TRACE("(%p)->(%d, %p)\n", This
, num
, info
);
1512 for(i
= 0; i
< num
; i
++)
1514 switch(info
[i
].eInfoType
)
1516 case DCINFOTYPE_VERSION
:
1517 if(V_VT(&info
[i
].vData
) != VT_UI4
)
1519 FIXME("VERSION with vt %x\n", V_VT(&info
[i
].vData
));
1520 hr
= DB_S_ERRORSOCCURRED
;
1523 This
->version
= V_UI4(&info
[i
].vData
);
1527 FIXME("Unhandled info type %d (vt %x)\n", info
[i
].eInfoType
, V_VT(&info
[i
].vData
));
1533 static const struct IDCInfoVtbl dcinfo_vtbl
=
1535 dcinfo_QueryInterface
,
1542 HRESULT
create_oledb_convert(IUnknown
*outer
, void **obj
)
1546 TRACE("(%p, %p)\n", outer
, obj
);
1550 if(outer
) return CLASS_E_NOAGGREGATION
;
1552 This
= heap_alloc(sizeof(*This
));
1553 if(!This
) return E_OUTOFMEMORY
;
1555 This
->IDataConvert_iface
.lpVtbl
= &convert_vtbl
;
1556 This
->IDCInfo_iface
.lpVtbl
= &dcinfo_vtbl
;
1558 This
->version
= 0x110;
1560 *obj
= &This
->IDataConvert_iface
;