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, value_list *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 n, type, val, r, row, 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 );
140 r = sv->ops->insert_row( sv, &row );
141 TRACE("insert_row returned %x\n", r);
145 for( n = 1; n <= col_count; n++ )
147 r = sv->ops->get_column_info( sv, n, NULL, &type );
151 if( type & MSITYPE_STRING )
153 const WCHAR *str = MSI_RecordGetString( values, n );
154 val = msi_addstringW( iv->db->strings, 0, str, -1, 1 );
158 val = MSI_RecordGetInteger( values, n );
161 r = sv->ops->set_int( sv, row, n, val );
168 msiobj_release( &values->hdr );
170 return ERROR_SUCCESS;
174 static UINT INSERT_close( struct tagMSIVIEW *view )
176 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
183 return ERROR_FUNCTION_FAILED;
185 return sv->ops->close( sv );
188 static UINT INSERT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
190 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
193 TRACE("%p %p %p\n", iv, rows, cols );
197 return ERROR_FUNCTION_FAILED;
199 return sv->ops->get_dimensions( sv, rows, cols );
202 static UINT INSERT_get_column_info( struct tagMSIVIEW *view,
203 UINT n, LPWSTR *name, UINT *type )
205 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
208 TRACE("%p %d %p %p\n", iv, n, name, type );
212 return ERROR_FUNCTION_FAILED;
214 return sv->ops->get_column_info( sv, n, name, type );
217 static UINT INSERT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec)
219 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
221 TRACE("%p %d %p\n", iv, eModifyMode, rec );
223 return ERROR_FUNCTION_FAILED;
226 static UINT INSERT_delete( struct tagMSIVIEW *view )
228 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
235 sv->ops->delete( sv );
236 msiobj_release( &iv->db->hdr );
237 HeapFree( GetProcessHeap(), 0, iv );
239 return ERROR_SUCCESS;
243 MSIVIEWOPS insert_ops =
251 INSERT_get_dimensions,
252 INSERT_get_column_info,
257 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
258 column_info *columns, value_list *values, BOOL temp )
260 MSIINSERTVIEW *iv = NULL;
262 MSIVIEW *tv = NULL, *sv = NULL;
266 r = TABLE_CreateView( db, table, &tv );
267 if( r != ERROR_SUCCESS )
270 r = SELECT_CreateView( db, &sv, tv, columns );
271 if( r != ERROR_SUCCESS )
274 tv->ops->delete( tv );
278 iv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *iv );
280 return ERROR_FUNCTION_FAILED;
282 /* fill the structure */
283 iv->view.ops = &insert_ops;
284 msiobj_addref( &db->hdr );
289 *view = (MSIVIEW*) iv;
291 return ERROR_SUCCESS;