ntdll: Load .so builtin modules without using libwine.
[wine/zf.git] / dlls / msi / alter.c
blob5c5893c82489b065bcb4e0768ed0236448a7394e
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 ITERATE_columns(MSIRECORD *row, LPVOID param)
66 (*(UINT *)param)++;
67 return ERROR_SUCCESS;
70 static BOOL check_column_exists(MSIDATABASE *db, LPCWSTR table, LPCWSTR column)
72 MSIQUERY *view;
73 MSIRECORD *rec;
74 UINT r;
76 static const WCHAR query[] = {
77 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
78 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
79 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','A','N','D',' ',
80 '`','N','a','m','e','`','=','\'','%','s','\'',0
83 r = MSI_OpenQuery(db, &view, query, table, column);
84 if (r != ERROR_SUCCESS)
85 return FALSE;
87 r = MSI_ViewExecute(view, NULL);
88 if (r != ERROR_SUCCESS)
89 goto done;
91 r = MSI_ViewFetch(view, &rec);
92 if (r == ERROR_SUCCESS)
93 msiobj_release(&rec->hdr);
95 done:
96 msiobj_release(&view->hdr);
97 return (r == ERROR_SUCCESS);
100 static UINT alter_add_column(MSIALTERVIEW *av)
102 UINT r, colnum = 1;
103 MSIQUERY *view;
104 MSIVIEW *columns;
106 static const WCHAR szColumns[] = {'_','C','o','l','u','m','n','s',0};
107 static const WCHAR query[] = {
108 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
109 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
110 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','O','R','D','E','R',' ',
111 'B','Y',' ','`','N','u','m','b','e','r','`',0
114 r = TABLE_CreateView(av->db, szColumns, &columns);
115 if (r != ERROR_SUCCESS)
116 return r;
118 if (check_column_exists(av->db, av->colinfo->table, av->colinfo->column))
120 columns->ops->delete(columns);
121 return ERROR_BAD_QUERY_SYNTAX;
124 r = MSI_OpenQuery(av->db, &view, query, av->colinfo->table, av->colinfo->column);
125 if (r == ERROR_SUCCESS)
127 r = MSI_IterateRecords(view, NULL, ITERATE_columns, &colnum);
128 msiobj_release(&view->hdr);
129 if (r != ERROR_SUCCESS)
131 columns->ops->delete(columns);
132 return r;
135 r = columns->ops->add_column(columns, av->colinfo->table,
136 colnum, av->colinfo->column,
137 av->colinfo->type, (av->hold == 1));
139 columns->ops->delete(columns);
140 return r;
143 static UINT ALTER_execute( struct tagMSIVIEW *view, MSIRECORD *record )
145 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
146 UINT ref;
148 TRACE("%p %p\n", av, record);
150 if (av->hold == 1)
151 av->table->ops->add_ref(av->table);
152 else if (av->hold == -1)
154 ref = av->table->ops->release(av->table);
155 if (ref == 0)
156 av->table = NULL;
159 if (av->colinfo)
160 return alter_add_column(av);
162 return ERROR_SUCCESS;
165 static UINT ALTER_close( struct tagMSIVIEW *view )
167 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
169 TRACE("%p\n", av );
171 return ERROR_SUCCESS;
174 static UINT ALTER_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
176 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
178 TRACE("%p %p %p\n", av, rows, cols );
180 return ERROR_FUNCTION_FAILED;
183 static UINT ALTER_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
184 UINT *type, BOOL *temporary, LPCWSTR *table_name )
186 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
188 TRACE("%p %d %p %p %p %p\n", av, n, name, type, temporary, table_name );
190 return ERROR_FUNCTION_FAILED;
193 static UINT ALTER_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
194 MSIRECORD *rec, UINT row )
196 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
198 TRACE("%p %d %p\n", av, eModifyMode, rec );
200 return ERROR_FUNCTION_FAILED;
203 static UINT ALTER_delete( struct tagMSIVIEW *view )
205 MSIALTERVIEW *av = (MSIALTERVIEW*)view;
207 TRACE("%p\n", av );
208 if (av->table)
209 av->table->ops->delete( av->table );
210 msi_free( av );
212 return ERROR_SUCCESS;
215 static const MSIVIEWOPS alter_ops =
217 ALTER_fetch_int,
218 ALTER_fetch_stream,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 NULL,
224 NULL,
225 ALTER_execute,
226 ALTER_close,
227 ALTER_get_dimensions,
228 ALTER_get_column_info,
229 ALTER_modify,
230 ALTER_delete,
231 NULL,
232 NULL,
233 NULL,
234 NULL,
235 NULL,
238 UINT ALTER_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR name, column_info *colinfo, int hold )
240 MSIALTERVIEW *av;
241 UINT r;
243 TRACE("%p %p %s %d\n", view, colinfo, debugstr_w(name), hold );
245 av = msi_alloc_zero( sizeof *av );
246 if( !av )
247 return ERROR_FUNCTION_FAILED;
249 r = TABLE_CreateView( db, name, &av->table );
250 if (r != ERROR_SUCCESS)
252 msi_free( av );
253 return r;
256 if (colinfo)
257 colinfo->table = name;
259 /* fill the structure */
260 av->view.ops = &alter_ops;
261 av->db = db;
262 av->hold = hold;
263 av->colinfo = colinfo;
265 *view = &av->view;
267 return ERROR_SUCCESS;