oledb32: Implement DBTYPE_BSTR to DBTYPE_VARIANT conversion.

This commit is contained in:
Nikolay Sivov 2013-04-07 23:28:33 +04:00 committed by Alexandre Julliard
parent 960852f447
commit 38a362a25c
2 changed files with 61 additions and 0 deletions

View File

@ -145,6 +145,8 @@ static int get_length(DBTYPE type)
case DBTYPE_STR:
case DBTYPE_BYREF | DBTYPE_WSTR:
return 0;
case DBTYPE_VARIANT:
return sizeof(VARIANT);
default:
FIXME("Unhandled type %04x\n", type);
return 0;
@ -727,6 +729,26 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
return hr;
}
case DBTYPE_VARIANT:
{
VARIANT *v = dst;
switch(src_type)
{
case DBTYPE_BSTR:
{
BSTR s = *(WCHAR**)src;
TRACE("%s\n", debugstr_w(s));
V_VT(v) = VT_BSTR;
V_BSTR(v) = SysAllocString(s);
hr = V_BSTR(v) ? S_OK : E_OUTOFMEMORY;
}
break;
default: FIXME("Unimplemented conversion %04x -> VARIANT\n", src_type); return E_NOTIMPL;
}
break;
}
default:
FIXME("Unimplemented conversion %04x -> %04x\n", src_type, dst_type);
return E_NOTIMPL;

View File

@ -2440,6 +2440,7 @@ static void test_getconversionsize(void)
IDataConvert *convert;
DBLENGTH dst_len;
HRESULT hr;
BSTR str;
hr = CoCreateInstance(&CLSID_OLEDB_CONVERSIONLIBRARY, NULL, CLSCTX_INPROC_SERVER, &IID_IDataConvert, (void**)&convert);
if(FAILED(hr))
@ -2461,6 +2462,43 @@ static void test_getconversionsize(void)
hr = IDataConvert_GetConversionSize(convert, DBTYPE_I2, DBTYPE_I4, NULL, NULL, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
/* size doesn't include string size */
str = SysAllocStringLen(NULL, 10);
dst_len = 0;
hr = IDataConvert_GetConversionSize(convert, DBTYPE_BSTR, DBTYPE_VARIANT, NULL, &dst_len, str);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(dst_len == sizeof(VARIANT), "%ld\n", dst_len);
SysFreeString(str);
IDataConvert_Release(convert);
}
static void test_converttovar(void)
{
static WCHAR strW[] = {'t','e','s','t',0};
IDataConvert *convert;
DBSTATUS dst_status;
DBLENGTH dst_len;
VARIANT dst;
HRESULT hr;
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;
}
V_VT(&dst) = VT_EMPTY;
dst_len = 0;
hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_VARIANT, sizeof(strW), &dst_len, strW, &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 %ld\n", dst_len);
ok(V_VT(&dst) == VT_BSTR, "got %d\n", V_VT(&dst));
ok(!lstrcmpW(V_BSTR(&dst), strW), "got %s\n", wine_dbgstr_w(V_BSTR(&dst)));
VariantClear(&dst);
IDataConvert_Release(convert);
}
@ -2482,6 +2520,7 @@ START_TEST(convert)
test_converttofiletime();
test_converttocy();
test_converttoui8();
test_converttovar();
test_getconversionsize();
OleUninitialize();
}