oledb32: Implement some conversions to DBTYPE_I4.

This commit is contained in:
Huw Davies 2009-09-22 16:17:22 +01:00 committed by Alexandre Julliard
parent 73b3d35d05
commit a3d947c70f
2 changed files with 133 additions and 26 deletions

View File

@ -109,21 +109,95 @@ static ULONG WINAPI convert_Release(IDataConvert* iface)
return ref;
}
static int get_length(DBTYPE type)
{
switch(type)
{
case DBTYPE_I1:
case DBTYPE_UI1:
return 1;
case DBTYPE_I2:
case DBTYPE_UI2:
return 2;
case DBTYPE_I4:
case DBTYPE_UI4:
return 4;
case DBTYPE_I8:
case DBTYPE_UI8:
return 8;
default:
FIXME("Unhandled type %04x\n", type);
return 0;
}
}
static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
DBTYPE wSrcType, DBTYPE wDstType,
DBLENGTH cbSrcLength, DBLENGTH *pcbDstLength,
void *pSrc, void *pDst,
DBLENGTH cbDstMaxLength,
DBSTATUS dbsSrcStatus, DBSTATUS *pdbsDstStatus,
BYTE bPrecision, BYTE bScale,
DBDATACONVERT dwFlags)
DBTYPE src_type, DBTYPE dst_type,
DBLENGTH src_len, DBLENGTH *dst_len,
void *src, void *dst,
DBLENGTH dst_max_len,
DBSTATUS src_status, DBSTATUS *dst_status,
BYTE precision, BYTE scale,
DBDATACONVERT flags)
{
convert *This = impl_from_IDataConvert(iface);
FIXME("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x): stub\n", This,
wSrcType, wDstType, cbSrcLength, pcbDstLength, pSrc, pDst, cbDstMaxLength,
dbsSrcStatus, pdbsDstStatus, bPrecision, bScale, dwFlags);
HRESULT hr;
TRACE("(%p)->(%d, %d, %d, %p, %p, %p, %d, %d, %p, %d, %d, %x): stub\n", This,
src_type, dst_type, src_len, dst_len, src, dst, dst_max_len,
src_status, dst_status, precision, scale, flags);
*dst_len = get_length(dst_type);
*dst_status = DBSTATUS_E_BADACCESSOR;
if(IDataConvert_CanConvert(iface, src_type, dst_type) != S_OK)
{
return DB_E_UNSUPPORTEDCONVERSION;
}
switch(dst_type)
{
case DBTYPE_I4:
{
signed int *d = dst;
switch(src_type)
{
case DBTYPE_EMPTY: *d = 0; hr = S_OK; break;
case DBTYPE_I2: hr = VarI4FromI2(*(signed short*)src, d); break;
case DBTYPE_I4: *d = *(signed int*)src; hr = S_OK; break;
case DBTYPE_R4: hr = VarI4FromR4(*(FLOAT*)src, d); break;
case DBTYPE_R8: hr = VarI4FromR8(*(double*)src, d); break;
case DBTYPE_CY: hr = VarI4FromCy(*(CY*)src, d); break;
case DBTYPE_DATE: hr = VarI4FromDate(*(DATE*)src, d); break;
case DBTYPE_BSTR: hr = VarI4FromStr(*(WCHAR**)src, LOCALE_USER_DEFAULT, 0, d); break;
case DBTYPE_BOOL: hr = VarI4FromBool(*(VARIANT_BOOL*)src, d); break;
case DBTYPE_DECIMAL: hr = VarI4FromDec((DECIMAL*)src, d); break;
case DBTYPE_I1: hr = VarI4FromI1(*(signed char*)src, d); break;
case DBTYPE_UI1: hr = VarI4FromUI1(*(BYTE*)src, d); break;
case DBTYPE_UI2: hr = VarI4FromUI2(*(WORD*)src, d); break;
case DBTYPE_UI4: hr = VarI4FromUI4(*(DWORD*)src, d); break;
case DBTYPE_I8: hr = VarI4FromI8(*(LONGLONG*)src, d); break;
case DBTYPE_UI8: hr = VarI4FromUI8(*(ULONGLONG*)src, d); break;
default: FIXME("Unimplemented conversion %04x -> I4\n", src_type); return E_NOTIMPL;
}
break;
}
default:
FIXME("Unimplemented conversion %04x -> %04x\n", src_type, dst_type);
return E_NOTIMPL;
}
if(hr == DISP_E_OVERFLOW)
{
*dst_status = DBSTATUS_E_DATAOVERFLOW;
hr = DB_E_ERRORSOCCURRED;
}
else if(hr == S_OK)
*dst_status = DBSTATUS_S_OK;
return hr;
}
static inline WORD get_dbtype_class(DBTYPE type)

View File

@ -356,8 +356,6 @@ static void test_converttoi4(void)
return;
}
todo_wine
{
i4 = 0x12345678;
hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
ok(hr == S_OK, "got %08x\n", hr);
@ -370,11 +368,8 @@ todo_wine
ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
ok(dst_len == sizeof(i4), "got %d\n", dst_len);
}
ok(i4 == 0x12345678, "got %08x\n", i4);
todo_wine
{
i4 = 0x12345678;
*(short *)src = 0x4321;
hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
@ -447,11 +442,8 @@ todo_wine
ok(hr == DB_E_UNSUPPORTEDCONVERSION, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_BADACCESSOR, "got %08x\n", dst_status);
ok(dst_len == sizeof(i4), "got %d\n", dst_len);
}
ok(i4 == 0x12345678, "got %08x\n", i4);
todo_wine
{
i4 = 0x12345678;
*(VARIANT_BOOL *)src = VARIANT_TRUE;
hr = IDataConvert_DataConvert(convert, DBTYPE_BOOL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
@ -472,6 +464,19 @@ todo_wine
V_VT((VARIANT*)src) = VT_I2;
V_I2((VARIANT*)src) = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_I4, 0, &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 == 0x1234, "got %08x\n", i4);
i4 = 0x12345678;
memset(src, 0, sizeof(DECIMAL));
((DECIMAL*)src)->u1.Lo64 = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_DECIMAL, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 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(i4), "got %d\n", dst_len);
@ -507,11 +512,8 @@ todo_wine
ok(hr == DB_E_ERRORSOCCURRED, "got %08x\n", hr);
ok(dst_status == DBSTATUS_E_DATAOVERFLOW, "got %08x\n", dst_status);
ok(dst_len == sizeof(i4), "got %d\n", dst_len);
}
ok(i4 == 0x12345678, "got %08x\n", i4);
todo_wine
{
i4 = 0x12345678;
*(DWORD*)src = 0x1234abcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI4, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 0, &dst_status, 0, 0, 0);
@ -521,37 +523,68 @@ todo_wine
ok(i4 == 0x1234abcd, "got %08x\n", i4);
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);
((LARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_I8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 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(i4), "got %d\n", dst_len);
ok(i4 == 0x1234abcd, "got %08x\n", i4);
i4 = 0x12345678;
((ULARGE_INTEGER*)src)->QuadPart = 0x1234abcd;
hr = IDataConvert_DataConvert(convert, DBTYPE_UI8, DBTYPE_I4, 0, &dst_len, src, &i4, sizeof(i4), 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(i4), "got %d\n", dst_len);
ok(i4 == 0x1234abcd, "got %08x\n", i4);
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);
ok(i4 == 10, "got %08x\n", i4);
}
ok(dst_len == sizeof(i4), "got %d\n", dst_len);
todo_wine
ok(i4 == 10, "got %08x\n", i4);
IDataConvert_Release(convert);
}