From 0d6eadc4a98db83c342f8252ced26b548a171b5a Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Thu, 23 May 2013 10:56:44 +1000 Subject: [PATCH] oledb32: Implement DataConvert DBTYPE_VARIANT->DBTYPE_DATE. --- dlls/oledb32/convert.c | 21 +++++++++++++++++++++ dlls/oledb32/tests/convert.c | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index ab188ee0505..61a2be6cac0 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -428,6 +428,27 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, switch (src_type) { case DBTYPE_DBDATE: memcpy(d, src, sizeof(DBDATE)); hr = S_OK; break; + case DBTYPE_BSTR: + { + VARIANT var; + BSTR s = *(WCHAR**)src; + + VariantInit(&var); + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(s); + + if ((hr = VariantChangeType(&var, &var, 0, VT_DATE)) == S_OK) + { + SYSTEMTIME st; + hr = (VariantTimeToSystemTime( V_DATE(&var), &st) ? S_OK : E_FAIL); + d->year = st.wYear; + d->month = st.wMonth; + d->day = st.wDay; + } + + VariantClear(&var); + } + break; case DBTYPE_VARIANT: if( V_VT((VARIANT*)src) == VT_DATE) { diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index 92d3a6404c4..b3eda95f493 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -2467,10 +2467,12 @@ static void test_converttodbdate(void) { DBLENGTH dst_len; HRESULT hr; + static WCHAR strW[] = {'2','0','1','3','-','0','5','-','1','4',0}; DBDATE ts = {2013, 5, 14}; DBDATE dst; DBSTATUS dst_status; VARIANT var; + BSTR bstr; dst_len = 0; hr = IDataConvert_DataConvert(convert, DBTYPE_DBDATE, DBTYPE_DBDATE, sizeof(ts), &dst_len, &ts, &dst, 2, 0, &dst_status, 0, 0, 0); @@ -2488,6 +2490,15 @@ static void test_converttodbdate(void) ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_len == sizeof(DBDATE), "got %ld\n", dst_len); ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n"); + + dst_len = 0; + bstr = SysAllocString(strW); + hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_DBDATE, 0, &dst_len, &bstr, &dst, 2, 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(DBDATE), "got %ld\n", dst_len); + ok(!memcmp(&ts, &dst, sizeof(DBDATE) ), "bytes differ\n"); + SysFreeString(bstr); }