From a2e069b15989af1b2c2f2f33c6df6645a72fe91b Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Wed, 23 Sep 2009 14:46:55 +0100 Subject: [PATCH] oledb32: Implement conversions to DBTYPE_BSTR. --- dlls/oledb32/convert.c | 27 +++++++++++++++++ dlls/oledb32/tests/convert.c | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index 6af4f092b4..6cdc9d64af 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -126,6 +126,8 @@ static int get_length(DBTYPE type) case DBTYPE_I8: case DBTYPE_UI8: return 8; + case DBTYPE_BSTR: + return sizeof(BSTR); default: FIXME("Unhandled type %04x\n", type); return 0; @@ -250,6 +252,31 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, break; } + case DBTYPE_BSTR: + { + BSTR *d = dst; + switch(src_type) + { + case DBTYPE_EMPTY: *d = SysAllocStringLen(NULL, 0); hr = *d ? S_OK : E_OUTOFMEMORY; break; + case DBTYPE_I2: hr = VarBstrFromI2(*(signed short*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_I4: hr = VarBstrFromI4(*(signed int*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_R4: hr = VarBstrFromR4(*(FLOAT*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_R8: hr = VarBstrFromR8(*(double*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_CY: hr = VarBstrFromCy(*(CY*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_DATE: hr = VarBstrFromDate(*(DATE*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_BSTR: *d = SysAllocStringLen(*(BSTR*)src, SysStringLen(*(BSTR*)src)); hr = *d ? S_OK : E_OUTOFMEMORY; break; + case DBTYPE_BOOL: hr = VarBstrFromBool(*(VARIANT_BOOL*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_DECIMAL: hr = VarBstrFromDec((DECIMAL*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_I1: hr = VarBstrFromI1(*(signed char*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_UI1: hr = VarBstrFromUI1(*(BYTE*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_UI2: hr = VarBstrFromUI2(*(WORD*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_UI4: hr = VarBstrFromUI4(*(DWORD*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_I8: hr = VarBstrFromI8(*(LONGLONG*)src, LOCALE_USER_DEFAULT, 0, d); break; + case DBTYPE_UI8: hr = VarBstrFromUI8(*(ULONGLONG*)src, LOCALE_USER_DEFAULT, 0, d); break; + default: FIXME("Unimplemented conversion %04x -> BSTR\n", src_type); return E_NOTIMPL; + } + break; + } default: FIXME("Unimplemented conversion %04x -> %04x\n", src_type, dst_type); return E_NOTIMPL; diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index 156c5ca1e2..658670f743 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -843,6 +843,63 @@ todo_wine IDataConvert_Release(convert); } +static void test_converttobstr(void) +{ + IDataConvert *convert; + HRESULT hr; + BSTR dst; + BYTE src[20]; + DBSTATUS dst_status; + DBLENGTH dst_len; + static const WCHAR ten[] = {'1','0',0}; + BSTR b; + + hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert); + if(FAILED(hr)) + { + win_skip("Unable to load oledb conversion library\n"); + return; + } + + hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %d\n", dst_len); + ok(dst != NULL, "got %p\n", dst); + ok(SysStringLen(dst) == 0, "got %d\n", SysStringLen(dst)); + SysFreeString(dst); + + dst = (void*)0x1234; + hr = IDataConvert_DataConvert(convert, DBTYPE_NULL, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr); + ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %d\n", dst_len); + ok(dst == (void*)0x1234, "got %p\n", dst); + + *(short *)src = 4321; + hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %d\n", dst_len); + ok(dst != NULL, "got %p\n", dst); + ok(SysStringLen(dst) == 4, "got %d\n", SysStringLen(dst)); + SysFreeString(dst); + + b = SysAllocString(ten); + *(BSTR *)src = b; + hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_BSTR, 0, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(dst_len == sizeof(dst), "got %d\n", dst_len); + ok(dst != NULL, "got %p\n", dst); + ok(dst != b, "got %p src %p\n", dst, b); + ok(!lstrcmpW(b, dst), "got %s\n", wine_dbgstr_w(dst)); + SysFreeString(dst); + SysFreeString(b); + + IDataConvert_Release(convert); +} + START_TEST(convert) { @@ -851,5 +908,6 @@ START_TEST(convert) test_canconvert(); test_converttoi2(); test_converttoi4(); + test_converttobstr(); OleUninitialize(); }