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
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
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;
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, column_info *vl, MSIRECORD *rec )
68 DWORD wildcard_count = 1, i;
70 merged = MSI_CreateRecord( fields );
71 for( i=1; i <= fields; i++ )
75 TRACE("Not enough elements in the list to insert\n");
78 switch( vl->val->type )
81 TRACE("field %d -> %s\n", i, debugstr_w(vl->val->u.sval));
82 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
85 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
90 MSI_RecordCopyField( rec, wildcard_count, merged, i );
94 ERR("Unknown expression type %d\n", vl->val->type);
101 msiobj_release( &merged->hdr );
105 static UINT INSERT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
107 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
108 UINT r, col_count = 0;
110 MSIRECORD *values = NULL;
112 TRACE("%p %p\n", iv, record );
116 return ERROR_FUNCTION_FAILED;
118 r = sv->ops->execute( sv, 0 );
119 TRACE("tv execute returned %x\n", r);
123 r = sv->ops->get_dimensions( sv, NULL, &col_count );
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 );
135 r = sv->ops->insert_row( sv, values );
139 msiobj_release( &values->hdr );
145 static UINT INSERT_close( struct tagMSIVIEW *view )
147 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
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;
164 TRACE("%p %p %p\n", iv, rows, cols );
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;
179 TRACE("%p %d %p %p\n", iv, n, name, type );
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)
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;
206 sv->ops->delete( sv );
207 msiobj_release( &iv->db->hdr );
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 =
230 INSERT_get_dimensions,
231 INSERT_get_column_info,
234 INSERT_find_matching_rows
237 static UINT count_column_info( column_info *ci )
240 for ( ; ci; ci = ci->next )
245 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
246 column_info *columns, column_info *values, BOOL temp )
248 MSIINSERTVIEW *iv = NULL;
250 MSIVIEW *tv = NULL, *sv = NULL;
254 /* there should be one value for each column */
255 if ( count_column_info( columns ) != count_column_info(values) )
256 return ERROR_BAD_QUERY_SYNTAX;
258 r = TABLE_CreateView( db, table, &tv );
259 if( r != ERROR_SUCCESS )
262 r = SELECT_CreateView( db, &sv, tv, columns );
263 if( r != ERROR_SUCCESS )
266 tv->ops->delete( tv );
270 iv = msi_alloc_zero( sizeof *iv );
272 return ERROR_FUNCTION_FAILED;
274 /* fill the structure */
275 iv->view.ops = &insert_ops;
276 msiobj_addref( &db->hdr );
281 *view = (MSIVIEW*) iv;
283 return ERROR_SUCCESS;