qmgr: Implement job lists for IBackgroundCopyManager.
[wine/gsoc_dplay.git] / dlls / msi / insert.c
blob55ac2340582041722dca6932ef89751ced6da6fb
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 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., 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"
32 #include "winnls.h"
34 #include "query.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
39 /* below is the query interface to a table */
41 typedef struct tagMSIINSERTVIEW
43 MSIVIEW view;
44 MSIDATABASE *db;
45 BOOL bIsTemp;
46 MSIVIEW *sv;
47 column_info *vals;
48 } MSIINSERTVIEW;
50 static UINT INSERT_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
52 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
54 TRACE("%p %d %d %p\n", iv, row, col, val );
56 return ERROR_FUNCTION_FAILED;
60 * msi_query_merge_record
62 * Merge a value_list and a record to create a second record.
63 * Replace wildcard entries in the valuelist with values from the record
65 MSIRECORD *msi_query_merge_record( UINT fields, const column_info *vl, MSIRECORD *rec )
67 MSIRECORD *merged;
68 DWORD wildcard_count = 1, i;
70 merged = MSI_CreateRecord( fields );
71 for( i=1; i <= fields; i++ )
73 if( !vl )
75 TRACE("Not enough elements in the list to insert\n");
76 goto err;
78 switch( vl->val->type )
80 case EXPR_SVAL:
81 TRACE("field %d -> %s\n", i, debugstr_w(vl->val->u.sval));
82 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
83 break;
84 case EXPR_IVAL:
85 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
86 break;
87 case EXPR_WILDCARD:
88 if( !rec )
89 goto err;
90 MSI_RecordCopyField( rec, wildcard_count, merged, i );
91 wildcard_count++;
92 break;
93 default:
94 ERR("Unknown expression type %d\n", vl->val->type);
96 vl = vl->next;
99 return merged;
100 err:
101 msiobj_release( &merged->hdr );
102 return NULL;
105 static UINT INSERT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
107 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
108 UINT r, col_count = 0;
109 MSIVIEW *sv;
110 MSIRECORD *values = NULL;
112 TRACE("%p %p\n", iv, record );
114 sv = iv->sv;
115 if( !sv )
116 return ERROR_FUNCTION_FAILED;
118 r = sv->ops->execute( sv, 0 );
119 TRACE("tv execute returned %x\n", r);
120 if( r )
121 return r;
123 r = sv->ops->get_dimensions( sv, NULL, &col_count );
124 if( r )
125 goto err;
128 * Merge the wildcard values into the list of values provided
129 * in the query, and create a record containing both.
131 values = msi_query_merge_record( col_count, iv->vals, record );
132 if( !values )
133 goto err;
135 r = sv->ops->insert_row( sv, values, iv->bIsTemp );
137 err:
138 if( values )
139 msiobj_release( &values->hdr );
141 return r;
145 static UINT INSERT_close( struct tagMSIVIEW *view )
147 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
148 MSIVIEW *sv;
150 TRACE("%p\n", iv);
152 sv = iv->sv;
153 if( !sv )
154 return ERROR_FUNCTION_FAILED;
156 return sv->ops->close( sv );
159 static UINT INSERT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
161 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
162 MSIVIEW *sv;
164 TRACE("%p %p %p\n", iv, rows, cols );
166 sv = iv->sv;
167 if( !sv )
168 return ERROR_FUNCTION_FAILED;
170 return sv->ops->get_dimensions( sv, rows, cols );
173 static UINT INSERT_get_column_info( struct tagMSIVIEW *view,
174 UINT n, LPWSTR *name, UINT *type )
176 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
177 MSIVIEW *sv;
179 TRACE("%p %d %p %p\n", iv, n, name, type );
181 sv = iv->sv;
182 if( !sv )
183 return ERROR_FUNCTION_FAILED;
185 return sv->ops->get_column_info( sv, n, name, type );
188 static UINT INSERT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
190 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
192 TRACE("%p %d %p\n", iv, eModifyMode, rec );
194 return ERROR_FUNCTION_FAILED;
197 static UINT INSERT_delete( struct tagMSIVIEW *view )
199 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
200 MSIVIEW *sv;
202 TRACE("%p\n", iv );
204 sv = iv->sv;
205 if( sv )
206 sv->ops->delete( sv );
207 msiobj_release( &iv->db->hdr );
208 msi_free( iv );
210 return ERROR_SUCCESS;
213 static UINT INSERT_find_matching_rows( struct tagMSIVIEW *view, UINT col,
214 UINT val, UINT *row, MSIITERHANDLE *handle )
216 TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
218 return ERROR_FUNCTION_FAILED;
222 static const MSIVIEWOPS insert_ops =
224 INSERT_fetch_int,
225 NULL,
226 NULL,
227 NULL,
228 NULL,
229 NULL,
230 INSERT_execute,
231 INSERT_close,
232 INSERT_get_dimensions,
233 INSERT_get_column_info,
234 INSERT_modify,
235 INSERT_delete,
236 INSERT_find_matching_rows,
237 NULL,
238 NULL,
239 NULL,
240 NULL,
241 NULL,
244 static UINT count_column_info( const column_info *ci )
246 UINT n = 0;
247 for ( ; ci; ci = ci->next )
248 n++;
249 return n;
252 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
253 column_info *columns, column_info *values, BOOL temp )
255 MSIINSERTVIEW *iv = NULL;
256 UINT r;
257 MSIVIEW *tv = NULL, *sv = NULL;
259 TRACE("%p\n", iv );
261 /* there should be one value for each column */
262 if ( count_column_info( columns ) != count_column_info(values) )
263 return ERROR_BAD_QUERY_SYNTAX;
265 r = TABLE_CreateView( db, table, &tv );
266 if( r != ERROR_SUCCESS )
267 return r;
269 r = SELECT_CreateView( db, &sv, tv, columns );
270 if( r != ERROR_SUCCESS )
272 if( tv )
273 tv->ops->delete( tv );
274 return r;
277 iv = msi_alloc_zero( sizeof *iv );
278 if( !iv )
279 return ERROR_FUNCTION_FAILED;
281 /* fill the structure */
282 iv->view.ops = &insert_ops;
283 msiobj_addref( &db->hdr );
284 iv->db = db;
285 iv->vals = values;
286 iv->bIsTemp = temp;
287 iv->sv = sv;
288 *view = (MSIVIEW*) iv;
290 return ERROR_SUCCESS;