From 7fce75805cbd3159d62295d7edccd5d8d252875c Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 13 Dec 2019 15:52:24 +0100 Subject: [PATCH] msado15: Implement _Recordset_AddNew. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/msado15/recordset.c | 29 +++++++++++++++++++++-- dlls/msado15/tests/msado15.c | 46 +++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/dlls/msado15/recordset.c b/dlls/msado15/recordset.c index e854b3e8247..f1c864cdd9b 100644 --- a/dlls/msado15/recordset.c +++ b/dlls/msado15/recordset.c @@ -887,10 +887,35 @@ static HRESULT WINAPI recordset_get_Source( _Recordset *iface, VARIANT *source ) return E_NOTIMPL; } +static BOOL resize_recordset( struct recordset *recordset, ULONG row_count ) +{ + ULONG row_size = get_column_count( recordset ) * sizeof(*recordset->data); + + if (row_count > recordset->allocated) + { + VARIANT *tmp; + ULONG count = max( row_count, recordset->allocated * 2 ); + if (!(tmp = heap_realloc_zero( recordset->data, count * row_size ))) return FALSE; + recordset->data = tmp; + recordset->allocated = count; + } + + recordset->count = row_count; + return TRUE; +} + static HRESULT WINAPI recordset_AddNew( _Recordset *iface, VARIANT field_list, VARIANT values ) { - FIXME( "%p, %s, %s\n", iface, debugstr_variant(&field_list), debugstr_variant(&values) ); - return E_NOTIMPL; + struct recordset *recordset = impl_from_Recordset( iface ); + + TRACE( "%p, %s, %s\n", recordset, debugstr_variant(&field_list), debugstr_variant(&values) ); + FIXME( "ignoring field list and values\n" ); + + if (recordset->state == adStateClosed) return MAKE_ADO_HRESULT( adErrObjectClosed ); + + if (!resize_recordset( recordset, recordset->count + 1 )) return E_OUTOFMEMORY; + recordset->index++; + return S_OK; } static HRESULT WINAPI recordset_CancelUpdate( _Recordset *iface ) diff --git a/dlls/msado15/tests/msado15.c b/dlls/msado15/tests/msado15.c index f9a5377c50f..3b1e953dc75 100644 --- a/dlls/msado15/tests/msado15.c +++ b/dlls/msado15/tests/msado15.c @@ -47,7 +47,9 @@ static void test_Recordset(void) { _Recordset *recordset; Fields *fields, *fields2; - LONG refs, count; + LONG refs, count, state; + VARIANT missing; + BSTR name; HRESULT hr; hr = CoCreateInstance( &CLSID_Recordset, NULL, CLSCTX_INPROC_SERVER, &IID__Recordset, (void **)&recordset ); @@ -92,6 +94,48 @@ static void test_Recordset(void) /* fields object still has a reference */ refs = Fields_Release( fields2 ); ok( refs == 1, "got %d\n", refs ); + + hr = CoCreateInstance( &CLSID_Recordset, NULL, CLSCTX_INPROC_SERVER, &IID__Recordset, (void **)&recordset ); + ok( hr == S_OK, "got %08x\n", hr ); + + state = -1; + hr = _Recordset_get_State( recordset, &state ); + todo_wine ok( hr == S_OK, "got %08x\n", hr ); + todo_wine ok( state == adStateClosed, "got %d\n", state ); + + VariantInit( &missing ); + hr = _Recordset_AddNew( recordset, missing, missing ); + ok( hr == MAKE_ADO_HRESULT( adErrObjectClosed ), "got %08x\n", hr ); + + V_VT( &missing ) = VT_ERROR; + V_ERROR( &missing ) = DISP_E_PARAMNOTFOUND; + hr = _Recordset_Open( recordset, missing, missing, adOpenStatic, adLockBatchOptimistic, adCmdUnspecified ); + todo_wine ok( hr == MAKE_ADO_HRESULT( adErrInvalidConnection ), "got %08x\n", hr ); + + hr = _Recordset_get_Fields( recordset, &fields ); + ok( hr == S_OK, "got %08x\n", hr ); + + name = SysAllocString( L"field" ); + hr = Fields__Append( fields, name, adInteger, 4, adFldUnspecified ); + ok( hr == S_OK, "got %08x\n", hr ); + SysFreeString( name ); + + hr = _Recordset_Open( recordset, missing, missing, adOpenStatic, adLockBatchOptimistic, adCmdUnspecified ); + ok( hr == S_OK, "got %08x\n", hr ); + + state = -1; + hr = _Recordset_get_State( recordset, &state ); + todo_wine ok( hr == S_OK, "got %08x\n", hr ); + todo_wine ok( state == adStateOpen, "got %d\n", state ); + + hr = _Recordset_AddNew( recordset, missing, missing ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = _Recordset_Close( recordset ); + ok( hr == S_OK, "got %08x\n", hr ); + + Fields_Release( fields ); + _Recordset_Release( recordset ); } static void test_Fields(void)