oledb32: Implement DBTYPE_STR and DBTYPE_WSTR src types.

This commit is contained in:
Huw Davies 2009-09-22 16:58:24 +01:00 committed by Alexandre Julliard
parent a3d947c70f
commit 4a61c1d265
2 changed files with 42 additions and 17 deletions

View File

@ -25,6 +25,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winnls.h"
#include "ole2.h" #include "ole2.h"
#include "msdadc.h" #include "msdadc.h"
#include "oledberr.h" #include "oledberr.h"
@ -143,7 +144,7 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
convert *This = impl_from_IDataConvert(iface); convert *This = impl_from_IDataConvert(iface);
HRESULT hr; 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_type, dst_type, src_len, dst_len, src, dst, dst_max_len,
src_status, dst_status, precision, scale, flags); src_status, dst_status, precision, scale, flags);
@ -155,6 +156,46 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
return DB_E_UNSUPPORTEDCONVERSION; 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) switch(dst_type)
{ {
case DBTYPE_I4: case DBTYPE_I4:

View File

@ -541,49 +541,33 @@ todo_wine
i4 = 0x12345678; i4 = 0x12345678;
strcpy((char *)src, "10"); 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); 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(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
}
ok(dst_len == sizeof(i4), "got %d\n", dst_len); ok(dst_len == sizeof(i4), "got %d\n", dst_len);
todo_wine
ok(i4 == 10, "got %08x\n", i4); ok(i4 == 10, "got %08x\n", i4);
i4 = 0x12345678; i4 = 0x12345678;
strcpy((char *)src, "10"); 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); 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(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
}
ok(dst_len == sizeof(i4), "got %d\n", dst_len); ok(dst_len == sizeof(i4), "got %d\n", dst_len);
todo_wine
ok(i4 == 10, "got %08x\n", i4); ok(i4 == 10, "got %08x\n", i4);
i4 = 0x12345678; i4 = 0x12345678;
memcpy(src, ten, sizeof(ten)); 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); 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(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
}
ok(dst_len == sizeof(i4), "got %d\n", dst_len); ok(dst_len == sizeof(i4), "got %d\n", dst_len);
todo_wine
ok(i4 == 10, "got %08x\n", i4); ok(i4 == 10, "got %08x\n", i4);
i4 = 0x12345678; i4 = 0x12345678;
memcpy(src, ten, sizeof(ten)); 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); 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(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
}
ok(dst_len == sizeof(i4), "got %d\n", dst_len); ok(dst_len == sizeof(i4), "got %d\n", dst_len);
todo_wine
ok(i4 == 10, "got %08x\n", i4); ok(i4 == 10, "got %08x\n", i4);
IDataConvert_Release(convert); IDataConvert_Release(convert);