create.c 4.4 KB
Newer Older
1 2 3
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
4
 * Copyright 2002-2004 Mike McCormack for CodeWeavers
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
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 46


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

typedef struct tagMSICREATEVIEW
{
    MSIVIEW          view;
    MSIDATABASE     *db;
    LPWSTR           name;
    BOOL             bIsTemp;
47
    column_info     *col_info;
48 49 50 51 52 53 54 55 56 57 58
} MSICREATEVIEW;

static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

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

    return ERROR_FUNCTION_FAILED;
}

59
static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
60 61
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
62
    MSITABLE *table;
63

64
    TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name), 
65 66
          cv->bIsTemp?"temporary":"permanent");

67
    return msi_create_table( cv->db, cv->name, cv->col_info, !cv->bIsTemp, &table);
68 69 70 71 72 73
}

static UINT CREATE_close( struct tagMSIVIEW *view )
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

74
    TRACE("%p\n", cv);
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    return ERROR_SUCCESS;
}

static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

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

    return ERROR_FUNCTION_FAILED;
}

static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
                UINT n, LPWSTR *name, UINT *type )
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

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

    return ERROR_FUNCTION_FAILED;
}

98
static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
99
                           MSIRECORD *rec, UINT row)
100 101 102
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

103
    TRACE("%p %d %p\n", cv, eModifyMode, rec );
104 105 106 107 108 109 110 111 112 113

    return ERROR_FUNCTION_FAILED;
}

static UINT CREATE_delete( struct tagMSIVIEW *view )
{
    MSICREATEVIEW *cv = (MSICREATEVIEW*)view;

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

114
    msiobj_release( &cv->db->hdr );
115
    msi_free( cv );
116 117 118 119

    return ERROR_SUCCESS;
}

120
static const MSIVIEWOPS create_ops =
121 122
{
    CREATE_fetch_int,
123 124
    NULL,
    NULL,
125
    NULL,
126
    NULL,
127
    NULL,
128 129 130 131 132
    CREATE_execute,
    CREATE_close,
    CREATE_get_dimensions,
    CREATE_get_column_info,
    CREATE_modify,
133 134 135
    CREATE_delete,
    NULL,
    NULL,
136
    NULL,
137
    NULL,
138
    NULL,
139
    NULL,
140 141
};

142 143 144 145 146 147 148 149 150 151 152 153 154
static UINT check_columns( column_info *col_info )
{
    column_info *c1, *c2;

    /* check for two columns with the same name */
    for( c1 = col_info; c1; c1 = c1->next )
        for( c2 = c1->next; c2; c2 = c2->next )
            if (!lstrcmpW(c1->column, c2->column))
                return ERROR_BAD_QUERY_SYNTAX;

    return ERROR_SUCCESS;
}

155
UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
156
                        column_info *col_info, BOOL hold )
157 158
{
    MSICREATEVIEW *cv = NULL;
159
    UINT r;
160 161
    const column_info *col;
    BOOL temp = TRUE;
162 163 164

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

165 166 167 168
    r = check_columns( col_info );
    if( r != ERROR_SUCCESS )
        return r;

169
    cv = msi_alloc_zero( sizeof *cv );
170 171
    if( !cv )
        return ERROR_FUNCTION_FAILED;
172

173 174 175 176 177 178 179
    for( col = col_info; col; col = col->next )
        if( !col->temporary )
        {
            temp = FALSE;
            break;
        }

180 181
    /* fill the structure */
    cv->view.ops = &create_ops;
182
    msiobj_addref( &db->hdr );
183
    cv->db = db;
184
    cv->name = table;
185 186 187 188 189 190
    cv->col_info = col_info;
    cv->bIsTemp = temp;
    *view = (MSIVIEW*) cv;

    return ERROR_SUCCESS;
}