msxml: Allow the element implementation to be aggregatable.
[wine/multimedia.git] / dlls / msi / select.c
blobabb2dbdb33b5b707cd82e89b7a1729a868b6a2ef
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 Mike McCormack for CodeWeavers
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.
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.
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
21 #include <stdarg.h>
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"
34 #include "query.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
39 /* below is the query interface to a table */
41 typedef struct tagMSISELECTVIEW
43 MSIVIEW view;
44 MSIDATABASE *db;
45 MSIVIEW *table;
46 UINT num_cols;
47 UINT max_cols;
48 UINT cols[1];
49 } MSISELECTVIEW;
51 static UINT SELECT_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
53 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
55 TRACE("%p %d %d %p\n", sv, row, col, val );
57 if( !sv->table )
58 return ERROR_FUNCTION_FAILED;
60 if( (col==0) || (col>sv->num_cols) )
61 return ERROR_FUNCTION_FAILED;
63 col = sv->cols[ col - 1 ];
65 return sv->table->ops->fetch_int( sv->table, row, col, val );
68 static UINT SELECT_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
70 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
72 TRACE("%p %d %d %p\n", sv, row, col, stm );
74 if( !sv->table )
75 return ERROR_FUNCTION_FAILED;
77 if( (col==0) || (col>sv->num_cols) )
78 return ERROR_FUNCTION_FAILED;
80 col = sv->cols[ col - 1 ];
82 return sv->table->ops->fetch_stream( sv->table, row, col, stm );
85 static UINT SELECT_set_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT val )
87 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
89 TRACE("%p %d %d %04x\n", sv, row, col, val );
91 if( !sv->table )
92 return ERROR_FUNCTION_FAILED;
94 if( (col==0) || (col>sv->num_cols) )
95 return ERROR_FUNCTION_FAILED;
97 col = sv->cols[ col - 1 ];
99 return sv->table->ops->set_int( sv->table, row, col, val );
102 static UINT SELECT_insert_row( struct tagMSIVIEW *view, MSIRECORD *record )
104 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
106 TRACE("%p %p\n", sv, record );
108 if( !sv->table )
109 return ERROR_FUNCTION_FAILED;
111 return sv->table->ops->insert_row( sv->table, record );
114 static UINT SELECT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
116 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
118 TRACE("%p %p\n", sv, record);
120 if( !sv->table )
121 return ERROR_FUNCTION_FAILED;
123 return sv->table->ops->execute( sv->table, record );
126 static UINT SELECT_close( struct tagMSIVIEW *view )
128 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
130 TRACE("%p\n", sv );
132 if( !sv->table )
133 return ERROR_FUNCTION_FAILED;
135 return sv->table->ops->close( sv->table );
138 static UINT SELECT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
140 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
142 TRACE("%p %p %p\n", sv, rows, cols );
144 if( !sv->table )
145 return ERROR_FUNCTION_FAILED;
147 if( cols )
148 *cols = sv->num_cols;
150 return sv->table->ops->get_dimensions( sv->table, rows, NULL );
153 static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
154 UINT n, LPWSTR *name, UINT *type )
156 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
158 TRACE("%p %d %p %p\n", sv, n, name, type );
160 if( !sv->table )
161 return ERROR_FUNCTION_FAILED;
163 if( (n==0) || (n>sv->num_cols) )
164 return ERROR_FUNCTION_FAILED;
166 n = sv->cols[ n - 1 ];
168 return sv->table->ops->get_column_info( sv->table, n, name, type );
171 static UINT SELECT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
172 MSIRECORD *rec )
174 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
176 TRACE("%p %d %p\n", sv, eModifyMode, rec );
178 if( !sv->table )
179 return ERROR_FUNCTION_FAILED;
181 return sv->table->ops->modify( sv->table, eModifyMode, rec );
184 static UINT SELECT_delete( struct tagMSIVIEW *view )
186 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
188 TRACE("%p\n", sv );
190 if( sv->table )
191 sv->table->ops->delete( sv->table );
192 sv->table = NULL;
194 msi_free( sv );
196 return ERROR_SUCCESS;
199 static UINT SELECT_find_matching_rows( struct tagMSIVIEW *view, UINT col,
200 UINT val, UINT *row, MSIITERHANDLE *handle )
202 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
204 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
206 if( !sv->table )
207 return ERROR_FUNCTION_FAILED;
209 if( (col==0) || (col>sv->num_cols) )
210 return ERROR_FUNCTION_FAILED;
212 col = sv->cols[ col - 1 ];
214 return sv->table->ops->find_matching_rows( sv->table, col, val, row, handle );
218 static const MSIVIEWOPS select_ops =
220 SELECT_fetch_int,
221 SELECT_fetch_stream,
222 SELECT_set_int,
223 SELECT_insert_row,
224 SELECT_execute,
225 SELECT_close,
226 SELECT_get_dimensions,
227 SELECT_get_column_info,
228 SELECT_modify,
229 SELECT_delete,
230 SELECT_find_matching_rows
233 static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
235 UINT r, n=0;
236 MSIVIEW *table;
238 TRACE("%p adding %s\n", sv, debugstr_w( name ) );
240 if( sv->view.ops != &select_ops )
241 return ERROR_FUNCTION_FAILED;
243 table = sv->table;
244 if( !table )
245 return ERROR_FUNCTION_FAILED;
246 if( !table->ops->get_dimensions )
247 return ERROR_FUNCTION_FAILED;
248 if( !table->ops->get_column_info )
249 return ERROR_FUNCTION_FAILED;
251 if( sv->num_cols >= sv->max_cols )
252 return ERROR_FUNCTION_FAILED;
254 r = VIEW_find_column( table, name, &n );
255 if( r != ERROR_SUCCESS )
256 return r;
258 sv->cols[sv->num_cols] = n;
259 TRACE("Translating column %s from %d -> %d\n",
260 debugstr_w( name ), sv->num_cols, n);
262 sv->num_cols++;
264 return ERROR_SUCCESS;
267 int select_count_columns( column_info *col )
269 int n;
270 for (n = 0; col; col = col->next)
271 n++;
272 return n;
275 UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
276 column_info *columns )
278 MSISELECTVIEW *sv = NULL;
279 UINT count = 0, r = ERROR_SUCCESS;
281 TRACE("%p\n", sv );
283 count = select_count_columns( columns );
285 sv = msi_alloc_zero( sizeof *sv + count*sizeof (UINT) );
286 if( !sv )
287 return ERROR_FUNCTION_FAILED;
289 /* fill the structure */
290 sv->view.ops = &select_ops;
291 sv->db = db;
292 sv->table = table;
293 sv->num_cols = 0;
294 sv->max_cols = count;
296 while( columns )
298 r = SELECT_AddColumn( sv, columns->column );
299 if( r )
300 break;
301 columns = columns->next;
304 if( r == ERROR_SUCCESS )
305 *view = &sv->view;
306 else
307 msi_free( sv );
309 return r;