Authors: Mike McCormack <mike@codeweavers.com>, Aric Stewart <aric@codeweavers.com>
[wine/multimedia.git] / dlls / msi / insert.c
blob8c7da568331dfbb5d19bce224d8d283905e38f48
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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(msi);
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 value_list *vals; /* looks like these may be ignored... */
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;
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;
63 MSIVIEW *sv;
65 TRACE("%p %p\n", iv, record );
67 sv = iv->sv;
68 if( !sv )
69 return ERROR_FUNCTION_FAILED;
71 r = sv->ops->execute( sv, 0 );
72 TRACE("tv execute returned %x\n", r);
73 if( r )
74 return r;
76 r = sv->ops->get_dimensions( sv, NULL, &col_count );
77 if( r )
78 goto err;
80 n = MSI_RecordGetFieldCount( record );
81 if( n != col_count )
83 ERR("Number of fields do not match\n");
84 goto err;
87 row = -1;
88 r = sv->ops->insert_row( sv, &row );
89 TRACE("insert_row returned %x\n", r);
90 if( r )
91 goto err;
93 for( n = 1; n <= col_count; n++ )
95 r = sv->ops->get_column_info( sv, n, NULL, &type );
96 if( r )
97 break;
99 if( type & MSITYPE_STRING )
101 const WCHAR *str = MSI_RecordGetString( record, n );
102 val = msi_addstringW( iv->db->strings, 0, str, -1, 1 );
104 else
106 val = MSI_RecordGetInteger( record, n );
107 val |= 0x8000;
109 r = sv->ops->set_int( sv, row, n, val );
110 if( r )
111 break;
114 err:
115 return ERROR_SUCCESS;
119 static UINT INSERT_close( struct tagMSIVIEW *view )
121 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
122 MSIVIEW *sv;
124 TRACE("%p\n", iv);
126 sv = iv->sv;
127 if( !sv )
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;
136 MSIVIEW *sv;
138 TRACE("%p %p %p\n", iv, rows, cols );
140 sv = iv->sv;
141 if( !sv )
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;
151 MSIVIEW *sv;
153 TRACE("%p %d %p %p\n", iv, n, name, type );
155 sv = iv->sv;
156 if( !sv )
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;
174 MSIVIEW *sv;
176 TRACE("%p\n", iv );
178 sv = iv->sv;
179 if( sv )
180 sv->ops->delete( sv );
181 delete_value_list( iv->vals );
182 HeapFree( GetProcessHeap(), 0, iv );
183 msiobj_release( &iv->db->hdr );
185 return ERROR_SUCCESS;
189 MSIVIEWOPS insert_ops =
191 INSERT_fetch_int,
192 NULL,
193 NULL,
194 NULL,
195 INSERT_execute,
196 INSERT_close,
197 INSERT_get_dimensions,
198 INSERT_get_column_info,
199 INSERT_modify,
200 INSERT_delete
203 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
204 string_list *columns, value_list *values, BOOL temp )
206 MSIINSERTVIEW *iv = NULL;
207 UINT r;
208 MSIVIEW *tv = NULL, *sv = NULL;
210 TRACE("%p\n", iv );
212 r = TABLE_CreateView( db, table, &tv );
213 if( r != ERROR_SUCCESS )
214 return r;
216 r = SELECT_CreateView( db, &sv, tv, columns );
217 if( r != ERROR_SUCCESS )
219 if( tv )
220 tv->ops->delete( tv );
221 return r;
224 iv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *iv );
225 if( !iv )
226 return ERROR_FUNCTION_FAILED;
228 /* fill the structure */
229 iv->view.ops = &insert_ops;
230 msiobj_addref( &db->hdr );
231 iv->db = db;
232 iv->vals = values;
233 iv->bIsTemp = temp;
234 iv->sv = sv;
235 *view = (MSIVIEW*) iv;
237 return ERROR_SUCCESS;