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_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 );
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;
105 UINT i, table_cols, r;
108 TRACE("%p %p\n", sv, record );
111 return ERROR_FUNCTION_FAILED;
113 /* rearrange the record to suit the table */
114 r = sv->table->ops->get_dimensions( sv->table, NULL, &table_cols );
115 if (r != ERROR_SUCCESS)
118 outrec = MSI_CreateRecord( table_cols + 1 );
120 for (i=0; i<sv->num_cols; i++)
122 r = MSI_RecordCopyField( record, i+1, outrec, sv->cols[i] );
123 if (r != ERROR_SUCCESS)
127 r = sv->table->ops->insert_row( sv->table, outrec );
130 msiobj_release( &outrec->hdr );
135 static UINT SELECT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
137 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
139 TRACE("%p %p\n", sv, record);
142 return ERROR_FUNCTION_FAILED;
144 return sv->table->ops->execute( sv->table, record );
147 static UINT SELECT_close( struct tagMSIVIEW *view )
149 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
154 return ERROR_FUNCTION_FAILED;
156 return sv->table->ops->close( sv->table );
159 static UINT SELECT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
161 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
163 TRACE("%p %p %p\n", sv, rows, cols );
166 return ERROR_FUNCTION_FAILED;
169 *cols = sv->num_cols;
171 return sv->table->ops->get_dimensions( sv->table, rows, NULL );
174 static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
175 UINT n, LPWSTR *name, UINT *type )
177 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
179 TRACE("%p %d %p %p\n", sv, n, name, type );
182 return ERROR_FUNCTION_FAILED;
184 if( (n==0) || (n>sv->num_cols) )
185 return ERROR_FUNCTION_FAILED;
187 n = sv->cols[ n - 1 ];
189 return sv->table->ops->get_column_info( sv->table, n, name, type );
192 static UINT SELECT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
195 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
197 TRACE("%p %d %p\n", sv, eModifyMode, rec );
200 return ERROR_FUNCTION_FAILED;
202 return sv->table->ops->modify( sv->table, eModifyMode, rec );
205 static UINT SELECT_delete( struct tagMSIVIEW *view )
207 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
212 sv->table->ops->delete( sv->table );
217 return ERROR_SUCCESS;
220 static UINT SELECT_find_matching_rows( struct tagMSIVIEW *view, UINT col,
221 UINT val, UINT *row, MSIITERHANDLE *handle )
223 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
225 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
228 return ERROR_FUNCTION_FAILED;
230 if( (col==0) || (col>sv->num_cols) )
231 return ERROR_FUNCTION_FAILED;
233 col = sv->cols[ col - 1 ];
235 return sv->table->ops->find_matching_rows( sv->table, col, val, row, handle );
239 static const MSIVIEWOPS select_ops =
247 SELECT_get_dimensions,
248 SELECT_get_column_info,
251 SELECT_find_matching_rows
254 static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
259 TRACE("%p adding %s\n", sv, debugstr_w( name ) );
261 if( sv->view.ops != &select_ops )
262 return ERROR_FUNCTION_FAILED;
266 return ERROR_FUNCTION_FAILED;
267 if( !table->ops->get_dimensions )
268 return ERROR_FUNCTION_FAILED;
269 if( !table->ops->get_column_info )
270 return ERROR_FUNCTION_FAILED;
272 if( sv->num_cols >= sv->max_cols )
273 return ERROR_FUNCTION_FAILED;
275 r = VIEW_find_column( table, name, &n );
276 if( r != ERROR_SUCCESS )
279 sv->cols[sv->num_cols] = n;
280 TRACE("Translating column %s from %d -> %d\n",
281 debugstr_w( name ), sv->num_cols, n);
285 return ERROR_SUCCESS;
288 static int select_count_columns( column_info *col )
291 for (n = 0; col; col = col->next)
296 UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
297 column_info *columns )
299 MSISELECTVIEW *sv = NULL;
300 UINT count = 0, r = ERROR_SUCCESS;
304 count = select_count_columns( columns );
306 sv = msi_alloc_zero( sizeof *sv + count*sizeof (UINT) );
308 return ERROR_FUNCTION_FAILED;
310 /* fill the structure */
311 sv->view.ops = &select_ops;
315 sv->max_cols = count;
319 r = SELECT_AddColumn( sv, columns->column );
322 columns = columns->next;
325 if( r == ERROR_SUCCESS )