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