msdasql: ICommandText Execute use ODBC to fetch results.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alistair Leslie-Hughes 2022-02-06 19:07:36 +11:00 committed by Alexandre Julliard
parent 111c87f444
commit 50fc9d7ddc
2 changed files with 56 additions and 18 deletions

View File

@ -477,6 +477,7 @@ struct msdasql_rowset
IColumnsRowset IColumnsRowset_iface;
IUnknown *caller;
LONG refs;
SQLHSTMT hstmt;
};
static inline struct msdasql_rowset *impl_from_IRowset( IRowset *iface )
@ -575,6 +576,8 @@ static ULONG WINAPI msdasql_rowset_Release(IRowset *iface)
{
TRACE( "destroying %p\n", rowset );
SQLFreeHandle(SQL_HANDLE_STMT, rowset->hstmt);
if (rowset->caller)
IUnknown_Release(rowset->caller);
@ -845,27 +848,53 @@ static HRESULT WINAPI command_Execute(ICommandText *iface, IUnknown *outer, REFI
{
struct command *command = impl_from_ICommandText( iface );
struct msdasql_rowset *msrowset;
HRESULT hr;
HRESULT hr = S_OK;
RETCODE ret;
SQLHSTMT hstmt = command->hstmt;
SQLLEN results = -1;
FIXME("%p, %p, %s, %p %p %p Semi Stub\n", command, outer, debugstr_guid(riid), params, affected, rowset);
TRACE("%p, %p, %s, %p %p %p\n", command, outer, debugstr_guid(riid), params, affected, rowset);
msrowset = heap_alloc(sizeof(*msrowset));
if (!msrowset)
return E_OUTOFMEMORY;
if (!hstmt)
SQLAllocHandle(SQL_HANDLE_STMT, command->hdbc, &hstmt);
msrowset->IRowset_iface.lpVtbl = &msdasql_rowset_vtbl;
msrowset->IRowsetInfo_iface.lpVtbl = &rowset_info_vtbl;
msrowset->IColumnsInfo_iface.lpVtbl = &rowset_columninfo_vtbll;
msrowset->IAccessor_iface.lpVtbl = &accessor_vtbl;
msrowset->IColumnsRowset_iface.lpVtbl = &columnrs_rs_vtbl;
msrowset->refs = 1;
ICommandText_QueryInterface(iface, &IID_IUnknown, (void**)&msrowset->caller);
ret = SQLExecDirectW(hstmt, command->query, SQL_NTS);
if (ret != SQL_SUCCESS)
{
dump_sql_diag_records(SQL_HANDLE_STMT, hstmt);
return E_FAIL;
}
ret = SQLRowCount(hstmt, &results);
if (ret != SQL_SUCCESS)
ERR("SQLRowCount failed (%d)\n", ret);
if (affected)
*affected = 0; /* FIXME */
*affected = results;
hr = IRowset_QueryInterface(&msrowset->IRowset_iface, riid, (void**)rowset);
IRowset_Release(&msrowset->IRowset_iface);
*rowset = NULL;
if (!wcsnicmp( command->query, L"select ", 7 ))
{
msrowset = heap_alloc(sizeof(*msrowset));
if (!msrowset)
return E_OUTOFMEMORY;
command->hstmt = NULL;
msrowset->IRowset_iface.lpVtbl = &msdasql_rowset_vtbl;
msrowset->IRowsetInfo_iface.lpVtbl = &rowset_info_vtbl;
msrowset->IColumnsInfo_iface.lpVtbl = &rowset_columninfo_vtbll;
msrowset->IAccessor_iface.lpVtbl = &accessor_vtbl;
msrowset->IColumnsRowset_iface.lpVtbl = &columnrs_rs_vtbl;
msrowset->refs = 1;
ICommandText_QueryInterface(iface, &IID_IUnknown, (void**)&msrowset->caller);
msrowset->hstmt = hstmt;
hr = IRowset_QueryInterface(&msrowset->IRowset_iface, riid, (void**)rowset);
IRowset_Release(&msrowset->IRowset_iface);
}
else
SQLFreeStmt(hstmt, SQL_CLOSE);
return hr;
}

View File

@ -382,11 +382,20 @@ static void test_command_rowset(IUnknown *cmd)
affected = 9999;
hr = ICommandText_Execute(command_text, NULL, &IID_IRowset, NULL, &affected, &unk);
ok(hr == S_OK, "got 0x%08lx\n", hr);
todo_wine ok(unk == NULL, "Unexpected value\n");
todo_wine ok(affected == -1, "got %Id\n", affected);
ok(unk == NULL, "Unexpected value\n");
ok(affected == -1, "got %Id\n", affected);
if (unk)
IUnknown_Release(unk);
hr = ICommandText_SetCommandText(command_text, &DBGUID_DEFAULT, L"insert into testing values(1, 0)");
ok(hr == S_OK, "got 0x%08lx\n", hr);
affected = 9999;
hr = ICommandText_Execute(command_text, NULL, &IID_IRowset, NULL, &affected, &unk);
ok(hr == S_OK, "got 0x%08lx\n", hr);
ok(affected == 1, "got %Id\n", affected);
ok(unk == NULL, "Unexpected value\n");
hr = ICommandText_SetCommandText(command_text, &DBGUID_DEFAULT, L"select * from testing");
ok(hr == S_OK, "got 0x%08lx\n", hr);
@ -396,7 +405,7 @@ static void test_command_rowset(IUnknown *cmd)
ok(unk != NULL, "Unexpected value\n");
if (hr == S_OK)
{
ok(affected == -1, "wrong affected value\n");
ok(affected == -1, "got %Id\n", affected);
hr = IUnknown_QueryInterface(unk, &IID_IRowset, (void**)&rowset);
ok(hr == S_OK, "got 0x%08lx\n", hr);