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
47 value_list *vals; /* looks like these may be ignored... */
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;
59 static UINT INSERT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
61 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
62 UINT n, type, val, r, row, col_count = 0;
65 TRACE("%p %p\n", iv, record );
69 return ERROR_FUNCTION_FAILED;
71 r = sv->ops->execute( sv, 0 );
72 TRACE("tv execute returned %x\n", r);
76 r = sv->ops->get_dimensions( sv, NULL, &col_count );
80 n = MSI_RecordGetFieldCount( record );
83 ERR("Number of fields do not match\n");
88 r = sv->ops->insert_row( sv, &row );
89 TRACE("insert_row returned %x\n", r);
93 for( n = 1; n <= col_count; n++ )
95 r = sv->ops->get_column_info( sv, n, NULL, &type );
99 if( type & MSITYPE_STRING )
101 const WCHAR *str = MSI_RecordGetString( record, n );
102 val = msi_addstringW( iv->db->strings, 0, str, -1, 1 );
106 val = MSI_RecordGetInteger( record, n );
109 r = sv->ops->set_int( sv, row, n, val );
115 return ERROR_SUCCESS;
119 static UINT INSERT_close( struct tagMSIVIEW *view )
121 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
128 return ERROR_FUNCTION_FAILED;
130 return sv->ops->close( sv );
133 static UINT INSERT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
135 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
138 TRACE("%p %p %p\n", iv, rows, cols );
142 return ERROR_FUNCTION_FAILED;
144 return sv->ops->get_dimensions( sv, rows, cols );
147 static UINT INSERT_get_column_info( struct tagMSIVIEW *view,
148 UINT n, LPWSTR *name, UINT *type )
150 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
153 TRACE("%p %d %p %p\n", iv, n, name, type );
157 return ERROR_FUNCTION_FAILED;
159 return sv->ops->get_column_info( sv, n, name, type );
162 static UINT INSERT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIHANDLE hrec)
164 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
166 TRACE("%p %d %ld\n", iv, eModifyMode, hrec );
168 return ERROR_FUNCTION_FAILED;
171 static UINT INSERT_delete( struct tagMSIVIEW *view )
173 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
180 sv->ops->delete( sv );
181 delete_value_list( iv->vals );
182 msiobj_release( &iv->db->hdr );
183 HeapFree( GetProcessHeap(), 0, iv );
185 return ERROR_SUCCESS;
189 MSIVIEWOPS insert_ops =
197 INSERT_get_dimensions,
198 INSERT_get_column_info,
203 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
204 string_list *columns, value_list *values, BOOL temp )
206 MSIINSERTVIEW *iv = NULL;
208 MSIVIEW *tv = NULL, *sv = NULL;
212 r = TABLE_CreateView( db, table, &tv );
213 if( r != ERROR_SUCCESS )
216 r = SELECT_CreateView( db, &sv, tv, columns );
217 if( r != ERROR_SUCCESS )
220 tv->ops->delete( tv );
224 iv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *iv );
226 return ERROR_FUNCTION_FAILED;
228 /* fill the structure */
229 iv->view.ops = &insert_ops;
230 msiobj_addref( &db->hdr );
235 *view = (MSIVIEW*) iv;
237 return ERROR_SUCCESS;