msi: Add tests for MsiGetUserInfo.
[wine] / dlls / msi / create.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002-2004 Mike McCormack for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "wine/debug.h"
27 #include "msi.h"
28 #include "msiquery.h"
29 #include "objbase.h"
30 #include "objidl.h"
31 #include "msipriv.h"
32 #include "winnls.h"
33
34 #include "query.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
37
38
39 /* below is the query interface to a table */
40
41 typedef struct tagMSICREATEVIEW
42 {
43     MSIVIEW          view;
44     MSIDATABASE     *db;
45     LPWSTR           name;
46     BOOL             bIsTemp;
47     column_info     *col_info;
48 } MSICREATEVIEW;
49
50 static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
51 {
52     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
53
54     TRACE("%p %d %d %p\n", cv, row, col, val );
55
56     return ERROR_FUNCTION_FAILED;
57 }
58
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           cv->bIsTemp?"temporary":"permanent");
66
67     return msi_create_table( cv->db, cv->name, cv->col_info, !cv->bIsTemp, &table);
68 }
69
70 static UINT CREATE_close( struct tagMSIVIEW *view )
71 {
72     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
73
74     TRACE("%p\n", cv);
75
76     return ERROR_SUCCESS;
77 }
78
79 static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
80 {
81     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
82
83     TRACE("%p %p %p\n", cv, rows, cols );
84
85     return ERROR_FUNCTION_FAILED;
86 }
87
88 static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
89                 UINT n, LPWSTR *name, UINT *type )
90 {
91     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
92
93     TRACE("%p %d %p %p\n", cv, n, name, type );
94
95     return ERROR_FUNCTION_FAILED;
96 }
97
98 static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
99                            MSIRECORD *rec, UINT row)
100 {
101     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
102
103     TRACE("%p %d %p\n", cv, eModifyMode, rec );
104
105     return ERROR_FUNCTION_FAILED;
106 }
107
108 static UINT CREATE_delete( struct tagMSIVIEW *view )
109 {
110     MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
111
112     TRACE("%p\n", cv );
113
114     msiobj_release( &cv->db->hdr );
115     msi_free( cv );
116
117     return ERROR_SUCCESS;
118 }
119
120 static const MSIVIEWOPS create_ops =
121 {
122     CREATE_fetch_int,
123     NULL,
124     NULL,
125     NULL,
126     NULL,
127     NULL,
128     CREATE_execute,
129     CREATE_close,
130     CREATE_get_dimensions,
131     CREATE_get_column_info,
132     CREATE_modify,
133     CREATE_delete,
134     NULL,
135     NULL,
136     NULL,
137     NULL,
138     NULL,
139     NULL,
140 };
141
142 static UINT check_columns( column_info *col_info )
143 {
144     column_info *c1, *c2;
145
146     /* check for two columns with the same name */
147     for( c1 = col_info; c1; c1 = c1->next )
148         for( c2 = c1->next; c2; c2 = c2->next )
149             if (!lstrcmpW(c1->column, c2->column))
150                 return ERROR_BAD_QUERY_SYNTAX;
151
152     return ERROR_SUCCESS;
153 }
154
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     const column_info *col;
161     BOOL temp = TRUE;
162
163     TRACE("%p\n", cv );
164
165     r = check_columns( col_info );
166     if( r != ERROR_SUCCESS )
167         return r;
168
169     cv = msi_alloc_zero( sizeof *cv );
170     if( !cv )
171         return ERROR_FUNCTION_FAILED;
172
173     for( col = col_info; col; col = col->next )
174         if( !col->temporary )
175         {
176             temp = FALSE;
177             break;
178         }
179
180     /* fill the structure */
181     cv->view.ops = &create_ops;
182     msiobj_addref( &db->hdr );
183     cv->db = db;
184     cv->name = table;
185     cv->col_info = col_info;
186     cv->bIsTemp = temp;
187     *view = (MSIVIEW*) cv;
188
189     return ERROR_SUCCESS;
190 }