From 4a61c1d265adc3cbfee7edb7ac4abf310735c4a4 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 22 Sep 2009 16:58:24 +0100 Subject: [PATCH] oledb32: Implement DBTYPE_STR and DBTYPE_WSTR src types. --- dlls/oledb32/convert.c | 43 +++++++++++++++++++++++++++++++++++- dlls/oledb32/tests/convert.c | 16 -------------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index f49a699cc11..9803caf61eb 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -25,6 +25,7 @@ #include "windef.h" #include "winbase.h" +#include "winnls.h" #include "ole2.h" #include "msdadc.h" #include "oledberr.h" @@ -143,7 +144,7 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, convert *This = impl_from_IDataConvert(iface); HRESULT hr; - TRACE("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x): stub\n", This, + TRACE("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x)\n", This, src_type, dst_type, src_len, dst_len, src, dst, dst_max_len, src_status, dst_status, precision, scale, flags); @@ -155,6 +156,46 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, return DB_E_UNSUPPORTEDCONVERSION; } + if(src_type == DBTYPE_STR) + { + BSTR b; + DWORD len; + + if(flags & DBDATACONVERT_LENGTHFROMNTS) + len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0) - 1; + else + len = MultiByteToWideChar(CP_ACP, 0, src, src_len, NULL, 0); + b = SysAllocStringLen(NULL, len); + if(!b) return E_OUTOFMEMORY; + if(flags & DBDATACONVERT_LENGTHFROMNTS) + MultiByteToWideChar(CP_ACP, 0, src, -1, b, len + 1); + else + MultiByteToWideChar(CP_ACP, 0, src, src_len, b, len); + + hr = IDataConvert_DataConvert(iface, DBTYPE_BSTR, dst_type, 0, dst_len, + &b, dst, dst_max_len, src_status, dst_status, + precision, scale, flags); + + SysFreeString(b); + return hr; + } + + if(src_type == DBTYPE_WSTR) + { + BSTR b; + + if(flags & DBDATACONVERT_LENGTHFROMNTS) + b = SysAllocString(src); + else + b = SysAllocStringLen(src, src_len / 2); + if(!b) return E_OUTOFMEMORY; + hr = IDataConvert_DataConvert(iface, DBTYPE_BSTR, dst_type, 0, dst_len, + &b, dst, dst_max_len, src_status, dst_status, + precision, scale, flags); + SysFreeString(b); + return hr; + } + switch(dst_type) { case DBTYPE_I4: diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index acda3a99aa2..7a733c28463 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -541,49 +541,33 @@ todo_wine i4 = 0x12345678; strcpy((char *)src, "10"); hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 2, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0); -todo_wine -{ ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); -} ok(dst_len == sizeof(i4), "got %d\n", dst_len); -todo_wine ok(i4 == 10, "got %08x\n", i4); i4 = 0x12345678; strcpy((char *)src, "10"); hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS); -todo_wine -{ ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); -} ok(dst_len == sizeof(i4), "got %d\n", dst_len); -todo_wine ok(i4 == 10, "got %08x\n", i4); i4 = 0x12345678; memcpy(src, ten, sizeof(ten)); hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 4, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0); -todo_wine -{ ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); -} ok(dst_len == sizeof(i4), "got %d\n", dst_len); -todo_wine ok(i4 == 10, "got %08x\n", i4); i4 = 0x12345678; memcpy(src, ten, sizeof(ten)); hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, DBDATACONVERT_LENGTHFROMNTS); -todo_wine -{ ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); -} ok(dst_len == sizeof(i4), "got %d\n", dst_len); -todo_wine ok(i4 == 10, "got %08x\n", i4); IDataConvert_Release(convert);