command.c 10.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright 2019 Alistair Leslie-Hughes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#define COBJMACROS
#include "objbase.h"
23
#include "msdasc.h"
24 25 26 27 28 29 30 31 32 33 34
#include "msado15_backcompat.h"

#include "wine/debug.h"
#include "wine/heap.h"

#include "msado15_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(msado15);

struct command
{
35 36 37 38
    _Command         Command_iface;
    LONG             ref;
    CommandTypeEnum  type;
    BSTR             text;
39
    _Connection     *connection;
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
};

static inline struct command *impl_from_Command( _Command *iface )
{
    return CONTAINING_RECORD( iface, struct command, Command_iface );
}

static HRESULT WINAPI command_QueryInterface( _Command *iface, REFIID riid, void **obj )
{
    TRACE( "%p, %s, %p\n", iface, debugstr_guid(riid), obj );

    *obj = NULL;

    if (IsEqualIID(riid, &IID_IUnknown)   ||
        IsEqualIID(riid, &IID_IDispatch)  ||
        IsEqualIID(riid, &IID__ADO)       ||
        IsEqualIID(riid, &IID_Command15)  ||
        IsEqualIID(riid, &IID_Command25)  ||
        IsEqualIID(riid, &IID__Command))
    {
        *obj = iface;
    }
    else
    {
        FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
        return E_NOINTERFACE;
    }

    _Command_AddRef( iface );
    return S_OK;
}

static ULONG WINAPI command_AddRef( _Command *iface )
{
    struct command *command = impl_from_Command( iface );
    return InterlockedIncrement( &command->ref );
}

static ULONG WINAPI command_Release( _Command *iface )
{
    struct command *command = impl_from_Command( iface );
    LONG ref = InterlockedDecrement( &command->ref );
    if (!ref)
    {
        TRACE( "destroying %p\n", command );
85
        if (command->connection) _Connection_Release(command->connection);
86
        heap_free( command->text );
87 88 89 90 91 92 93
        heap_free( command );
    }
    return ref;
}

static HRESULT WINAPI command_GetTypeInfoCount( _Command *iface, UINT *count )
{
94 95 96 97
    struct command *command = impl_from_Command( iface );
    TRACE( "%p, %p\n", command, count );
    *count = 1;
    return S_OK;
98 99 100 101
}

static HRESULT WINAPI command_GetTypeInfo( _Command *iface, UINT index, LCID lcid, ITypeInfo **info )
{
102
    struct command *command = impl_from_Command( iface );
103
    TRACE( "%p, %u, %lu, %p\n", command, index, lcid, info );
104
    return get_typeinfo(Command_tid, info);
105 106 107 108 109
}

static HRESULT WINAPI command_GetIDsOfNames( _Command *iface, REFIID riid, LPOLESTR *names, UINT count,
                                             LCID lcid, DISPID *dispid )
{
110 111 112 113
    struct command *command = impl_from_Command( iface );
    HRESULT hr;
    ITypeInfo *typeinfo;

114
    TRACE( "%p, %s, %p, %u, %lu, %p\n", command, debugstr_guid(riid), names, count, lcid, dispid );
115 116 117 118 119 120 121 122 123

    hr = get_typeinfo(Command_tid, &typeinfo);
    if(SUCCEEDED(hr))
    {
        hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, dispid);
        ITypeInfo_Release(typeinfo);
    }

    return hr;
124 125 126 127 128
}

