From 5f236f1a5c25820f1a7d25c6664e96e2e054aae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Mon, 5 Apr 2010 11:39:08 -0500 Subject: [PATCH] oledb32: Implemented OLEDB32 conversion to DBTYPE_STR. --- dlls/oledb32/convert.c | 32 ++++++++++++++++++++++++++++++++ dlls/oledb32/tests/convert.c | 32 +++----------------------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index 27ff58595ce..4f2c303929b 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -136,6 +136,7 @@ static int get_length(DBTYPE type) case DBTYPE_GUID: return sizeof(GUID); case DBTYPE_WSTR: + case DBTYPE_STR: case DBTYPE_BYREF | DBTYPE_WSTR: return 0; default: @@ -473,6 +474,37 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface, SysFreeString(b); return hr; } + case DBTYPE_STR: + { + BSTR b; + DBLENGTH bstr_len; + INT bytes_to_copy; + hr = IDataConvert_DataConvert(iface, src_type, DBTYPE_BSTR, src_len, &bstr_len, + src, &b, sizeof(BSTR), src_status, dst_status, + precision, scale, flags); + if(hr != S_OK) return hr; + bstr_len = SysStringLen(b); + *dst_len = bstr_len * sizeof(char); /* Doesn't include size for '\0' */ + *dst_status = DBSTATUS_S_OK; + bytes_to_copy = min(*dst_len + sizeof(char), dst_max_len); + if(dst) + { + if(bytes_to_copy >= sizeof(char)) + { + WideCharToMultiByte(CP_ACP, 0, b, bytes_to_copy - sizeof(char), dst, dst_max_len, NULL, NULL); + *((char *)dst + bytes_to_copy / sizeof(char) - 1) = 0; + if(bytes_to_copy < *dst_len + sizeof(char)) + *dst_status = DBSTATUS_S_TRUNCATED; + } + else + { + *dst_status = DBSTATUS_E_DATAOVERFLOW; + hr = DB_E_ERRORSOCCURRED; + } + } + SysFreeString(b); + return hr; + } case DBTYPE_BYREF | DBTYPE_WSTR: { diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index e20d6199650..eb62e91b094 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -1059,10 +1059,10 @@ static void test_converttostr(void) memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_EMPTY, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 0, &dst_status, 0, 0, 0); - todo_wine ok(hr == S_OK, "got %08x\n", hr); - todo_wine ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); + ok(hr == S_OK, "got %08x\n", hr); + ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status); ok(dst_len == 0, "got %d\n", dst_len); - todo_wine ok(dst[0] == 0, "got %02x\n", dst[0]); + ok(dst[0] == 0, "got %02x\n", dst[0]); ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]); memset(dst, 0xcc, sizeof(dst)); @@ -1074,60 +1074,49 @@ static void test_converttostr(void) *(short *)src = 4321; hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 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 == 4, "got %d\n", dst_len); ok(!lstrcmpA(dst, fourthreetwoone), "got %s\n", dst); - } *(short *)src = 4321; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 0, 0, &dst_status, 0, 0, 0); - 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 == 4, "got %d\n", dst_len); - } ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]); *(short *)src = 4321; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, NULL, 0, 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 == 4, "got %d\n", dst_len); - } ok(dst[0] == (char)0xcc, "got %02x\n", dst[0]); *(short *)src = 4321; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 2, 0, &dst_status, 0, 0, 0); - todo_wine { ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status); ok(dst_len == 4, "got %d\n", dst_len); ok(dst[0] == '4', "got %02x\n", dst[0]); ok(dst[1] == 0, "got %02x\n", dst[1]); - } ok(dst[2] == (char)0xcc, "got %02x\n", dst[2]); *(short *)src = 4321; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 1, 0, &dst_status, 0, 0, 0); - todo_wine { ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status); ok(dst_len == 4, "got %d\n", dst_len); ok(dst[0] == 0, "got %02x\n", dst[0]); - } ok(dst[1] == (char)0xcc, "got %02x\n", dst[1]); *(short *)src = 4321; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_I2, DBTYPE_STR, 0, &dst_len, src, dst, 4, 0, &dst_status, 0, 0, 0); - todo_wine { ok(hr == S_OK, "got %08x\n", hr); ok(dst_status == DBSTATUS_S_TRUNCATED, "got %08x\n", dst_status); ok(dst_len == 4, "got %d\n", dst_len); @@ -1135,84 +1124,69 @@ static void test_converttostr(void) ok(dst[1] == '3', "got %02x\n", dst[1]); ok(dst[2] == '2', "got %02x\n", dst[2]); ok(dst[3] == 0, "got %02x\n", dst[3]); - } ok(dst[4] == (char)0xcc, "got %02x\n", dst[4]); b = SysAllocString(ten); *(BSTR *)src = b; memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_BSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 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 == 2, "got %d\n", dst_len); ok(!lstrcmpA(ten_a, dst), "got %s\n", dst); - } SysFreeString(b); memcpy(src, ten, sizeof(ten)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 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 == 1, "got %d\n", dst_len); ok(dst[0] == '1', "got %02x\n", dst[0]); ok(dst[1] == 0, "got %02x\n", dst[1]); - } memcpy(src, ten, sizeof(ten)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 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 == 2, "got %d\n", dst_len); ok(!lstrcmpA(ten_a, dst), "got %s\n", dst); - } memcpy(src, ten, sizeof(ten)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_WSTR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 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 == 2, "got %d\n", dst_len); ok(!lstrcmpA(ten_a, dst), "got %s\n", dst); - } memcpy(src, ten_a, sizeof(ten_a)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 2, &dst_len, src, dst, sizeof(dst), 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 == 2, "got %d\n", dst_len); ok(dst[0] == '1', "got %02x\n", dst[0]); ok(dst[1] == '0', "got %02x\n", dst[1]); ok(dst[2] == 0, "got %02x\n", dst[2]); - } ok(dst[3] == (char)0xcc, "got %02x\n", dst[3]); memcpy(src, ten_a, sizeof(ten_a)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 4, &dst_len, src, dst, sizeof(dst), 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 == 4, "got %d\n", dst_len); ok(!lstrcmpA(ten_a, dst), "got %s\n", dst); - } memcpy(src, ten_a, sizeof(ten_a)); memset(dst, 0xcc, sizeof(dst)); hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR, 0, &dst_len, src, dst, sizeof(dst), 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 == 2, "got %d\n", dst_len); ok(!lstrcmpA(ten_a, dst), "got %s\n", dst); - } IDataConvert_Release(convert); }