f48549e249a266768a4e82e8ef932592a9d8647e
[reactos.git] / reactos / dll / win32 / 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 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include <stdarg.h>
26
27 //#include "windef.h"
28 //#include "winbase.h"
29 //#include "winerror.h"
30 #include <wine/debug.h>
31 #include <wine/unicode.h>
32 //#include "msi.h"
33 //#include "msiquery.h"
34 //#include "objbase.h"
35 //#include "objidl.h"
36 //#include "msipriv.h"
37 //#include "winnls.h"
38
39 #include "query.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
42
43
44 /* below is the query interface to a table */
45
46 typedef struct tagMSICREATEVIEW
47 {
48 MSIVIEW view;
49 MSIDATABASE *db;
50 LPCWSTR name;
51 BOOL bIsTemp;
52 BOOL hold;
53 column_info *col_info;
54 } MSICREATEVIEW;
55
56 static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
57 {
58 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
59
60 TRACE("%p %d %d %p\n", cv, row, col, val );
61
62 return ERROR_FUNCTION_FAILED;
63 }
64
65 static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
66 {
67 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
68 BOOL persist = (cv->bIsTemp) ? MSICONDITION_FALSE : MSICONDITION_TRUE;
69
70 TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
71 cv->bIsTemp?"temporary":"permanent");
72
73 if (cv->bIsTemp && !cv->hold)
74 return ERROR_SUCCESS;
75
76 return msi_create_table( cv->db, cv->name, cv->col_info, persist );
77 }
78
79 static UINT CREATE_close( struct tagMSIVIEW *view )
80 {
81 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
82
83 TRACE("%p\n", cv);
84
85 return ERROR_SUCCESS;
86 }
87
88 static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
89 {
90 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
91
92 TRACE("%p %p %p\n", cv, rows, cols );
93
94 return ERROR_FUNCTION_FAILED;
95 }
96
97 static UINT CREATE_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
98 UINT *type, BOOL *temporary, LPCWSTR *table_name )
99 {
100 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
101
102 TRACE("%p %d %p %p %p %p\n", cv, n, name, type, temporary, table_name );
103
104 return ERROR_FUNCTION_FAILED;
105 }
106
107 static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
108 MSIRECORD *rec, UINT row)
109 {
110 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
111
112 TRACE("%p %d %p\n", cv, eModifyMode, rec );
113
114 return ERROR_FUNCTION_FAILED;
115 }
116
117 static UINT CREATE_delete( struct tagMSIVIEW *view )
118 {
119 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
120
121 TRACE("%p\n", cv );
122
123 msiobj_release( &cv->db->hdr );
124 msi_free( cv );
125
126 return ERROR_SUCCESS;
127 }
128
129 static const MSIVIEWOPS create_ops =
130 {
131 CREATE_fetch_int,
132 NULL,
133 NULL,
134 NULL,
135 NULL,
136 NULL,
137 CREATE_execute,
138 CREATE_close,
139 CREATE_get_dimensions,
140 CREATE_get_column_info,
141 CREATE_modify,
142 CREATE_delete,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
147 NULL,
148 NULL,
149 NULL,
150 };
151
152 static UINT check_columns( const column_info *col_info )
153 {
154 const column_info *c1, *c2;
155
156 /* check for two columns with the same name */
157 for( c1 = col_info; c1; c1 = c1->next )
158 for( c2 = c1->next; c2; c2 = c2->next )
159 if (!strcmpW( c1->column, c2->column ))
160 return ERROR_BAD_QUERY_SYNTAX;
161
162 return ERROR_SUCCESS;
163 }
164
165 UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
166 column_info *col_info, BOOL hold )
167 {
168 MSICREATEVIEW *cv = NULL;
169 UINT r;
170 column_info *col;
171 BOOL temp = TRUE;
172 BOOL tempprim = FALSE;
173
174 TRACE("%p\n", cv );
175
176 r = check_columns( col_info );
177 if( r != ERROR_SUCCESS )
178 return r;
179
180 cv = msi_alloc_zero( sizeof *cv );
181 if( !cv )
182 return ERROR_FUNCTION_FAILED;
183
184 for( col = col_info; col; col = col->next )
185 {
186 if (!col->table)
187 col->table = table;
188
189 if( !col->temporary )
190 temp = FALSE;
191 else if ( col->type & MSITYPE_KEY )
192 tempprim = TRUE;
193 }
194
195 if ( !temp && tempprim )
196 {
197 msi_free( cv );
198 return ERROR_FUNCTION_FAILED;
199 }
200
201 /* fill the structure */
202 cv->view.ops = &create_ops;
203 msiobj_addref( &db->hdr );
204 cv->db = db;
205 cv->name = table;
206 cv->col_info = col_info;
207 cv->bIsTemp = temp;
208 cv->hold = hold;
209 *view = (MSIVIEW*) cv;
210
211 return ERROR_SUCCESS;
212 }