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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
39 /* below is the query interface to a table */
41 typedef struct tagMSIINSERTVIEW
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;
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 static MSIRECORD *INSERT_merge_record( UINT fields, column_info *vl, MSIRECORD *rec )
68 DWORD wildcard_count = 1, i;
71 merged = MSI_CreateRecord( fields );
72 for( i=1; i <= fields; i++ )
76 TRACE("Not enough elements in the list to insert\n");
79 switch( vl->val->type )
82 TRACE("field %ld -> %s\n", i, debugstr_w(vl->val->u.sval));
83 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
86 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
91 if( MSI_RecordIsNull( rec, wildcard_count ) )
93 str = MSI_RecordGetString( rec, wildcard_count );
94 MSI_RecordSetStringW( merged, i, str );
98 ERR("Unknown expression type %d\n", vl->val->type);
105 msiobj_release( &merged->hdr );
109 static UINT INSERT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
111 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
112 UINT r, col_count = 0;
114 MSIRECORD *values = NULL;
116 TRACE("%p %p\n", iv, record );
120 return ERROR_FUNCTION_FAILED;
122 r = sv->ops->execute( sv, 0 );
123 TRACE("tv execute returned %x\n", r);
127 r = sv->ops->get_dimensions( sv, NULL, &col_count );
132 * Merge the wildcard values into the list of values provided
133 * in the query, and create a record containing both.
135 values = INSERT_merge_record( col_count, iv->vals, record );
139 r = sv->ops->insert_row( sv, values );
143 msiobj_release( &values->hdr );
149 static UINT INSERT_close( struct tagMSIVIEW *view )
151 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
158 return ERROR_FUNCTION_FAILED;
160 return sv->ops->close( sv );
163 static UINT INSERT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
165 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
168 TRACE("%p %p %p\n", iv, rows, cols );
172 return ERROR_FUNCTION_FAILED;
174 return sv->ops->get_dimensions( sv, rows, cols );
177 static UINT INSERT_get_column_info( struct tagMSIVIEW *view,
178 UINT n, LPWSTR *name, UINT *type )
180 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
183 TRACE("%p %d %p %p\n", iv, n, name, type );
187 return ERROR_FUNCTION_FAILED;
189 return sv->ops->get_column_info( sv, n, name, type );
192 static UINT INSERT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec)
194 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
196 TRACE("%p %d %p\n", iv, eModifyMode, rec );
198 return ERROR_FUNCTION_FAILED;
201 static UINT INSERT_delete( struct tagMSIVIEW *view )
203 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
210 sv->ops->delete( sv );
211 msiobj_release( &iv->db->hdr );
212 HeapFree( GetProcessHeap(), 0, iv );
214 return ERROR_SUCCESS;
218 MSIVIEWOPS insert_ops =
226 INSERT_get_dimensions,
227 INSERT_get_column_info,
232 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
233 column_info *columns, column_info *values, BOOL temp )
235 MSIINSERTVIEW *iv = NULL;
237 MSIVIEW *tv = NULL, *sv = NULL;
241 r = TABLE_CreateView( db, table, &tv );
242 if( r != ERROR_SUCCESS )
245 r = SELECT_CreateView( db, &sv, tv, columns );
246 if( r != ERROR_SUCCESS )
249 tv->ops->delete( tv );
253 iv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *iv );
255 return ERROR_FUNCTION_FAILED;
257 /* fill the structure */
258 iv->view.ops = &insert_ops;
259 msiobj_addref( &db->hdr );
264 *view = (MSIVIEW*) iv;
266 return ERROR_SUCCESS;