update.c 5.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2004 Mike McCormack for CodeWeavers
 *
 * 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 receuved a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/debug.h"
#include "msi.h"
#include "msiquery.h"
#include "objbase.h"
#include "objidl.h"
#include "msipriv.h"
#include "winnls.h"

#include "query.h"

36
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
37 38 39 40 41 42 43 44 45


/* below is the query interface to a table */

typedef struct tagMSIUPDATEVIEW
{
    MSIVIEW          view;
    MSIDATABASE     *db;
    MSIVIEW         *wv;
46
    column_info     *vals;
47 48 49 50 51 52 53 54 55 56 57
} MSIUPDATEVIEW;

static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;

    TRACE("%p %d %d %p\n", uv, row, col, val );

    return ERROR_FUNCTION_FAILED;
}

58
static UINT UPDATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
59 60
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
61
    UINT i, r, col_count = 0, row_count = 0;
62
    MSIRECORD *values = NULL;
63 64
    MSIVIEW *wv;

65
    TRACE("%p %p\n", uv, record );
66 67 68 69 70 71 72 73 74 75 76 77

    wv = uv->wv;
    if( !wv )
        return ERROR_FUNCTION_FAILED;

    r = wv->ops->execute( wv, 0 );
    TRACE("tv execute returned %x\n", r);
    if( r )
        return r;

    r = wv->ops->get_dimensions( wv, &row_count, &col_count );
    if( r )
78
        return r;
79

80 81 82 83
    values = msi_query_merge_record( col_count, uv->vals, record );
    if (!values)
        return ERROR_FUNCTION_FAILED;

84
    for ( i=0; i<row_count; i++ )
85
    {
86 87 88
        r = wv->ops->set_row( wv, i, values, (1 << col_count) - 1 );
        if (r != ERROR_SUCCESS)
            break;
89 90
    }

91 92
    msiobj_release( &values->hdr );

93
    return r;
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
}


static UINT UPDATE_close( struct tagMSIVIEW *view )
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
    MSIVIEW *wv;

    TRACE("%p\n", uv);

    wv = uv->wv;
    if( !wv )
        return ERROR_FUNCTION_FAILED;

    return wv->ops->close( wv );
}

static UINT UPDATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
    MSIVIEW *wv;

    TRACE("%p %p %p\n", uv, rows, cols );

    wv = uv->wv;
    if( !wv )
        return ERROR_FUNCTION_FAILED;

    return wv->ops->get_dimensions( wv, rows, cols );
}

static UINT UPDATE_get_column_info( struct tagMSIVIEW *view,
                UINT n, LPWSTR *name, UINT *type )
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
    MSIVIEW *wv;

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

    wv = uv->wv;
    if( !wv )
        return ERROR_FUNCTION_FAILED;

    return wv->ops->get_column_info( wv, n, name, type );
}

140 141
static UINT UPDATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
                MSIRECORD *rec )
142 143 144
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;

145
    TRACE("%p %d %p\n", uv, eModifyMode, rec );
146 147 148 149 150 151 152 153 154 155 156 157 158 159

    return ERROR_FUNCTION_FAILED;
}

static UINT UPDATE_delete( struct tagMSIVIEW *view )
{
    MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
    MSIVIEW *wv;

    TRACE("%p\n", uv );

    wv = uv->wv;
    if( wv )
        wv->ops->delete( wv );
160
    msiobj_release( &uv->db->hdr );
161
    msi_free( uv );
162 163 164 165

    return ERROR_SUCCESS;
}

166 167 168 169 170 171 172
static UINT UPDATE_find_matching_rows( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle )
{
    TRACE("%p %d %d %p\n", view, col, val, *handle );

    return ERROR_FUNCTION_FAILED;
}

173

174
static const MSIVIEWOPS update_ops =
175 176 177 178
{
    UPDATE_fetch_int,
    NULL,
    NULL,
179
    NULL,
180 181 182 183 184
    UPDATE_execute,
    UPDATE_close,
    UPDATE_get_dimensions,
    UPDATE_get_column_info,
    UPDATE_modify,
185 186
    UPDATE_delete,
    UPDATE_find_matching_rows
187 188 189
};

UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
190
                        column_info *columns, struct expr *expr )
191 192 193 194 195 196 197 198 199 200 201
{
    MSIUPDATEVIEW *uv = NULL;
    UINT r;
    MSIVIEW *tv = NULL, *sv = NULL, *wv = NULL;

    TRACE("%p\n", uv );

    r = TABLE_CreateView( db, table, &tv );
    if( r != ERROR_SUCCESS )
        return r;

202
    if (expr)
203
    {
204 205 206 207 208 209 210
        /* add conditions first */
        r = WHERE_CreateView( db, &wv, tv, expr );
        if( r != ERROR_SUCCESS )
        {
            tv->ops->delete( tv );
            return r;
        }
211
    }
212 213 214
    else
       wv = tv;

215
    /* then select the columns we want */
216
    r = SELECT_CreateView( db, &sv, wv, columns );
217 218
    if( r != ERROR_SUCCESS )
    {
219
        wv->ops->delete( wv );
220 221 222
        return r;
    }

223
    uv = msi_alloc_zero( sizeof *uv );
224 225 226 227 228
    if( !uv )
        return ERROR_FUNCTION_FAILED;

    /* fill the structure */
    uv->view.ops = &update_ops;
229
    msiobj_addref( &db->hdr );
230
    uv->db = db;
231
    uv->vals = columns;
232 233 234 235 236
    uv->wv = sv;
    *view = (MSIVIEW*) uv;

    return ERROR_SUCCESS;
}