cryptnet: Add CertDllVerifyRevocation stub.
[wine/hacks.git] / dlls / msi / alter.c
blobe0a1b91ffe7fe13d2ebd8042c8d3f8f8db3baf1a
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2006 Mike McCormack
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"
33 #include "query.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
37 typedef struct tagMSIALTERVIEW
39 MSIVIEW view;
40 MSIDATABASE *db;
41 MSIVIEW *table;
42 column_info *colinfo;
43 INT hold;
44 } MSIALTERVIEW;
46 static UINT ALTER_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
48 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
50 TRACE("%p %d %d %p\n", av, row, col, val );
52 return ERROR_FUNCTION_FAILED;
55 static UINT ALTER_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
57 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
59 TRACE("%p %d %d %p\n", av, row, col, stm );
61 return ERROR_FUNCTION_FAILED;
64 static UINT ALTER_get_row( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec )
66 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
68 TRACE("%p %d %p\n", av, row, rec );
70 return av->table->ops->get_row(av->table, row, rec);
73 static UINT ITERATE_columns(MSIRECORD *row, LPVOID param)
75 (*(UINT *)param)++;
76 return ERROR_SUCCESS;
79 static BOOL check_column_exists(MSIDATABASE *db, MSIVIEW *columns, LPCWSTR table, LPCWSTR column)
81 MSIQUERY *view;
82 MSIRECORD *rec;
83 UINT r;
85 static const WCHAR query[] = {
86 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
87 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
88 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','A','N','D',' ',
89 '`','N','a','m','e','`','=','\'','%','s','\'',0
92 r = MSI_OpenQuery(db, &view, query, table, column);
93 if (r != ERROR_SUCCESS)
94 return FALSE;
96 r = MSI_ViewExecute(view, NULL);
97 if (r != ERROR_SUCCESS)
98 goto done;
100 r = MSI_ViewFetch(view, &rec);
101 if (r == ERROR_SUCCESS)
102 msiobj_release(&rec->hdr);
104 done:
105 msiobj_release(&view->hdr);
106 return (r == ERROR_SUCCESS);
109 static UINT alter_add_column(MSIALTERVIEW *av)
111 UINT r, colnum = 1;
112 MSIQUERY *view;
113 MSIVIEW *columns;
115 static const WCHAR szColumns[] = {'_','C','o','l','u','m','n','s',0};
116 static const WCHAR query[] = {
117 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
118 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
119 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','O','R','D','E','R',' ',
120 'B','Y',' ','`','N','u','m','b','e','r','`',0
123 r = TABLE_CreateView(av->db, szColumns, &columns);
124 if (r != ERROR_SUCCESS)
125 return r;
127 if (check_column_exists(av->db, columns, av->colinfo->table, av->colinfo->column))
128 return ERROR_BAD_QUERY_SYNTAX;
130 r = MSI_OpenQuery(av->db, &view, query, av->colinfo->table, av->colinfo->column);
131 if (r == ERROR_SUCCESS)
133 r = MSI_IterateRecords(view, NULL, ITERATE_columns, &colnum);
134 msiobj_release(&view->hdr);
137 r = columns->ops->add_column(columns, av->colinfo->table,
138 colnum, av->colinfo->column,
139 av->colinfo->type, (av->hold == 1));
141 columns->ops->delete(columns);
142 return r;
145 static UINT ALTER_execute( struct tagMSIVIEW *view, MSIRECORD *record )
147 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
149 TRACE("%p %p\n", av, record);
151 if (av->hold == 1)
152 av->table->ops->add_ref(av->table);
153 else if (av->hold == -1)
154 av->table->ops->release(av->table);
156 if (av->colinfo)
157 return alter_add_column(av);
159 return ERROR_SUCCESS;
162 static UINT ALTER_close( struct tagMSIVIEW *view )
164 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
166 TRACE("%p\n", av );
168 return ERROR_SUCCESS;
171 static UINT ALTER_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
173 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
175 TRACE("%p %p %p\n", av, rows, cols );
177 return ERROR_FUNCTION_FAILED;
180 static UINT ALTER_get_column_info( struct tagMSIVIEW *view,
181 UINT n, LPWSTR *name, UINT *type )
183 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
185 TRACE("%p %d %p %p\n", av, n, name, type );
187 return ERROR_FUNCTION_FAILED;
190 static UINT ALTER_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
191 MSIRECORD *rec, UINT row )
193 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
195 TRACE("%p %d %p\n", av, eModifyMode, rec );
197 return ERROR_FUNCTION_FAILED;
200 static UINT ALTER_delete( struct tagMSIVIEW *view )
202 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
204 TRACE("%p\n", av );
205 av->table->ops->delete( av->table );
206 msi_free( av );
208 return ERROR_SUCCESS;
211 static UINT ALTER_find_matching_rows( struct tagMSIVIEW *view, UINT col,
212 UINT val, UINT *row, MSIITERHANDLE *handle )
214 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
216 return ERROR_FUNCTION_FAILED;
219 static const MSIVIEWOPS alter_ops =
221 ALTER_fetch_int,
222 ALTER_fetch_stream,
223 ALTER_get_row,
224 NULL,
225 NULL,
226 NULL,
227 ALTER_execute,
228 ALTER_close,
229 ALTER_get_dimensions,
230 ALTER_get_column_info,
231 ALTER_modify,
232 ALTER_delete,
233 ALTER_find_matching_rows,
234 NULL,
235 NULL,
236 NULL,
237 NULL,
240 UINT ALTER_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR name, column_info *colinfo, int hold )
242 MSIALTERVIEW *av;
243 UINT r;
245 TRACE("%p %p %s %d\n", view, colinfo, debugstr_w(name), hold );
247 av = msi_alloc_zero( sizeof *av );
248 if( !av )
249 return ERROR_FUNCTION_FAILED;
251 r = TABLE_CreateView( db, name, &av->table );
252 if (r != ERROR_SUCCESS || !av->table)
253 return r;
255 if (colinfo)
256 colinfo->table = name;
258 /* fill the structure */
259 av->view.ops = &alter_ops;
260 av->db = db;
261 av->hold = hold;
262 av->colinfo = colinfo;
264 *view = &av->view;
266 return ERROR_SUCCESS;