alter.c 4.34 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2006 Mike McCormack
 *
 * 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"
#include "winerror.h"
#include "wine/debug.h"
#include "msi.h"
#include "msiquery.h"
#include "objbase.h"
#include "objidl.h"
#include "msipriv.h"

#include "query.h"

WINE_DEFAULT_DEBUG_CHANNEL(msidb);

typedef struct tagMSIALTERVIEW
{
    MSIVIEW        view;
    MSIDATABASE   *db;
41
    MSIVIEW       *table;
42
    column_info   *colinfo;
43
    INT hold;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
} MSIALTERVIEW;

static UINT ALTER_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

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

    return ERROR_FUNCTION_FAILED;
}

static UINT ALTER_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

    TRACE("%p %d %d %p\n", av, row, col, stm );

    return ERROR_FUNCTION_FAILED;
}

static UINT ALTER_execute( struct tagMSIVIEW *view, MSIRECORD *record )
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;
67
    UINT ref;
68

69 70
    TRACE("%p %p\n", av, record);

71
    if (av->colinfo)
72
        return av->table->ops->add_column(av->table, av->colinfo->column,
73
                av->colinfo->type, av->hold == 1);
74

75 76 77
    if (av->hold == 1)
        av->table->ops->add_ref(av->table);
    else if (av->hold == -1)
78 79 80 81 82
    {
        ref = av->table->ops->release(av->table);
        if (ref == 0)
            av->table = NULL;
    }
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    return ERROR_SUCCESS;
}

static UINT ALTER_close( struct tagMSIVIEW *view )
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

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

    return ERROR_SUCCESS;
}

static UINT ALTER_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

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

    return ERROR_FUNCTION_FAILED;
}

105 106
static UINT ALTER_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
                                   UINT *type, BOOL *temporary, LPCWSTR *table_name )
107 108 109
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

110
    TRACE("%p %d %p %p %p %p\n", av, n, name, type, temporary, table_name );
111 112 113 114 115

    return ERROR_FUNCTION_FAILED;
}

static UINT ALTER_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
116
                          MSIRECORD *rec, UINT row )
117 118 119 120 121 122 123 124 125 126 127 128 129
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

    TRACE("%p %d %p\n", av, eModifyMode, rec );

    return ERROR_FUNCTION_FAILED;
}

static UINT ALTER_delete( struct tagMSIVIEW *view )
{
    MSIALTERVIEW *av = (MSIALTERVIEW*)view;

    TRACE("%p\n", av );
130 131
    if (av->table)
        av->table->ops->delete( av->table );
132
    msi_free( av );
133 134 135 136 137 138 139 140

    return ERROR_SUCCESS;
}

static const MSIVIEWOPS alter_ops =
{
    ALTER_fetch_int,
    ALTER_fetch_stream,
141 142
    NULL,
    NULL,
143
    NULL,
144 145
    NULL,
    NULL,
146
    NULL,
147 148 149 150 151 152
    ALTER_execute,
    ALTER_close,
    ALTER_get_dimensions,
    ALTER_get_column_info,
    ALTER_modify,
    ALTER_delete,
153 154
    NULL,
    NULL,
155
    NULL,
156
    NULL,
157
    NULL,
158 159
};

160
UINT ALTER_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR name, column_info *colinfo, int hold )
161
{
Mike McCormack's avatar
Mike McCormack committed
162
    MSIALTERVIEW *av;
163
    UINT r;
164

165
    TRACE("%p %p %s %d\n", view, colinfo, debugstr_w(name), hold );
166 167 168 169 170

    av = msi_alloc_zero( sizeof *av );
    if( !av )
        return ERROR_FUNCTION_FAILED;

171
    r = TABLE_CreateView( db, name, &av->table );
172 173 174
    if (r != ERROR_SUCCESS)
    {
        msi_free( av );
175
        return r;
176
    }
177

178 179 180
    if (colinfo)
        colinfo->table = name;

181 182 183
    /* fill the structure */
    av->view.ops = &alter_ops;
    av->db = db;
184
    av->hold = hold;
185
    av->colinfo = colinfo;
186 187 188 189 190

    *view = &av->view;

    return ERROR_SUCCESS;
}