Create the +msidb debug channel for msi database code.
[wine/multimedia.git] / dlls / msi / delete.c
blob7f6675fe2202a9a74238d3ce995483f5d2aa6166
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2005 Mike McCormack for CodeWeavers
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
32 #include "winnls.h"
34 #include "query.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
40 * Code to delete rows from a table.
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:
45 * delete from Property
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.
51 typedef struct tagMSIDELETEVIEW
53 MSIVIEW view;
54 MSIDATABASE *db;
55 MSIVIEW *table;
56 } MSIDELETEVIEW;
58 static UINT DELETE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
60 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
62 TRACE("%p %d %d %p\n", dv, row, col, val );
64 return ERROR_FUNCTION_FAILED;
67 static UINT DELETE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
69 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
71 TRACE("%p %d %d %p\n", dv, row, col, stm );
73 return ERROR_FUNCTION_FAILED;
76 static UINT DELETE_set_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT val )
78 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
80 TRACE("%p %d %d %04x\n", dv, row, col, val );
82 return ERROR_FUNCTION_FAILED;
85 static UINT DELETE_insert_row( struct tagMSIVIEW *view, MSIRECORD *record )
87 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
89 TRACE("%p %p\n", dv, record );
91 return ERROR_FUNCTION_FAILED;
94 static UINT DELETE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
96 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
97 UINT r, i, j, rows = 0, cols = 0;
99 TRACE("%p %p\n", dv, record);
101 if( !dv->table )
102 return ERROR_FUNCTION_FAILED;
104 r = dv->table->ops->execute( dv->table, record );
105 if( r != ERROR_SUCCESS )
106 return r;
108 r = dv->table->ops->get_dimensions( dv->table, &rows, &cols );
109 if( r != ERROR_SUCCESS )
110 return r;
112 TRACE("blanking %d rows\n", rows);
114 /* blank out all the rows that match */
115 for( i=0; i<rows; i++ )
116 for( j=1; j<=cols; j++ )
117 dv->table->ops->set_int( dv->table, i, j, 0 );
119 return ERROR_SUCCESS;
122 static UINT DELETE_close( struct tagMSIVIEW *view )
124 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
126 TRACE("%p\n", dv );
128 if( !dv->table )
129 return ERROR_FUNCTION_FAILED;
131 return dv->table->ops->close( dv->table );
134 static UINT DELETE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
136 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
138 TRACE("%p %p %p\n", dv, rows, cols );
140 if( !dv->table )
141 return ERROR_FUNCTION_FAILED;
143 *rows = 0;
145 return dv->table->ops->get_dimensions( dv->table, NULL, cols );
148 static UINT DELETE_get_column_info( struct tagMSIVIEW *view,
149 UINT n, LPWSTR *name, UINT *type )
151 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
153 TRACE("%p %d %p %p\n", dv, n, name, type );
155 if( !dv->table )
156 return ERROR_FUNCTION_FAILED;
158 return dv->table->ops->get_column_info( dv->table, n, name, type );
161 static UINT DELETE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
162 MSIRECORD *rec )
164 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
166 TRACE("%p %d %p\n", dv, eModifyMode, rec );
168 return ERROR_FUNCTION_FAILED;
171 static UINT DELETE_delete( struct tagMSIVIEW *view )
173 MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
175 TRACE("%p\n", dv );
177 if( dv->table )
178 dv->table->ops->delete( dv->table );
180 msi_free( dv );
182 return ERROR_SUCCESS;
186 MSIVIEWOPS delete_ops =
188 DELETE_fetch_int,
189 DELETE_fetch_stream,
190 DELETE_set_int,
191 DELETE_insert_row,
192 DELETE_execute,
193 DELETE_close,
194 DELETE_get_dimensions,
195 DELETE_get_column_info,
196 DELETE_modify,
197 DELETE_delete
200 UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
202 MSIDELETEVIEW *dv = NULL;
204 TRACE("%p\n", dv );
206 dv = msi_alloc_zero( sizeof *dv );
207 if( !dv )
208 return ERROR_FUNCTION_FAILED;
210 /* fill the structure */
211 dv->view.ops = &delete_ops;
212 dv->db = db;
213 dv->table = table;
215 *view = &dv->view;
217 return ERROR_SUCCESS;