mfmediaengine: Remove unnecessary import library.
[wine.git] / dlls / msi / update.c
blob4aa03443f0ca5cd49f230f70edd52775e1a9b678
1 /*
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
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 tagMSIUPDATEVIEW
43 MSIVIEW view;
44 MSIDATABASE *db;
45 MSIVIEW *wv;
46 column_info *vals;
47 } MSIUPDATEVIEW;
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;
64 MSIVIEW *wv;
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 */
71 if (record)
73 r = MSI_RecordGetFieldCount(record);
75 for (i = 0; col; col = col->next)
76 i++;
78 cols_count = i;
79 where_count = r - i;
81 if (where_count > 0)
83 where = MSI_CreateRecord(where_count);
85 if (where)
86 for (i = 1; i <= where_count; i++)
87 MSI_RecordCopyField(record, cols_count + i, where, i);
91 wv = uv->wv;
92 if( !wv )
94 r = ERROR_FUNCTION_FAILED;
95 goto done;
98 r = wv->ops->execute( wv, where );
99 TRACE("tv execute returned %x\n", r);
100 if( r )
101 goto done;
103 r = wv->ops->get_dimensions( wv, &row_count, &col_count );
104 if( r )
105 goto done;
107 values = msi_query_merge_record( col_count, uv->vals, record );
108 if (!values)
110 r = ERROR_FUNCTION_FAILED;
111 goto done;
114 for ( i=0; i<row_count; i++ )
116 r = msi_select_update( wv, values, i );
117 if (r != ERROR_SUCCESS)
118 break;
121 done:
122 if ( where ) msiobj_release( &where->hdr );
123 if ( values ) msiobj_release( &values->hdr );
125 return r;
129 static UINT UPDATE_close( struct tagMSIVIEW *view )
131 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
132 MSIVIEW *wv;
134 TRACE("%p\n", uv);
136 wv = uv->wv;
137 if( !wv )
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;
146 MSIVIEW *wv;
148 TRACE("%p %p %p\n", uv, rows, cols );
150 wv = uv->wv;
151 if( !wv )
152 return ERROR_FUNCTION_FAILED;
154 return wv->ops->get_dimensions( wv, rows, cols );
157 static UINT UPDATE_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
158 UINT *type, BOOL *temporary, LPCWSTR *table_name )
160 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
161 MSIVIEW *wv;
163 TRACE("%p %d %p %p %p %p\n", uv, n, name, type, temporary, table_name );
165 wv = uv->wv;
166 if( !wv )
167 return ERROR_FUNCTION_FAILED;
169 return wv->ops->get_column_info( wv, n, name, type, temporary, table_name );
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;
185 MSIVIEW *wv;
187 TRACE("%p\n", uv );
189 wv = uv->wv;
190 if( wv )
191 wv->ops->delete( wv );
192 msiobj_release( &uv->db->hdr );
193 msi_free( uv );
195 return ERROR_SUCCESS;
198 static const MSIVIEWOPS update_ops =
200 UPDATE_fetch_int,
201 NULL,
202 NULL,
203 NULL,
204 NULL,
205 NULL,
206 NULL,
207 NULL,
208 UPDATE_execute,
209 UPDATE_close,
210 UPDATE_get_dimensions,
211 UPDATE_get_column_info,
212 UPDATE_modify,
213 UPDATE_delete,
214 NULL,
215 NULL,
216 NULL,
217 NULL,
220 UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
221 column_info *columns, struct expr *expr )
223 MSIUPDATEVIEW *uv = NULL;
224 UINT r;
225 MSIVIEW *sv = NULL, *wv = NULL;
227 TRACE("%p\n", uv );
229 if (expr)
230 r = WHERE_CreateView( db, &wv, table, expr );
231 else
232 r = TABLE_CreateView( db, table, &wv );
234 if( r != ERROR_SUCCESS )
235 return r;
237 /* then select the columns we want */
238 r = SELECT_CreateView( db, &sv, wv, columns );
239 if( r != ERROR_SUCCESS )
241 wv->ops->delete( wv );
242 return r;
245 uv = msi_alloc_zero( sizeof *uv );
246 if( !uv )
248 wv->ops->delete( wv );
249 return ERROR_FUNCTION_FAILED;
252 /* fill the structure */
253 uv->view.ops = &update_ops;
254 msiobj_addref( &db->hdr );
255 uv->db = db;
256 uv->vals = columns;
257 uv->wv = sv;
258 *view = (MSIVIEW*) uv;
260 return ERROR_SUCCESS;