9f65415e1bbedd0519228c1dccc5dc6476c48a18
[reactos.git] / reactos / dll / win32 / msi / delete.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2002-2005 Mike McCormack for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include <stdarg.h>
26
27 //#include "windef.h"
28 //#include "winbase.h"
29 //#include "winerror.h"
30 #include <wine/debug.h>
31 //#include "msi.h"
32 //#include "msiquery.h"
33 //#include "objbase.h"
34 //#include "objidl.h"
35 #include "msipriv.h"
36 //#include "winnls.h"
37
38 //#include "query.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
41
42
43 /*
44 * Code to delete rows from a table.
45 *
46 * We delete rows by blanking them out rather than trying to remove the row.
47 * This appears to be what the native MSI does (or tries to do). For the query:
48 *
49 * delete from Property
50 *
51 * some non-zero entries are left in the table by native MSI. I'm not sure if
52 * that's a bug in the way I'm running the query, or a just a bug.
53 */
54
55 typedef struct tagMSIDELETEVIEW
56 {
57 MSIVIEW view;
58 MSIDATABASE *db;
59 MSIVIEW *table;
60 } MSIDELETEVIEW;
61
62 static UINT DELETE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
63 {
64 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
65
66 TRACE("%p %d %d %p\n", dv, row, col, val );
67
68 return ERROR_FUNCTION_FAILED;
69 }
70
71 static UINT DELETE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
72 {
73 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
74
75 TRACE("%p %d %d %p\n", dv, row, col, stm );
76
77 return ERROR_FUNCTION_FAILED;
78 }
79
80 static UINT DELETE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
81 {
82 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
83 UINT r, i, rows = 0, cols = 0;
84
85 TRACE("%p %p\n", dv, record);
86
87 if( !dv->table )
88 return ERROR_FUNCTION_FAILED;
89
90 r = dv->table->ops->execute( dv->table, record );
91 if( r != ERROR_SUCCESS )
92 return r;
93
94 r = dv->table->ops->get_dimensions( dv->table, &rows, &cols );
95 if( r != ERROR_SUCCESS )
96 return r;
97
98 TRACE("deleting %d rows\n", rows);
99
100 /* blank out all the rows that match */
101 for ( i=0; i<rows; i++ )
102 dv->table->ops->delete_row( dv->table, i );
103
104 return ERROR_SUCCESS;
105 }
106
107 static UINT DELETE_close( struct tagMSIVIEW *view )
108 {
109 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
110
111 TRACE("%p\n", dv );
112
113 if( !dv->table )
114 return ERROR_FUNCTION_FAILED;
115
116 return dv->table->ops->close( dv->table );
117 }
118
119 static UINT DELETE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
120 {
121 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
122
123 TRACE("%p %p %p\n", dv, rows, cols );
124
125 if( !dv->table )
126 return ERROR_FUNCTION_FAILED;
127
128 *rows = 0;
129
130 return dv->table->ops->get_dimensions( dv->table, NULL, cols );
131 }
132
133 static UINT DELETE_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
134 UINT *type, BOOL *temporary, LPCWSTR *table_name )
135 {
136 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
137
138 TRACE("%p %d %p %p %p %p\n", dv, n, name, type, temporary, table_name );
139
140 if( !dv->table )
141 return ERROR_FUNCTION_FAILED;
142
143 return dv->table->ops->get_column_info( dv->table, n, name,
144 type, temporary, table_name);
145 }
146
147 static UINT DELETE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
148 MSIRECORD *rec, UINT row )
149 {
150 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
151
152 TRACE("%p %d %p\n", dv, eModifyMode, rec );
153
154 return ERROR_FUNCTION_FAILED;
155 }
156
157 static UINT DELETE_delete( struct tagMSIVIEW *view )
158 {
159 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
160
161 TRACE("%p\n", dv );
162
163 if( dv->table )
164 dv->table->ops->delete( dv->table );
165
166 msi_free( dv );
167
168 return ERROR_SUCCESS;
169 }
170
171 static UINT DELETE_find_matching_rows( struct tagMSIVIEW *view, UINT col,
172 UINT val, UINT *row, MSIITERHANDLE *handle )
173 {
174 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
175
176 return ERROR_FUNCTION_FAILED;
177 }
178
179
180 static const MSIVIEWOPS delete_ops =
181 {
182 DELETE_fetch_int,
183 DELETE_fetch_stream,
184 NULL,
185 NULL,
186 NULL,
187 NULL,
188 DELETE_execute,
189 DELETE_close,
190 DELETE_get_dimensions,
191 DELETE_get_column_info,
192 DELETE_modify,
193 DELETE_delete,
194 DELETE_find_matching_rows,
195 NULL,
196 NULL,
197 NULL,
198 NULL,
199 NULL,
200 NULL,
201 };
202
203 UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
204 {
205 MSIDELETEVIEW *dv = NULL;
206
207 TRACE("%p\n", dv );
208
209 dv = msi_alloc_zero( sizeof *dv );
210 if( !dv )
211 return ERROR_FUNCTION_FAILED;
212
213 /* fill the structure */
214 dv->view.ops = &delete_ops;
215 dv->db = db;
216 dv->table = table;
217
218 *view = &dv->view;
219
220 return ERROR_SUCCESS;
221 }