2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 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 tagMSIUPDATEVIEW
49 static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
51 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
53 TRACE("%p %d %d %p\n", uv, row, col, val );
55 return ERROR_FUNCTION_FAILED;
58 static UINT UPDATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
60 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
61 UINT i, r, col_count = 0, row_count = 0;
62 MSIRECORD *values = NULL;
63 MSIRECORD *where = NULL;
65 UINT cols_count, where_count;
66 column_info *col = uv->vals;
68 TRACE("%p %p\n", uv, record );
70 /* extract the where markers from the record */
73 r = MSI_RecordGetFieldCount(record);
75 for (i = 0; col; col = col->next)
83 where = MSI_CreateRecord(where_count);
86 for (i = 1; i <= where_count; i++)
87 MSI_RecordCopyField(record, cols_count + i, where, i);
94 r = ERROR_FUNCTION_FAILED;
98 r = wv->ops->execute( wv, where );
99 TRACE("tv execute returned %x\n", r);
103 r = wv->ops->get_dimensions( wv, &row_count, &col_count );
107 values = msi_query_merge_record( col_count, uv->vals, record );
110 r = ERROR_FUNCTION_FAILED;
114 for ( i=0; i<row_count; i++ )
116 r = wv->ops->set_row( wv, i, values, (1 << col_count) - 1 );
117 if (r != ERROR_SUCCESS)
122 if ( where ) msiobj_release( &where->hdr );
123 if ( values ) msiobj_release( &values->hdr );
129 static UINT UPDATE_close( struct tagMSIVIEW *view )
131 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
138 return ERROR_FUNCTION_FAILED;
140 return wv->ops->close( wv );
143 static UINT UPDATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
145 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
148 TRACE("%p %p %p\n", uv, rows, cols );
152 return ERROR_FUNCTION_FAILED;
154 return wv->ops->get_dimensions( wv, rows, cols );
157 static UINT UPDATE_get_column_info( struct tagMSIVIEW *view,
158 UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
160 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
163 TRACE("%p %d %p %p %p\n", uv, n, name, type, temporary );
167 return ERROR_FUNCTION_FAILED;
169 return wv->ops->get_column_info( wv, n, name, type, temporary );
172 static UINT UPDATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
173 MSIRECORD *rec, UINT row )
175 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
177 TRACE("%p %d %p\n", uv, eModifyMode, rec );
179 return ERROR_FUNCTION_FAILED;
182 static UINT UPDATE_delete( struct tagMSIVIEW *view )
184 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
191 wv->ops->delete( wv );
192 msiobj_release( &uv->db->hdr );
195 return ERROR_SUCCESS;
198 static UINT UPDATE_find_matching_rows( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle )
200 TRACE("%p %d %d %p\n", view, col, val, *handle );
202 return ERROR_FUNCTION_FAILED;
206 static const MSIVIEWOPS update_ops =
216 UPDATE_get_dimensions,
217 UPDATE_get_column_info,
220 UPDATE_find_matching_rows,
228 UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
229 column_info *columns, struct expr *expr )
231 MSIUPDATEVIEW *uv = NULL;
233 MSIVIEW *tv = NULL, *sv = NULL, *wv = NULL;
237 r = TABLE_CreateView( db, table, &tv );
238 if( r != ERROR_SUCCESS )
243 /* add conditions first */
244 r = WHERE_CreateView( db, &wv, tv, expr );
245 if( r != ERROR_SUCCESS )
247 tv->ops->delete( tv );
254 /* then select the columns we want */
255 r = SELECT_CreateView( db, &sv, wv, columns );
256 if( r != ERROR_SUCCESS )
258 wv->ops->delete( wv );
262 uv = msi_alloc_zero( sizeof *uv );
265 wv->ops->delete( wv );
266 return ERROR_FUNCTION_FAILED;
269 /* fill the structure */
270 uv->view.ops = &update_ops;
271 msiobj_addref( &db->hdr );
275 *view = (MSIVIEW*) uv;
277 return ERROR_SUCCESS;