crypt32: Implement CryptFindLocalizedName.
[wine/hacks.git] / dlls / msi / update.c
blob23d7ab5f7359f1874de92f221550862259a5a06c
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 MSIVIEW *wv;
65 TRACE("%p %p\n", uv, record );
67 wv = uv->wv;
68 if( !wv )
69 return ERROR_FUNCTION_FAILED;
71 r = wv->ops->execute( wv, 0 );
72 TRACE("tv execute returned %x\n", r);
73 if( r )
74 return r;
76 r = wv->ops->get_dimensions( wv, &row_count, &col_count );
77 if( r )
78 return r;
80 values = msi_query_merge_record( col_count, uv->vals, record );
81 if (!values)
82 return ERROR_FUNCTION_FAILED;
84 for ( i=0; i<row_count; i++ )
86 r = wv->ops->set_row( wv, i, values, (1 << col_count) - 1 );
87 if (r != ERROR_SUCCESS)
88 break;
91 msiobj_release( &values->hdr );
93 return r;
97 static UINT UPDATE_close( struct tagMSIVIEW *view )
99 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
100 MSIVIEW *wv;
102 TRACE("%p\n", uv);
104 wv = uv->wv;
105 if( !wv )
106 return ERROR_FUNCTION_FAILED;
108 return wv->ops->close( wv );
111 static UINT UPDATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
113 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
114 MSIVIEW *wv;
116 TRACE("%p %p %p\n", uv, rows, cols );
118 wv = uv->wv;
119 if( !wv )
120 return ERROR_FUNCTION_FAILED;
122 return wv->ops->get_dimensions( wv, rows, cols );
125 static UINT UPDATE_get_column_info( struct tagMSIVIEW *view,
126 UINT n, LPWSTR *name, UINT *type )
128 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
129 MSIVIEW *wv;
131 TRACE("%p %d %p %p\n", uv, n, name, type );
133 wv = uv->wv;
134 if( !wv )
135 return ERROR_FUNCTION_FAILED;
137 return wv->ops->get_column_info( wv, n, name, type );
140 static UINT UPDATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
141 MSIRECORD *rec, UINT row )
143 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
145 TRACE("%p %d %p\n", uv, eModifyMode, rec );
147 return ERROR_FUNCTION_FAILED;
150 static UINT UPDATE_delete( struct tagMSIVIEW *view )
152 MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
153 MSIVIEW *wv;
155 TRACE("%p\n", uv );
157 wv = uv->wv;
158 if( wv )
159 wv->ops->delete( wv );
160 msiobj_release( &uv->db->hdr );
161 msi_free( uv );
163 return ERROR_SUCCESS;
166 static UINT UPDATE_find_matching_rows( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle )
168 TRACE("%p %d %d %p\n", view, col, val, *handle );
170 return ERROR_FUNCTION_FAILED;
174 static const MSIVIEWOPS update_ops =
176 UPDATE_fetch_int,
177 NULL,
178 NULL,
179 NULL,
180 NULL,
181 NULL,
182 UPDATE_execute,
183 UPDATE_close,
184 UPDATE_get_dimensions,
185 UPDATE_get_column_info,
186 UPDATE_modify,
187 UPDATE_delete,
188 UPDATE_find_matching_rows,
189 NULL,
190 NULL,
191 NULL,
192 NULL,
195 UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
196 column_info *columns, struct expr *expr )
198 MSIUPDATEVIEW *uv = NULL;
199 UINT r;
200 MSIVIEW *tv = NULL, *sv = NULL, *wv = NULL;
202 TRACE("%p\n", uv );
204 r = TABLE_CreateView( db, table, &tv );
205 if( r != ERROR_SUCCESS )
206 return r;
208 if (expr)
210 /* add conditions first */
211 r = WHERE_CreateView( db, &wv, tv, expr );
212 if( r != ERROR_SUCCESS )
214 tv->ops->delete( tv );
215 return r;
218 else
219 wv = tv;
221 /* then select the columns we want */
222 r = SELECT_CreateView( db, &sv, wv, columns );
223 if( r != ERROR_SUCCESS )
225 wv->ops->delete( wv );
226 return r;
229 uv = msi_alloc_zero( sizeof *uv );
230 if( !uv )
231 return ERROR_FUNCTION_FAILED;
233 /* fill the structure */
234 uv->view.ops = &update_ops;
235 msiobj_addref( &db->hdr );
236 uv->db = db;
237 uv->vals = columns;
238 uv->wv = sv;
239 *view = (MSIVIEW*) uv;
241 return ERROR_SUCCESS;