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