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
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
39 /* below is the query interface to a table */
41 typedef struct tagMSISELECTVIEW
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 );
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 );
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_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
87 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
88 UINT i, expanded_mask = 0, r = ERROR_SUCCESS, col_count = 0;
91 TRACE("%p %d %p %08x\n", sv, row, rec, mask );
94 return ERROR_FUNCTION_FAILED;
96 /* test if any of the mask bits are invalid */
97 if ( mask >= (1<<sv->num_cols) )
98 return ERROR_INVALID_PARAMETER;
100 /* find the number of columns in the table below */
101 r = sv->table->ops->get_dimensions( sv->table, NULL, &col_count );
105 /* expand the record to the right size for the underlying table */
106 expanded = MSI_CreateRecord( col_count );
108 return ERROR_FUNCTION_FAILED;
110 /* move the right fields across */
111 for ( i=0; i<sv->num_cols; i++ )
113 r = MSI_RecordCopyField( rec, i+1, expanded, sv->cols[ i ] );
114 if (r != ERROR_SUCCESS)
116 expanded_mask |= (1<<(sv->cols[i]-1));
119 /* set the row in the underlying table */
120 if (r == ERROR_SUCCESS)
121 r = sv->table->ops->set_row( sv->table, row, expanded, expanded_mask );
123 msiobj_release( &expanded->hdr );
127 static UINT SELECT_insert_row( struct tagMSIVIEW *view, MSIRECORD *record )
129 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
130 UINT i, table_cols, r;
133 TRACE("%p %p\n", sv, record );
136 return ERROR_FUNCTION_FAILED;
138 /* rearrange the record to suit the table */
139 r = sv->table->ops->get_dimensions( sv->table, NULL, &table_cols );
140 if (r != ERROR_SUCCESS)
143 outrec = MSI_CreateRecord( table_cols + 1 );
145 for (i=0; i<sv->num_cols; i++)
147 r = MSI_RecordCopyField( record, i+1, outrec, sv->cols[i] );
148 if (r != ERROR_SUCCESS)
152 r = sv->table->ops->insert_row( sv->table, outrec );
155 msiobj_release( &outrec->hdr );
160 static UINT SELECT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
162 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
164 TRACE("%p %p\n", sv, record);
167 return ERROR_FUNCTION_FAILED;
169 return sv->table->ops->execute( sv->table, record );
172 static UINT SELECT_close( struct tagMSIVIEW *view )
174 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
179 return ERROR_FUNCTION_FAILED;
181 return sv->table->ops->close( sv->table );
184 static UINT SELECT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
186 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
188 TRACE("%p %p %p\n", sv, rows, cols );
191 return ERROR_FUNCTION_FAILED;
194 *cols = sv->num_cols;
196 return sv->table->ops->get_dimensions( sv->table, rows, NULL );
199 static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
200 UINT n, LPWSTR *name, UINT *type )
202 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
204 TRACE("%p %d %p %p\n", sv, n, name, type );
207 return ERROR_FUNCTION_FAILED;
209 if( (n==0) || (n>sv->num_cols) )
210 return ERROR_FUNCTION_FAILED;
212 n = sv->cols[ n - 1 ];
214 return sv->table->ops->get_column_info( sv->table, n, name, type );
217 static UINT SELECT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
220 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
222 TRACE("%p %d %p\n", sv, eModifyMode, rec );
225 return ERROR_FUNCTION_FAILED;
227 return sv->table->ops->modify( sv->table, eModifyMode, rec );
230 static UINT SELECT_delete( struct tagMSIVIEW *view )
232 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
237 sv->table->ops->delete( sv->table );
242 return ERROR_SUCCESS;
245 static UINT SELECT_find_matching_rows( struct tagMSIVIEW *view, UINT col,
246 UINT val, UINT *row, MSIITERHANDLE *handle )
248 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
250 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
253 return ERROR_FUNCTION_FAILED;
255 if( (col==0) || (col>sv->num_cols) )
256 return ERROR_FUNCTION_FAILED;
258 col = sv->cols[ col - 1 ];
260 return sv->table->ops->find_matching_rows( sv->table, col, val, row, handle );
264 static const MSIVIEWOPS select_ops =
272 SELECT_get_dimensions,
273 SELECT_get_column_info,
276 SELECT_find_matching_rows
279 static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
284 TRACE("%p adding %s\n", sv, debugstr_w( name ) );
286 if( sv->view.ops != &select_ops )
287 return ERROR_FUNCTION_FAILED;
291 return ERROR_FUNCTION_FAILED;
292 if( !table->ops->get_dimensions )
293 return ERROR_FUNCTION_FAILED;
294 if( !table->ops->get_column_info )
295 return ERROR_FUNCTION_FAILED;
297 if( sv->num_cols >= sv->max_cols )
298 return ERROR_FUNCTION_FAILED;
300 r = VIEW_find_column( table, name, &n );
301 if( r != ERROR_SUCCESS )
304 sv->cols[sv->num_cols] = n;
305 TRACE("Translating column %s from %d -> %d\n",
306 debugstr_w( name ), sv->num_cols, n);
310 return ERROR_SUCCESS;
313 static int select_count_columns( column_info *col )
316 for (n = 0; col; col = col->next)
321 UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
322 column_info *columns )
324 MSISELECTVIEW *sv = NULL;
325 UINT count = 0, r = ERROR_SUCCESS;
329 count = select_count_columns( columns );
331 sv = msi_alloc_zero( sizeof *sv + count*sizeof (UINT) );
333 return ERROR_FUNCTION_FAILED;
335 /* fill the structure */
336 sv->view.ops = &select_ops;
340 sv->max_cols = count;
344 r = SELECT_AddColumn( sv, columns->column );
347 columns = columns->next;
350 if( r == ERROR_SUCCESS )