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"
34 #include "wine/heap.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(oledb
);
40 IDataConvert IDataConvert_iface
;
41 IDCInfo IDCInfo_iface
;
45 UINT version
; /* Set by IDCInfo_SetInfo */
48 static inline convert
*impl_from_IDataConvert(IDataConvert
*iface
)
50 return CONTAINING_RECORD(iface
, convert
, IDataConvert_iface
);
53 static inline convert
*impl_from_IDCInfo(IDCInfo
*iface
)
55 return CONTAINING_RECORD(iface
, convert
, IDCInfo_iface
);
58 static HRESULT WINAPI
convert_QueryInterface(IDataConvert
* iface
,
62 convert
*This
= impl_from_IDataConvert(iface
);
63 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), obj
);
67 if(IsEqualIID(riid
, &IID_IUnknown
) ||
68 IsEqualIID(riid
, &IID_IDataConvert
))
72 else if(IsEqualIID(riid
, &IID_IDCInfo
))
74 *obj
= &This
->IDCInfo_iface
;
78 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
82 IDataConvert_AddRef(iface
);
87 static ULONG WINAPI
convert_AddRef(IDataConvert
* iface
)
89 convert
*This
= impl_from_IDataConvert(iface
);
90 TRACE("(%p)\n", This
);
92 return InterlockedIncrement(&This
->ref
);
96 static ULONG WINAPI
convert_Release(IDataConvert
* iface
)
98 convert
*This
= impl_from_IDataConvert(iface
);
101 TRACE("(%p)\n", This
);
103 ref
= InterlockedDecrement(&This
->ref
);
110 static int get_length(DBTYPE type
)
121 return sizeof(VARIANT_BOOL
);
132 return sizeof(DBDATE
);
133 case DBTYPE_DBTIMESTAMP
:
134 return sizeof(DBTIMESTAMP
);
139 case DBTYPE_FILETIME
:
140 return sizeof(FILETIME
);
144 return sizeof(DB_NUMERIC
);
148 case DBTYPE_BYREF
| DBTYPE_WSTR
:
151 return sizeof(VARIANT
);
153 FIXME("Unhandled type %04x\n", type
);
158 static HRESULT WINAPI
convert_DataConvert(IDataConvert
* iface
,
159 DBTYPE src_type
, DBTYPE dst_type
,
160 DBLENGTH src_len
, DBLENGTH
*dst_len
,
161 void *src
, void *dst
,
162 DBLENGTH dst_max_len
,
163 DBSTATUS src_status
, DBSTATUS
*dst_status
,
164 BYTE precision
, BYTE scale
,
167 convert
*This
= impl_from_IDataConvert(iface
);
168 DBLENGTH dst_len_loc
;
169 DBSTATUS dst_status_loc
;
173 TRACE("(%p)->(%d, %d, %Id, %p, %p, %p, %Id, %ld, %p, %d, %d, %lx)\n", This
,
174 src_type
, dst_type
, src_len
, dst_len
, src
, dst
, dst_max_len
,
175 src_status
, dst_status
, precision
, scale
, flags
);
177 if (!dst_len
) dst_len
= &dst_len_loc
;
178 if (!dst_status
) dst_status
= &dst_status_loc
;
180 *dst_status
= DBSTATUS_E_BADACCESSOR
;
182 if(src_status
== DBSTATUS_S_ISNULL
)
184 *dst_status
= DBSTATUS_S_ISNULL
;
189 if(src_type
== DBTYPE_VARIANT
&& V_VT((VARIANT
*)src
) == VT_NULL
)
191 if(dst_type
== DBTYPE_VARIANT
)
192 *dst_len
= sizeof(VARIANT
);
194 *dst_status
= DBSTATUS_S_ISNULL
;
198 if(IDataConvert_CanConvert(iface
, src_type
, dst_type
) != S_OK
)
200 return DB_E_UNSUPPORTEDCONVERSION
;
203 if(dst
== NULL
&& get_length(dst_type
) != 0)
205 *dst_len
= get_length(src_type
);
206 *dst_status
= DBSTATUS_S_OK
;
210 if(src_type
== DBTYPE_STR
)
215 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
216 len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0) - 1;
218 len
= MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, NULL
, 0);
219 b
= SysAllocStringLen(NULL
, len
);
220 if(!b
) return E_OUTOFMEMORY
;
221 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
222 MultiByteToWideChar(CP_ACP
, 0, src
, -1, b
, len
+ 1);
224 MultiByteToWideChar(CP_ACP
, 0, src
, src_len
, b
, len
);
226 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
227 &b
, dst
, dst_max_len
, src_status
, dst_status
,
228 precision
, scale
, flags
);
234 if(src_type
== DBTYPE_WSTR
)
238 if(flags
& DBDATACONVERT_LENGTHFROMNTS
)
239 b
= SysAllocString(src
);
241 b
= SysAllocStringLen(src
, src_len
/ 2);
242 if(!b
) return E_OUTOFMEMORY
;
243 hr
= IDataConvert_DataConvert(iface
, DBTYPE_BSTR
, dst_type
, 0, dst_len
,
244 &b
, dst
, dst_max_len
, src_status
, dst_status
,
245 precision
, scale
, flags
);
254 signed char *d
= dst
;
257 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
258 case DBTYPE_I1
: *d
= *(signed char*)src
; hr
= S_OK
; break;
259 case DBTYPE_I2
: hr
= VarI1FromI2(*(signed short*)src
, d
); break;
260 case DBTYPE_I4
: hr
= VarI1FromI4(*(signed int*)src
, d
); break;
261 case DBTYPE_R4
: hr
= VarI1FromR4(*(FLOAT
*)src
, d
); break;
262 case DBTYPE_R8
: hr
= VarI1FromR8(*(double*)src
, d
); break;
263 case DBTYPE_CY
: hr
= VarI1FromCy(*(CY
*)src
, d
); break;
264 case DBTYPE_DATE
: hr
= VarI1FromDate(*(DATE
*)src
, d
); break;
265 case DBTYPE_BSTR
: hr
= VarI1FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
266 case DBTYPE_BOOL
: hr
= VarI1FromBool(*(VARIANT_BOOL
*)src
, d
); break;
267 case DBTYPE_DECIMAL
: hr
= VarI1FromDec(src
, d
); break;
268 case DBTYPE_UI1
: hr
= VarI1FromUI1(*(BYTE
*)src
, d
); break;
269 case DBTYPE_UI2
: hr
= VarI1FromUI2(*(WORD
*)src
, d
); break;
270 case DBTYPE_UI4
: hr
= VarI1FromUI4(*(DWORD
*)src
, d
); break;
271 case DBTYPE_I8
: hr
= VarI1FromI8(*(LONGLONG
*)src
, d
); break;
272 case DBTYPE_UI8
: hr
= VarI1FromUI8(*(ULONGLONG
*)src
, d
); break;
275 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_I1
)) == S_OK
)
278 default: FIXME("Unimplemented conversion %04x -> I1\n", src_type
); return E_NOTIMPL
;
285 signed short *d
= dst
;
288 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
289 case DBTYPE_I2
: *d
= *(signed short*)src
; hr
= S_OK
; break;
290 case DBTYPE_I4
: hr
= VarI2FromI4(*(signed int*)src
, d
); break;
291 case DBTYPE_R4
: hr
= VarI2FromR4(*(FLOAT
*)src
, d
); break;
292 case DBTYPE_R8
: hr
= VarI2FromR8(*(double*)src
, d
); break;
293 case DBTYPE_CY
: hr
= VarI2FromCy(*(CY
*)src
, d
); break;
294 case DBTYPE_DATE
: hr
= VarI2FromDate(*(DATE
*)src
, d
); break;
295 case DBTYPE_BSTR
: hr
= VarI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
296 case DBTYPE_BOOL
: hr
= VarI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
297 case DBTYPE_DECIMAL
: hr
= VarI2FromDec(src
, d
); break;
298 case DBTYPE_I1
: hr
= VarI2FromI1(*(signed char*)src
, d
); break;
299 case DBTYPE_UI1
: hr
= VarI2FromUI1(*(BYTE
*)src
, d
); break;
300 case DBTYPE_UI2
: hr
= VarI2FromUI2(*(WORD
*)src
, d
); break;
301 case DBTYPE_UI4
: hr
= VarI2FromUI4(*(DWORD
*)src
, d
); break;
302 case DBTYPE_I8
: hr
= VarI2FromI8(*(LONGLONG
*)src
, d
); break;
303 case DBTYPE_UI8
: hr
= VarI2FromUI8(*(ULONGLONG
*)src
, d
); break;
306 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_I2
)) == S_OK
)
309 default: FIXME("Unimplemented conversion %04x -> I2\n", src_type
); return E_NOTIMPL
;
319 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
320 case DBTYPE_I2
: hr
= VarI4FromI2(*(signed short*)src
, d
); break;
321 case DBTYPE_I4
: *d
= *(signed int*)src
; hr
= S_OK
; break;
322 case DBTYPE_R4
: hr
= VarI4FromR4(*(FLOAT
*)src
, d
); break;
323 case DBTYPE_R8
: hr
= VarI4FromR8(*(double*)src
, d
); break;
324 case DBTYPE_CY
: hr
= VarI4FromCy(*(CY
*)src
, d
); break;
325 case DBTYPE_DATE
: hr
= VarI4FromDate(*(DATE
*)src
, d
); break;
326 case DBTYPE_BSTR
: hr
= VarI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
327 case DBTYPE_BOOL
: hr
= VarI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
328 case DBTYPE_DECIMAL
: hr
= VarI4FromDec(src
, d
); break;
329 case DBTYPE_I1
: hr
= VarI4FromI1(*(signed char*)src
, d
); break;
330 case DBTYPE_UI1
: hr
= VarI4FromUI1(*(BYTE
*)src
, d
); break;
331 case DBTYPE_UI2
: hr
= VarI4FromUI2(*(WORD
*)src
, d
); break;
332 case DBTYPE_UI4
: hr
= VarI4FromUI4(*(DWORD
*)src
, d
); break;
333 case DBTYPE_I8
: hr
= VarI4FromI8(*(LONGLONG
*)src
, d
); break;
334 case DBTYPE_UI8
: hr
= VarI4FromUI8(*(ULONGLONG
*)src
, d
); break;
337 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_I4
)) == S_OK
)
340 default: FIXME("Unimplemented conversion %04x -> I4\n", src_type
); return E_NOTIMPL
;
350 case DBTYPE_BSTR
: hr
= VarI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
351 case DBTYPE_I8
: *d
= *(LONGLONG
*)src
; hr
= S_OK
; break;
352 default: FIXME("Unimplemented conversion %04x -> I8\n", src_type
); return E_NOTIMPL
;
362 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
363 case DBTYPE_I2
: hr
= VarR4FromI2(*(signed short*)src
, d
); break;
364 case DBTYPE_I4
: hr
= VarR4FromI4(*(signed int*)src
, d
); break;
365 case DBTYPE_R4
: *d
= *(FLOAT
*)src
; hr
= S_OK
; break;
366 case DBTYPE_R8
: hr
= VarR4FromR8(*(double*)src
, d
); break;
367 case DBTYPE_CY
: hr
= VarR4FromCy(*(CY
*)src
, d
); break;
368 case DBTYPE_DATE
: hr
= VarR4FromDate(*(DATE
*)src
, d
); break;
369 case DBTYPE_BSTR
: hr
= VarR4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
370 case DBTYPE_BOOL
: hr
= VarR4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
371 case DBTYPE_DECIMAL
: hr
= VarR4FromDec(src
, d
); break;
372 case DBTYPE_I1
: hr
= VarR4FromI1(*(signed char*)src
, d
); break;
373 case DBTYPE_UI1
: hr
= VarR4FromUI1(*(BYTE
*)src
, d
); break;
374 case DBTYPE_UI2
: hr
= VarR4FromUI2(*(WORD
*)src
, d
); break;
375 case DBTYPE_UI4
: hr
= VarR4FromUI4(*(DWORD
*)src
, d
); break;
376 case DBTYPE_I8
: hr
= VarR4FromI8(*(LONGLONG
*)src
, d
); break;
377 case DBTYPE_UI8
: hr
= VarR4FromUI8(*(ULONGLONG
*)src
, d
); break;
380 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_R4
)) == S_OK
)
383 default: FIXME("Unimplemented conversion %04x -> R4\n", src_type
); return E_NOTIMPL
;
392 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
393 case DBTYPE_I1
: hr
= VarR8FromI1(*(signed char*)src
, d
); break;
394 case DBTYPE_I2
: hr
= VarR8FromI2(*(signed short*)src
, d
); break;
395 case DBTYPE_I4
: hr
= VarR8FromI4(*(signed int*)src
, d
); break;
396 case DBTYPE_I8
: hr
= VarR8FromI8(*(LONGLONG
*)src
, d
); break;
397 case DBTYPE_UI1
: hr
= VarR8FromUI1(*(BYTE
*)src
, d
); break;
398 case DBTYPE_UI2
: hr
= VarR8FromUI2(*(WORD
*)src
, d
); break;
399 case DBTYPE_UI4
: hr
= VarR8FromUI4(*(DWORD
*)src
, d
); break;
400 case DBTYPE_UI8
: hr
= VarR8FromUI8(*(ULONGLONG
*)src
, d
); break;
401 case DBTYPE_R4
: hr
= VarR8FromR4(*(FLOAT
*)src
, d
); break;
402 case DBTYPE_R8
: *d
= *(DOUBLE
*)src
; hr
= S_OK
; break;
403 case DBTYPE_CY
: hr
= VarR8FromCy(*(CY
*)src
, d
); break;
404 case DBTYPE_DATE
: hr
= VarR8FromDate(*(DATE
*)src
, d
); break;
405 case DBTYPE_BSTR
: hr
= VarR8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
406 case DBTYPE_BOOL
: hr
= VarR8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
407 case DBTYPE_DECIMAL
: hr
= VarR8FromDec(src
, d
); break;
410 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_R8
)) == S_OK
)
413 default: FIXME("Unimplemented conversion %04x -> R8\n", src_type
); return E_NOTIMPL
;
422 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
423 case DBTYPE_I1
: hr
= VarBoolFromI1(*(signed char*)src
, d
); break;
424 case DBTYPE_I2
: hr
= VarBoolFromI2(*(signed short*)src
, d
); break;
425 case DBTYPE_I4
: hr
= VarBoolFromI4(*(signed int*)src
, d
); break;
426 case DBTYPE_I8
: hr
= VarBoolFromI8(*(LONGLONG
*)src
, d
); break;
427 case DBTYPE_UI1
: hr
= VarBoolFromUI1(*(BYTE
*)src
, d
); break;
428 case DBTYPE_UI2
: hr
= VarBoolFromUI2(*(WORD
*)src
, d
); break;
429 case DBTYPE_UI4
: hr
= VarBoolFromUI4(*(DWORD
*)src
, d
); break;
430 case DBTYPE_UI8
: hr
= VarBoolFromUI8(*(ULONGLONG
*)src
, d
); break;
431 case DBTYPE_R4
: hr
= VarBoolFromR4(*(FLOAT
*)src
, d
); break;
432 case DBTYPE_R8
: hr
= VarBoolFromR8(*(DOUBLE
*)src
, d
); break;
433 case DBTYPE_CY
: hr
= VarBoolFromCy(*(CY
*)src
, d
); break;
434 case DBTYPE_DATE
: hr
= VarBoolFromDate(*(DATE
*)src
, d
); break;
435 case DBTYPE_BSTR
: hr
= VarBoolFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
436 case DBTYPE_BOOL
: *d
= *(VARIANT_BOOL
*)src
; hr
= S_OK
; break;
437 case DBTYPE_DECIMAL
: hr
= VarBoolFromDec(src
, d
); break;
438 default: FIXME("Unimplemented conversion %04x -> BOOL\n", src_type
); return E_NOTIMPL
;
447 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
448 case DBTYPE_I1
: hr
= VarDateFromI1(*(signed char*)src
, d
); break;
449 case DBTYPE_I2
: hr
= VarDateFromI2(*(signed short*)src
, d
); break;
450 case DBTYPE_I4
: hr
= VarDateFromI4(*(signed int*)src
, d
); break;
451 case DBTYPE_I8
: hr
= VarDateFromI8(*(LONGLONG
*)src
, d
); break;
452 case DBTYPE_UI1
: hr
= VarDateFromUI1(*(BYTE
*)src
, d
); break;
453 case DBTYPE_UI2
: hr
= VarDateFromUI2(*(WORD
*)src
, d
); break;
454 case DBTYPE_UI4
: hr
= VarDateFromUI4(*(DWORD
*)src
, d
); break;
455 case DBTYPE_UI8
: hr
= VarDateFromUI8(*(ULONGLONG
*)src
, d
); break;
456 case DBTYPE_R4
: hr
= VarDateFromR4(*(FLOAT
*)src
, d
); break;
457 case DBTYPE_R8
: hr
= VarDateFromR8(*(DOUBLE
*)src
, d
); break;
458 case DBTYPE_CY
: hr
= VarDateFromCy(*(CY
*)src
, d
); break;
459 case DBTYPE_DATE
: *d
= *(DATE
*)src
; hr
= S_OK
; break;
460 case DBTYPE_BSTR
: hr
= VarDateFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
461 case DBTYPE_BOOL
: hr
= VarDateFromBool(*(VARIANT_BOOL
*)src
, d
); break;
462 case DBTYPE_DECIMAL
: hr
= VarDateFromDec(src
, d
); break;
463 case DBTYPE_DBTIMESTAMP
:
466 DBTIMESTAMP
*ts
= src
;
469 st
.wMonth
= ts
->month
;
472 st
.wMinute
= ts
->minute
;
473 st
.wSecond
= ts
->second
;
474 st
.wMilliseconds
= ts
->fraction
/1000000;
475 hr
= (SystemTimeToVariantTime(&st
, d
) ? S_OK
: E_FAIL
);
482 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_DATE
)) == S_OK
)
486 default: FIXME("Unimplemented conversion %04x -> DATE\n", src_type
); return E_NOTIMPL
;
495 case DBTYPE_DBDATE
: memcpy(d
, src
, sizeof(DBDATE
)); 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
)
508 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
510 d
->month
= st
.wMonth
;
521 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_DATE
)) == S_OK
)
524 hr
= (VariantTimeToSystemTime( V_DATE(&tmp
), &st
) ? S_OK
: E_FAIL
);
526 d
->month
= st
.wMonth
;
531 FIXME("Unimplemented variant type %d -> DBDATE\n", V_VT((VARIANT
*)src
));
536 default: FIXME("Unimplemented conversion %04x -> DBDATE\n", src_type
); return E_NOTIMPL
;
540 case DBTYPE_DBTIMESTAMP
:
545 case DBTYPE_EMPTY
: memset(d
, 0, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
546 case DBTYPE_DBTIMESTAMP
: memcpy(d
, src
, sizeof(DBTIMESTAMP
)); hr
= S_OK
; break;
550 BSTR s
= *(WCHAR
**)src
;
553 V_VT(&var
) = VT_BSTR
;
554 V_BSTR(&var
) = SysAllocString(s
);
556 if ((hr
= VariantChangeType(&var
, &var
, 0, VT_DATE
)) == S_OK
)
560 hr
= (VariantTimeToSystemTime( V_DATE(&var
), &st
) ? S_OK
: E_FAIL
);
562 d
->month
= st
.wMonth
;
565 d
->minute
= st
.wMinute
;
566 d
->second
= st
.wSecond
;
567 d
->fraction
= st
.wMilliseconds
* 1000000;
571 if(swscanf( s
, L
"%d-%d-%d %d:%d:%d.%d", &d
->year
, &d
->month
, &d
->day
, &d
->hour
, &d
->minute
,
572 &d
->second
, &d
->fraction
) != 7)
574 hr
= DISP_E_TYPEMISMATCH
;
575 *dst_status
= DBSTATUS_E_CANTCONVERTVALUE
;
576 *dst_len
= get_length(dst_type
);
588 hr
= (VariantTimeToSystemTime(*(double*)src
, &st
) ? S_OK
: E_FAIL
);
590 d
->month
= st
.wMonth
;
593 d
->minute
= st
.wMinute
;
594 d
->second
= st
.wSecond
;
595 d
->fraction
= st
.wMilliseconds
* 1000000;
599 if( V_VT((VARIANT
*)src
) == VT_DATE
)
602 hr
= (VariantTimeToSystemTime( V_DATE((VARIANT
*)src
), &st
) ? S_OK
: E_FAIL
);
604 d
->month
= st
.wMonth
;
607 d
->minute
= st
.wMinute
;
608 d
->second
= st
.wSecond
;
609 d
->fraction
= st
.wMilliseconds
* 1000000;
613 FIXME("Unimplemented variant type %d -> DBTIMESTAMP\n", V_VT((VARIANT
*)src
));
617 default: FIXME("Unimplemented conversion %04x -> DBTIMESTAMP\n", src_type
); return E_NOTIMPL
;
627 case DBTYPE_EMPTY
: d
->int64
= 0; hr
= S_OK
; break;
628 case DBTYPE_I2
: hr
= VarCyFromI2(*(signed short*)src
, d
); break;
629 case DBTYPE_I4
: hr
= VarCyFromI4(*(signed int*)src
, d
); break;
630 case DBTYPE_R4
: hr
= VarCyFromR4(*(FLOAT
*)src
, d
); break;
631 case DBTYPE_R8
: hr
= VarCyFromR8(*(double*)src
, d
); break;
632 case DBTYPE_CY
: *d
= *(CY
*)src
; hr
= S_OK
; break;
633 case DBTYPE_DATE
: hr
= VarCyFromDate(*(DATE
*)src
, d
); break;
634 case DBTYPE_BSTR
: hr
= VarCyFromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
635 case DBTYPE_BOOL
: hr
= VarCyFromBool(*(VARIANT_BOOL
*)src
, d
); break;
636 case DBTYPE_DECIMAL
: hr
= VarCyFromDec(src
, d
); break;
637 case DBTYPE_I1
: hr
= VarCyFromI1(*(signed char*)src
, d
); break;
638 case DBTYPE_UI1
: hr
= VarCyFromUI1(*(BYTE
*)src
, d
); break;
639 case DBTYPE_UI2
: hr
= VarCyFromUI2(*(WORD
*)src
, d
); break;
640 case DBTYPE_UI4
: hr
= VarCyFromUI4(*(DWORD
*)src
, d
); break;
641 case DBTYPE_I8
: hr
= VarCyFromI8(*(LONGLONG
*)src
, d
); break;
642 case DBTYPE_UI8
: hr
= VarCyFromUI8(*(ULONGLONG
*)src
, d
); break;
643 default: FIXME("Unimplemented conversion %04x -> CY\n", src_type
); return E_NOTIMPL
;
653 case DBTYPE_EMPTY
: *d
= SysAllocStringLen(NULL
, 0); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
654 case DBTYPE_I2
: hr
= VarBstrFromI2(*(signed short*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
655 case DBTYPE_I4
: hr
= VarBstrFromI4(*(signed int*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
656 case DBTYPE_R4
: hr
= VarBstrFromR4(*(FLOAT
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
657 case DBTYPE_R8
: hr
= VarBstrFromR8(*(double*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
658 case DBTYPE_CY
: hr
= VarBstrFromCy(*(CY
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
659 case DBTYPE_DATE
: hr
= VarBstrFromDate(*(DATE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
660 case DBTYPE_BSTR
: *d
= SysAllocStringLen(*(BSTR
*)src
, SysStringLen(*(BSTR
*)src
)); hr
= *d
? S_OK
: E_OUTOFMEMORY
; break;
661 case DBTYPE_BOOL
: hr
= VarBstrFromBool(*(VARIANT_BOOL
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
662 case DBTYPE_DECIMAL
: hr
= VarBstrFromDec(src
, LOCALE_USER_DEFAULT
, 0, d
); break;
663 case DBTYPE_I1
: hr
= VarBstrFromI1(*(signed char*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
664 case DBTYPE_UI1
: hr
= VarBstrFromUI1(*(BYTE
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
665 case DBTYPE_UI2
: hr
= VarBstrFromUI2(*(WORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
666 case DBTYPE_UI4
: hr
= VarBstrFromUI4(*(DWORD
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
667 case DBTYPE_I8
: hr
= VarBstrFromI8(*(LONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
668 case DBTYPE_UI8
: hr
= VarBstrFromUI8(*(ULONGLONG
*)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
672 const GUID
*id
= src
;
673 wsprintfW(szBuff
, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
674 id
->Data1
, id
->Data2
, id
->Data3
,
675 id
->Data4
[0], id
->Data4
[1], id
->Data4
[2], id
->Data4
[3],
676 id
->Data4
[4], id
->Data4
[5], id
->Data4
[6], id
->Data4
[7] );
677 *d
= SysAllocString(szBuff
);
678 hr
= *d
? S_OK
: E_OUTOFMEMORY
;
683 *d
= SysAllocStringLen(NULL
, 2 * src_len
);
688 static const char hexchars
[] = "0123456789ABCDEF";
690 unsigned char *p
= src
;
693 *s
++ = hexchars
[(*p
>> 4) & 0x0F];
694 *s
++ = hexchars
[(*p
) & 0x0F];
701 case DBTYPE_DBTIMESTAMP
:
704 DBTIMESTAMP
*ts
= src
;
706 if(ts
->fraction
== 0)
707 wsprintfW(szBuff
, L
"%04d-%02d-%02d %02d:%02d:%02d", ts
->year
, ts
->month
, ts
->day
, ts
->hour
,
708 ts
->minute
, ts
->second
);
710 wsprintfW(szBuff
, L
"%04d-%02d-%02d %02d:%02d:%02d.%09d", ts
->year
, ts
->month
, ts
->day
, ts
->hour
,
711 ts
->minute
, ts
->second
, ts
->fraction
);
712 *d
= SysAllocString(szBuff
);
713 hr
= *d
? S_OK
: E_OUTOFMEMORY
;
718 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_BSTR
)) == S_OK
)
721 default: FIXME("Unimplemented conversion %04x -> BSTR\n", src_type
); return E_NOTIMPL
;
731 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
732 case DBTYPE_I2
: hr
= VarUI1FromI2(*(signed short*)src
, d
); break;
733 case DBTYPE_I4
: hr
= VarUI1FromI4(*(signed int*)src
, d
); break;
734 case DBTYPE_R4
: hr
= VarUI1FromR4(*(FLOAT
*)src
, d
); break;
735 case DBTYPE_R8
: hr
= VarUI1FromR8(*(double*)src
, d
); break;
736 case DBTYPE_CY
: hr
= VarUI1FromCy(*(CY
*)src
, d
); break;
737 case DBTYPE_DATE
: hr
= VarUI1FromDate(*(DATE
*)src
, d
); break;
738 case DBTYPE_BSTR
: hr
= VarUI1FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
739 case DBTYPE_BOOL
: hr
= VarUI1FromBool(*(VARIANT_BOOL
*)src
, d
); break;
740 case DBTYPE_DECIMAL
: hr
= VarUI1FromDec(src
, d
); break;
741 case DBTYPE_I1
: hr
= VarUI1FromI1(*(signed char*)src
, d
); break;
742 case DBTYPE_UI1
: *d
= *(BYTE
*)src
; hr
= S_OK
; break;
743 case DBTYPE_UI2
: hr
= VarUI1FromUI2(*(WORD
*)src
, d
); break;
744 case DBTYPE_UI4
: hr
= VarUI1FromUI4(*(DWORD
*)src
, d
); break;
745 case DBTYPE_I8
: hr
= VarUI1FromI8(*(LONGLONG
*)src
, d
); break;
746 case DBTYPE_UI8
: hr
= VarUI1FromUI8(*(ULONGLONG
*)src
, d
); break;
747 default: FIXME("Unimplemented conversion %04x -> UI1\n", src_type
); return E_NOTIMPL
;
756 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
757 case DBTYPE_I2
: hr
= VarUI2FromI2(*(signed short*)src
, d
); break;
758 case DBTYPE_I4
: hr
= VarUI2FromI4(*(signed int*)src
, d
); break;
759 case DBTYPE_R4
: hr
= VarUI2FromR4(*(FLOAT
*)src
, d
); break;
760 case DBTYPE_R8
: hr
= VarUI2FromR8(*(double*)src
, d
); break;
761 case DBTYPE_CY
: hr
= VarUI2FromCy(*(CY
*)src
, d
); break;
762 case DBTYPE_DATE
: hr
= VarUI2FromDate(*(DATE
*)src
, d
); break;
763 case DBTYPE_BSTR
: hr
= VarUI2FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
764 case DBTYPE_BOOL
: hr
= VarUI2FromBool(*(VARIANT_BOOL
*)src
, d
); break;
765 case DBTYPE_DECIMAL
: hr
= VarUI2FromDec(src
, d
); break;
766 case DBTYPE_I1
: hr
= VarUI2FromI1(*(signed char*)src
, d
); break;
767 case DBTYPE_UI1
: hr
= VarUI2FromUI1(*(BYTE
*)src
, d
); break;
768 case DBTYPE_UI2
: *d
= *(WORD
*)src
; hr
= S_OK
; break;
769 case DBTYPE_UI4
: hr
= VarUI2FromUI4(*(DWORD
*)src
, d
); break;
770 case DBTYPE_I8
: hr
= VarUI2FromI8(*(LONGLONG
*)src
, d
); break;
771 case DBTYPE_UI8
: hr
= VarUI2FromUI8(*(ULONGLONG
*)src
, d
); break;
772 default: FIXME("Unimplemented conversion %04x -> UI2\n", src_type
); return E_NOTIMPL
;
782 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
783 case DBTYPE_I2
: hr
= VarUI4FromI2(*(signed short*)src
, d
); break;
784 case DBTYPE_I4
: hr
= VarUI4FromI4(*(signed int*)src
, d
); break;
785 case DBTYPE_R4
: hr
= VarUI4FromR4(*(FLOAT
*)src
, d
); break;
786 case DBTYPE_R8
: hr
= VarUI4FromR8(*(double*)src
, d
); break;
787 case DBTYPE_CY
: hr
= VarUI4FromCy(*(CY
*)src
, d
); break;
788 case DBTYPE_DATE
: hr
= VarUI4FromDate(*(DATE
*)src
, d
); break;
789 case DBTYPE_BSTR
: hr
= VarUI4FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
790 case DBTYPE_BOOL
: hr
= VarUI4FromBool(*(VARIANT_BOOL
*)src
, d
); break;
791 case DBTYPE_DECIMAL
: hr
= VarUI4FromDec(src
, d
); break;
792 case DBTYPE_I1
: hr
= VarUI4FromI1(*(signed char*)src
, d
); break;
793 case DBTYPE_UI1
: hr
= VarUI4FromUI1(*(BYTE
*)src
, d
); break;
794 case DBTYPE_UI2
: hr
= VarUI4FromUI2(*(WORD
*)src
, d
); break;
795 case DBTYPE_UI4
: *d
= *(DWORD
*)src
; hr
= S_OK
; break;
796 case DBTYPE_I8
: hr
= VarUI4FromI8(*(LONGLONG
*)src
, d
); break;
797 case DBTYPE_UI8
: hr
= VarUI4FromUI8(*(ULONGLONG
*)src
, d
); break;
800 if ((hr
= VariantChangeType(&tmp
, src
, 0, VT_UI4
)) == S_OK
)
803 default: FIXME("Unimplemented conversion %04x -> UI4\n", src_type
); return E_NOTIMPL
;
813 case DBTYPE_EMPTY
: *d
= 0; hr
= S_OK
; break;
814 case DBTYPE_I2
: hr
= VarUI8FromI2(*(signed short*)src
, d
); break;
815 case DBTYPE_I4
: {LONGLONG s
= *(signed int*)src
; hr
= VarUI8FromI8(s
, d
); break;}
816 case DBTYPE_R4
: hr
= VarUI8FromR4(*(FLOAT
*)src
, d
); break;
817 case DBTYPE_R8
: hr
= VarUI8FromR8(*(double*)src
, d
); break;
818 case DBTYPE_CY
: hr
= VarUI8FromCy(*(CY
*)src
, d
); break;
819 case DBTYPE_DATE
: hr
= VarUI8FromDate(*(DATE
*)src
, d
); break;
820 case DBTYPE_BSTR
: hr
= VarUI8FromStr(*(WCHAR
**)src
, LOCALE_USER_DEFAULT
, 0, d
); break;
821 case DBTYPE_BOOL
: hr
= VarUI8FromBool(*(VARIANT_BOOL
*)src
, d
); break;
822 case DBTYPE_DECIMAL
: hr
= VarUI8FromDec(src
, d
); break;
823 case DBTYPE_I1
: hr
= VarUI8FromI1(*(signed char*)src
, d
); break;
824 case DBTYPE_UI1
: hr
= VarUI8FromUI1(*(BYTE
*)src
, d
); break;
825 case DBTYPE_UI2
: hr
= VarUI8FromUI2(*(WORD
*)src
, d
); break;
826 case DBTYPE_UI4
: hr
= VarUI8FromUI4(*(DWORD
*)src
, d
); break;
827 case DBTYPE_I8
: hr
= VarUI8FromI8(*(LONGLONG
*)src
, d
); break;
828 case DBTYPE_UI8
: *d
= *(ULONGLONG
*)src
; hr
= S_OK
; break;
829 default: FIXME("Unimplemented conversion %04x -> UI8\n", src_type
); return E_NOTIMPL
;
834 case DBTYPE_FILETIME
:
839 case DBTYPE_EMPTY
: d
->dwLowDateTime
= d
->dwHighDateTime
= 0; hr
= S_OK
; break;
840 case DBTYPE_FILETIME
: *d
= *(FILETIME
*)src
; hr
= S_OK
; break;
841 default: FIXME("Unimplemented conversion %04x -> FILETIME\n", src_type
); return E_NOTIMPL
;
851 case DBTYPE_EMPTY
: *d
= GUID_NULL
; hr
= S_OK
; break;
852 case DBTYPE_GUID
: *d
= *(GUID
*)src
; hr
= S_OK
; break;
853 default: FIXME("Unimplemented conversion %04x -> GUID\n", src_type
); return E_NOTIMPL
;
863 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
864 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
865 precision
, scale
, flags
);
866 if(hr
!= S_OK
|| *dst_status
== DBSTATUS_S_ISNULL
)
868 bstr_len
= SysStringLen(b
);
869 *dst_len
= bstr_len
* sizeof(WCHAR
); /* Doesn't include size for '\0' */
870 *dst_status
= DBSTATUS_S_OK
;
871 bytes_to_copy
= min(*dst_len
+ sizeof(WCHAR
), dst_max_len
);
874 if(bytes_to_copy
>= sizeof(WCHAR
))
876 memcpy(dst
, b
, bytes_to_copy
- sizeof(WCHAR
));
877 *((WCHAR
*)dst
+ bytes_to_copy
/ sizeof(WCHAR
) - 1) = 0;
878 if(bytes_to_copy
< *dst_len
+ sizeof(WCHAR
))
879 *dst_status
= DBSTATUS_S_TRUNCATED
;
883 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
884 hr
= DB_E_ERRORSOCCURRED
;
896 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &length
,
897 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
898 precision
, scale
, flags
);
899 if(hr
!= S_OK
) return hr
;
900 length
= WideCharToMultiByte(CP_ACP
, 0, b
, SysStringLen(b
), NULL
, 0, NULL
, NULL
);
901 *dst_len
= length
; /* Doesn't include size for '\0' */
902 *dst_status
= DBSTATUS_S_OK
;
903 bytes_to_copy
= min(length
+ 1, dst_max_len
);
906 if(bytes_to_copy
>= sizeof(char))
908 WideCharToMultiByte(CP_ACP
, 0, b
, SysStringLen(b
), dst
, bytes_to_copy
- 1, NULL
, NULL
);
909 *((char *)dst
+ bytes_to_copy
- 1) = 0;
910 if(bytes_to_copy
< length
+ 1)
911 *dst_status
= DBSTATUS_S_TRUNCATED
;
915 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
916 hr
= DB_E_ERRORSOCCURRED
;
923 case DBTYPE_BYREF
| DBTYPE_WSTR
:
928 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &bstr_len
,
929 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
930 precision
, scale
, flags
);
931 if(hr
!= S_OK
) return hr
;
933 bstr_len
= SysStringLen(b
) * sizeof(WCHAR
);
934 *dst_len
= bstr_len
; /* Doesn't include size for '\0' */
936 *d
= CoTaskMemAlloc(bstr_len
+ sizeof(WCHAR
));
937 if(*d
) memcpy(*d
, b
, bstr_len
+ sizeof(WCHAR
));
938 else hr
= E_OUTOFMEMORY
;
943 case DBTYPE_BYREF
| DBTYPE_STR
:
948 hr
= IDataConvert_DataConvert(iface
, src_type
, DBTYPE_BSTR
, src_len
, &length
,
949 src
, &b
, sizeof(BSTR
), src_status
, dst_status
,
950 precision
, scale
, flags
);
951 if(hr
!= S_OK
) return hr
;
953 length
= WideCharToMultiByte(CP_ACP
, 0, b
, SysStringLen(b
) + 1, NULL
, 0, NULL
, NULL
);
954 *dst_len
= length
- 1; /* Doesn't include size for '\0' */
955 *dst_status
= DBSTATUS_S_OK
;
956 *d
= CoTaskMemAlloc(length
);
959 WideCharToMultiByte(CP_ACP
, 0, b
, SysStringLen(b
) + 1, *d
, length
, NULL
, NULL
);
975 V_BOOL(v
) = *(VARIANT_BOOL
*)src
;
980 V_I2(v
) = *(signed short*)src
;
985 V_I4(v
) = *(signed int*)src
;
989 V_VT(v
) = VT_DECIMAL
;
990 hr
= VarDecFromI8( *(LONGLONG
*)src
, &V_DECIMAL(v
));
994 V_R4(v
) = *(FLOAT
*)src
;
999 V_R8(v
) = *(double*)src
;
1004 BSTR s
= *(WCHAR
**)src
;
1005 TRACE("%s\n", debugstr_w(s
));
1007 V_BSTR(v
) = SysAllocString(s
);
1008 hr
= V_BSTR(v
) ? S_OK
: E_OUTOFMEMORY
;
1013 V_DATE(v
) = *(DATE
*)src
;
1023 st
.wYear
= ts
->year
;
1024 st
.wMonth
= ts
->month
;
1029 st
.wMilliseconds
= 0;
1030 hr
= (SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
);
1033 case DBTYPE_DBTIMESTAMP
:
1036 DBTIMESTAMP
*ts
= src
;
1040 st
.wYear
= ts
->year
;
1041 st
.wMonth
= ts
->month
;
1043 st
.wHour
= ts
->hour
;
1044 st
.wMinute
= ts
->minute
;
1045 st
.wSecond
= ts
->second
;
1046 st
.wMilliseconds
= ts
->fraction
/1000000;
1047 hr
= SystemTimeToVariantTime(&st
, &V_DATE(v
)) ? S_OK
: E_FAIL
;
1052 V_CY(v
) = *(CY
*)src
;
1058 SAFEARRAY
*psa
= NULL
;
1059 SAFEARRAYBOUND rgsabound
[1];
1060 unsigned char *p
= src
;
1062 rgsabound
[0].lLbound
= 0;
1063 rgsabound
[0].cElements
= src_len
;
1065 psa
= SafeArrayCreate(VT_UI1
,1,rgsabound
);
1066 for(i
=0; i
< src_len
; i
++,p
++)
1068 hr
= SafeArrayPutElement(psa
, &i
, p
);
1070 SafeArrayDestroy (psa
);
1075 V_VT(v
) = VT_ARRAY
|VT_UI1
;
1080 default: FIXME("Unimplemented conversion %04x -> VARIANT\n", src_type
); return E_NOTIMPL
;
1091 if( src_len
> dst_max_len
)
1092 *dst_status
= DBSTATUS_S_TRUNCATED
;
1094 *dst_status
= DBSTATUS_S_OK
;
1097 memcpy(d
, src
, min(src_len
, dst_max_len
));
1100 case DBTYPE_VARIANT
:
1102 switch(V_VT((VARIANT
*)src
))
1104 case VT_UI1
| VT_ARRAY
:
1109 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1113 hr
= SafeArrayAccessData(V_ARRAY((VARIANT
*)src
), (VOID
**)&data
);
1116 ERR("SafeArrayAccessData Failed = 0x%08lx\n", hr
);
1121 *dst_status
= DBSTATUS_S_OK
;
1122 memcpy(d
, data
, *dst_len
);
1124 SafeArrayUnaccessData(V_ARRAY((VARIANT
*)src
));
1129 FIXME("Unimplemented variant type %d -> BYTES\n", V_VT((VARIANT
*)src
));
1134 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES\n", src_type
); return E_NOTIMPL
;
1138 case DBTYPE_BYTES
| DBTYPE_BYREF
:
1145 *d
= CoTaskMemAlloc(src_len
);
1146 if(*d
) memcpy(*d
, src
, src_len
);
1147 else hr
= E_OUTOFMEMORY
;
1150 *dst_status
= DBSTATUS_S_OK
;
1152 default: FIXME("Unimplemented conversion %04x -> DBTYPE_BYTES | DBTYPE_BYREF\n", src_type
); return E_NOTIMPL
;
1157 case DBTYPE_NUMERIC
:
1158 FIXME("Unimplemented conversion %04x -> DBTYPE_NUMERIC\n", src_type
);
1162 FIXME("Unimplemented conversion %04x -> %04x\n", src_type
, dst_type
);
1166 if(hr
== DISP_E_OVERFLOW
)
1168 *dst_status
= DBSTATUS_E_DATAOVERFLOW
;
1169 *dst_len
= get_length(dst_type
);
1170 hr
= DB_E_ERRORSOCCURRED
;
1174 *dst_status
= DBSTATUS_S_OK
;
1175 *dst_len
= get_length(dst_type
);
1181 static inline WORD
get_dbtype_class(DBTYPE type
)
1208 case DBTYPE_DBTIMESTAMP
:
1209 return DBTYPE_DBDATE
;
1214 /* Many src types will convert to this group of dst types */
1215 static inline BOOL
common_class(WORD dst_class
)
1225 case DBTYPE_VARIANT
:
1228 case DBTYPE_DECIMAL
:
1229 case DBTYPE_NUMERIC
:
1235 static inline BOOL
array_type(DBTYPE type
)
1237 return (type
>= DBTYPE_I2
&& type
<= DBTYPE_UI4
);
1240 static HRESULT WINAPI
convert_CanConvert(IDataConvert
* iface
,
1241 DBTYPE src_type
, DBTYPE dst_type
)
1243 convert
*This
= impl_from_IDataConvert(iface
);
1244 DBTYPE src_base_type
= src_type
& 0x1ff;
1245 DBTYPE dst_base_type
= dst_type
& 0x1ff;
1246 WORD dst_class
= get_dbtype_class(dst_base_type
);
1248 TRACE("(%p)->(%d, %d)\n", This
, src_type
, dst_type
);
1250 if(src_type
& DBTYPE_VECTOR
|| dst_type
& DBTYPE_VECTOR
) return S_FALSE
;
1252 if(src_type
& DBTYPE_ARRAY
)
1254 if(!array_type(src_base_type
)) return S_FALSE
;
1255 if(dst_type
& DBTYPE_ARRAY
)
1257 if(src_type
== dst_type
) return S_OK
;
1260 if(dst_type
== DBTYPE_VARIANT
) return S_OK
;
1264 if(dst_type
& DBTYPE_ARRAY
)
1266 if(!array_type(dst_base_type
)) return S_FALSE
;
1267 if(src_type
== DBTYPE_IDISPATCH
|| src_type
== DBTYPE_VARIANT
) return S_OK
;
1271 if(dst_type
& DBTYPE_BYREF
)
1272 if(dst_base_type
!= DBTYPE_BYTES
&& dst_base_type
!= DBTYPE_STR
&& dst_base_type
!= DBTYPE_WSTR
)
1275 switch(get_dbtype_class(src_base_type
))
1278 if(common_class(dst_class
)) return S_OK
;
1283 case DBTYPE_FILETIME
:
1286 if(dst_base_type
== DBTYPE_DBTIMESTAMP
) return S_OK
;
1291 switch(dst_base_type
)
1294 case DBTYPE_VARIANT
:
1295 case DBTYPE_FILETIME
: return S_OK
;
1296 default: return S_FALSE
;
1300 if(dst_base_type
== DBTYPE_BYTES
) return S_OK
;
1303 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1305 case DBTYPE_DECIMAL
:
1306 if(common_class(dst_class
)) return S_OK
;
1307 if(dst_class
== DBTYPE_DBDATE
) return S_OK
;
1311 if(dst_base_type
== DBTYPE_DATE
) return S_OK
;
1313 case DBTYPE_NUMERIC
:
1315 if(common_class(dst_class
)) return S_OK
;
1319 if(common_class(dst_class
)) return S_OK
;
1320 switch(dst_base_type
)
1323 case DBTYPE_FILETIME
: return S_OK
;
1324 default: return S_FALSE
;
1336 case DBTYPE_VARIANT
:
1340 case DBTYPE_FILETIME
:
1342 default: return S_FALSE
;
1345 case DBTYPE_IDISPATCH
:
1346 case DBTYPE_VARIANT
:
1347 switch(dst_base_type
)
1349 case DBTYPE_IDISPATCH
:
1351 case DBTYPE_IUNKNOWN
:
1356 if(common_class(dst_class
)) return S_OK
;
1363 case DBTYPE_FILETIME
:
1365 default: return S_FALSE
;
1369 switch(dst_base_type
)
1373 case DBTYPE_VARIANT
:
1376 default: return S_FALSE
;
1379 case DBTYPE_IUNKNOWN
:
1380 switch(dst_base_type
)
1384 case DBTYPE_IDISPATCH
:
1385 case DBTYPE_VARIANT
:
1386 case DBTYPE_IUNKNOWN
:
1388 default: return S_FALSE
;
1392 if(dst_class
== DBTYPE_I4
|| dst_class
== DBTYPE_I8
) return S_OK
;
1400 case DBTYPE_VARIANT
:
1404 default: return S_FALSE
;
1407 case DBTYPE_FILETIME
:
1408 if(dst_class
== DBTYPE_I8
) return S_OK
;
1417 case DBTYPE_VARIANT
:
1419 case DBTYPE_FILETIME
:
1421 default: return S_FALSE
;
1428 static HRESULT WINAPI
convert_GetConversionSize(IDataConvert
* iface
,
1429 DBTYPE src_type
, DBTYPE dst_type
,
1430 DBLENGTH
*src_len
, DBLENGTH
*dst_len
,
1433 convert
*This
= impl_from_IDataConvert(iface
);
1436 TRACE("(%p)->(%d, %d, %p, %p, %p)\n", This
, src_type
, dst_type
, src_len
, dst_len
, src
);
1438 hr
= IDataConvert_CanConvert(iface
, src_type
, dst_type
);
1440 return DB_E_UNSUPPORTEDCONVERSION
;
1443 return E_INVALIDARG
;
1445 /* for some types we don't need to look into source data */
1446 if ((*dst_len
= get_length(dst_type
)))
1451 if(src_type
== DBTYPE_VARIANT
&& V_VT((VARIANT
*)src
) == VT_NULL
)
1459 case DBTYPE_VARIANT
:
1464 if ((hr
= VariantChangeType(&v
, src
, 0, VT_BSTR
)) == S_OK
)
1466 *dst_len
= WideCharToMultiByte(CP_ACP
, 0, V_BSTR(&v
), -1, NULL
, 0, NULL
, NULL
);
1474 case DBTYPE_DECIMAL
:
1485 case DBTYPE_DBTIMESTAMP
:
1489 FIXME("unimplemented for %04x -> DBTYPE_STR\n", src_type
);
1496 case DBTYPE_VARIANT
:
1501 if ((hr
= VariantChangeType(&v
, src
, 0, VT_BSTR
)) == S_OK
)
1503 *dst_len
= (SysStringLen(V_BSTR(&v
))+1) * sizeof(WCHAR
);
1510 *dst_len
= (*src_len
+ 1) * sizeof(WCHAR
);
1512 *dst_len
= (strlen(src
) + 1) * sizeof(WCHAR
);
1516 *dst_len
= (*src_len
) + sizeof(WCHAR
);
1518 *dst_len
= (lstrlenW(src
) + 1) * sizeof(WCHAR
);
1521 case DBTYPE_DECIMAL
:
1532 case DBTYPE_DBTIMESTAMP
:
1536 FIXME("unimplemented for %04x -> DBTYPE_WSTR\n", src_type
);
1543 case DBTYPE_VARIANT
:
1544 if(V_VT((VARIANT
*)src
) == VT_BSTR
)
1545 *dst_len
= (SysStringLen(V_BSTR((VARIANT
*)src
))) / sizeof(WCHAR
);
1548 switch(V_VT((VARIANT
*)src
))
1550 case VT_UI1
| VT_ARRAY
:
1554 hr
= SafeArrayGetUBound(V_ARRAY((VARIANT
*)src
), 1, &l
);
1562 WARN("DBTYPE_VARIANT(%d)->DBTYPE_BYTES unimplemented\n", V_VT((VARIANT
*)src
));
1567 FIXME("unimplemented for %04x -> DBTYPE_BYTES\n", src_type
);
1572 FIXME("unimplemented for conversion %d->%d\n", src_type
, dst_type
);
1579 static const struct IDataConvertVtbl convert_vtbl
=
1581 convert_QueryInterface
,
1584 convert_DataConvert
,
1586 convert_GetConversionSize
1589 static HRESULT WINAPI
dcinfo_QueryInterface(IDCInfo
* iface
, REFIID riid
, void **obj
)
1591 convert
*This
= impl_from_IDCInfo(iface
);
1593 return IDataConvert_QueryInterface(&This
->IDataConvert_iface
, riid
, obj
);
1596 static ULONG WINAPI
dcinfo_AddRef(IDCInfo
* iface
)
1598 convert
*This
= impl_from_IDCInfo(iface
);
1600 return IDataConvert_AddRef(&This
->IDataConvert_iface
);
1603 static ULONG WINAPI
dcinfo_Release(IDCInfo
* iface
)
1605 convert
*This
= impl_from_IDCInfo(iface
);
1607 return IDataConvert_Release(&This
->IDataConvert_iface
);
1610 static HRESULT WINAPI
dcinfo_GetInfo(IDCInfo
*iface
, ULONG num
, DCINFOTYPE types
[], DCINFO
**info_ptr
)
1612 convert
*This
= impl_from_IDCInfo(iface
);
1616 TRACE("(%p)->(%ld, %p, %p)\n", This
, num
, types
, info_ptr
);
1618 *info_ptr
= infos
= CoTaskMemAlloc(num
* sizeof(*infos
));
1619 if(!infos
) return E_OUTOFMEMORY
;
1621 for(i
= 0; i
< num
; i
++)
1623 infos
[i
].eInfoType
= types
[i
];
1624 VariantInit(&infos
[i
].vData
);
1628 case DCINFOTYPE_VERSION
:
1629 V_VT(&infos
[i
].vData
) = VT_UI4
;
1630 V_UI4(&infos
[i
].vData
) = This
->version
;
1638 static HRESULT WINAPI
dcinfo_SetInfo(IDCInfo
* iface
, ULONG num
, DCINFO info
[])
1640 convert
*This
= impl_from_IDCInfo(iface
);
1644 TRACE("(%p)->(%ld, %p)\n", This
, num
, info
);
1646 for(i
= 0; i
< num
; i
++)
1648 switch(info
[i
].eInfoType
)
1650 case DCINFOTYPE_VERSION
:
1651 if(V_VT(&info
[i
].vData
) != VT_UI4
)
1653 FIXME("VERSION with vt %x\n", V_VT(&info
[i
].vData
));
1654 hr
= DB_S_ERRORSOCCURRED
;
1657 This
->version
= V_UI4(&info
[i
].vData
);
1661 FIXME("Unhandled info type %ld (vt %x)\n", info
[i
].eInfoType
, V_VT(&info
[i
].vData
));
1667 static const struct IDCInfoVtbl dcinfo_vtbl
=
1669 dcinfo_QueryInterface
,
1676 HRESULT
create_oledb_convert(IUnknown
*outer
, void **obj
)
1680 TRACE("(%p, %p)\n", outer
, obj
);
1684 if(outer
) return CLASS_E_NOAGGREGATION
;
1686 This
= heap_alloc(sizeof(*This
));
1687 if(!This
) return E_OUTOFMEMORY
;
1689 This
->IDataConvert_iface
.lpVtbl
= &convert_vtbl
;
1690 This
->IDCInfo_iface
.lpVtbl
= &dcinfo_vtbl
;
1692 This
->version
= 0x110;
1694 *obj
= &This
->IDataConvert_iface
;