static HRESULT WINAPI command_Invoke( _Command *iface, DISPID member, REFIID riid, LCID lcid, WORD flags,
                                      DISPPARAMS *params, VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
{
129 130 131 132
    struct command *command = impl_from_Command( iface );
    HRESULT hr;
    ITypeInfo *typeinfo;

133
    TRACE( "%p, %ld, %s, %ld, %d, %p, %p, %p, %p\n", command, member, debugstr_guid(riid), lcid, flags, params,
134
           result, excep_info, arg_err );
135

136
    hr = get_typeinfo(Command_tid, &typeinfo);
137 138 139 140 141 142 143 144
    if(SUCCEEDED(hr))
    {
        hr = ITypeInfo_Invoke(typeinfo, &command->Command_iface, member, flags, params,
                               result, excep_info, arg_err);
        ITypeInfo_Release(typeinfo);
    }

    return hr;
145 146 147 148 149 150 151 152 153 154
}

static HRESULT WINAPI command_get_Properties( _Command *iface, Properties **props )
{
    FIXME( "%p, %p\n", iface, props );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_ActiveConnection( _Command *iface, _Connection **connection )
{
155 156 157 158 159 160
    struct command *command = impl_from_Command( iface );
    TRACE( "%p, %p\n", iface, connection );

    *connection = command->connection;
    if (command->connection) _Connection_AddRef(command->connection);
    return S_OK;
161 162 163 164
}

static HRESULT WINAPI command_putref_ActiveConnection( _Command *iface, _Connection *connection )
{
165 166 167 168 169 170 171
    struct command *command = impl_from_Command( iface );
    TRACE( "%p, %p\n", iface, connection );

    if (command->connection) _Connection_Release(command->connection);
    command->connection = connection;
    if (command->connection) _Connection_AddRef(command->connection);
    return S_OK;
172 173 174 175 176 177 178 179 180 181
}

static HRESULT WINAPI command_put_ActiveConnection( _Command *iface, VARIANT connection )
{
    FIXME( "%p, %s\n", iface, debugstr_variant(&connection) );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_CommandText( _Command *iface, BSTR *text )
{
182 183 184 185 186 187 188 189
    struct command *command = impl_from_Command( iface );
    BSTR cmd_text = NULL;

    TRACE( "%p, %p\n", command, text );

    if (command->text && !(cmd_text = SysAllocString( command->text ))) return E_OUTOFMEMORY;
    *text = cmd_text;
    return S_OK;
190 191 192 193
}

static HRESULT WINAPI command_put_CommandText( _Command *iface, BSTR text )
{
194 195 196 197 198 199 200 201 202
    struct command *command = impl_from_Command( iface );
    WCHAR *source = NULL;

    TRACE( "%p, %s\n", command, debugstr_w( text ) );

    if (text && !(source = strdupW( text ))) return E_OUTOFMEMORY;
    heap_free( command->text );
    command->text = source;
    return S_OK;
203 204 205 206 207 208 209 210 211 212
}

static HRESULT WINAPI command_get_CommandTimeout( _Command *iface, LONG *timeout )
{
    FIXME( "%p, %p\n", iface, timeout );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_CommandTimeout( _Command *iface, LONG timeout )
{
213
    FIXME( "%p, %ld\n", iface, timeout );
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_Prepared( _Command *iface, VARIANT_BOOL *prepared )
{
    FIXME( "%p, %p\n", iface, prepared );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_Prepared( _Command *iface, VARIANT_BOOL prepared )
{
    FIXME( "%p, %d\n", iface, prepared );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_Execute( _Command *iface, VARIANT *affected, VARIANT *parameters,
                                       LONG options, _Recordset **recordset )
{
232
    FIXME( "%p, %p, %p, %ld, %p\n", iface, affected, parameters, options, recordset );
233 234 235 236
    return E_NOTIMPL;
}

static HRESULT WINAPI command_CreateParameter( _Command *iface, BSTR name, DataTypeEnum type,
237
                                               ParameterDirectionEnum direction, ADO_LONGPTR size, VARIANT value,
238 239
                                               _Parameter **parameter )
{
240
    FIXME( "%p, %s, %d, %d, %Id, %p\n", iface, debugstr_w(name), type, direction, size, parameter );
241 242 243 244 245 246 247 248 249 250 251
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_Parameters( _Command *iface, Parameters **parameters )
{
    FIXME( "%p, %p\n", iface, parameters );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_CommandType( _Command *iface, CommandTypeEnum type )
{
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    struct command *command = impl_from_Command( iface );

    TRACE( "%p, %d\n", iface, type );

    switch (type)
    {
    case adCmdUnspecified:
    case adCmdUnknown:
    case adCmdText:
    case adCmdTable:
    case adCmdStoredProc:
    case adCmdFile:
    case adCmdTableDirect:
        command->type = type;
        return S_OK;
    }

    return MAKE_ADO_HRESULT( adErrInvalidArgument );
270 271 272 273
}

static HRESULT WINAPI command_get_CommandType( _Command *iface, CommandTypeEnum *type )
{
274 275 276 277 278 279
    struct command *command = impl_from_Command( iface );

    TRACE( "%p, %p\n", iface, type );

    *type = command->type;
    return S_OK;
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
}

static HRESULT WINAPI command_get_Name(_Command *iface, BSTR *name)
{
    FIXME( "%p, %p\n", iface, name );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_Name( _Command *iface, BSTR name )
{
    FIXME( "%p, %s\n", iface, debugstr_w(name) );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_State( _Command *iface, LONG *state )
{
    FIXME( "%p, %p\n", iface, state );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_Cancel( _Command *iface )
{
    FIXME( "%p\n", iface );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_putref_CommandStream( _Command *iface, IUnknown *stream )
{
    FIXME( "%p, %p\n", iface, stream );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_CommandStream( _Command *iface, VARIANT *stream )
{
    FIXME( "%p, %p\n", iface, stream );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_Dialect( _Command *iface, BSTR dialect )
{
    FIXME( "%p, %s\n", iface, debugstr_w(dialect) );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_Dialect( _Command *iface, BSTR *dialect )
{
    FIXME( "%p, %p\n", iface, dialect );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_put_NamedParameters( _Command *iface, VARIANT_BOOL parameters )
{
    FIXME( "%p, %d\n", iface, parameters );
    return E_NOTIMPL;
}

static HRESULT WINAPI command_get_NamedParameters( _Command *iface, VARIANT_BOOL *parameters )
{
    FIXME( "%p, %p\n", iface, parameters );
    return E_NOTIMPL;
}

static const struct _CommandVtbl command_vtbl =
{
    command_QueryInterface,
    command_AddRef,
    command_Release,
    command_GetTypeInfoCount,
    command_GetTypeInfo,
    command_GetIDsOfNames,
    command_Invoke,
    command_get_Properties,
    command_get_ActiveConnection,
    command_putref_ActiveConnection,
    command_put_ActiveConnection,
    command_get_CommandText,
    command_put_CommandText,
    command_get_CommandTimeout,
    command_put_CommandTimeout,
    command_get_Prepared,
    command_put_Prepared,
    command_Execute,
    command_CreateParameter,
    command_get_Parameters,
    command_put_CommandType,
    command_get_CommandType,
    command_get_Name,
    command_put_Name,
    command_get_State,
    command_Cancel,
    command_putref_CommandStream,
    command_get_CommandStream,
    command_put_Dialect,
    command_get_Dialect,
    command_put_NamedParameters,
    command_get_NamedParameters
};

HRESULT Command_create( void **obj )
{
    struct command *command;

    if (!(command = heap_alloc( sizeof(*command) ))) return E_OUTOFMEMORY;
    command->Command_iface.lpVtbl = &command_vtbl;
384
    command->type = adCmdUnknown;
385
    command->text = NULL;
386
    command->connection = NULL;
387 388 389 390 391 392
    command->ref = 1;

    *obj = &command->Command_iface;
    TRACE( "returning iface %p\n", *obj );
    return S_OK;
}