Handle CBR_BLOCK in EXECUTE and ADVISE DDE transactions.
[wine/hacks.git] / dlls / msi / insert.c
blobdf5c1d88d3f19bf1e8e231bf806a9e73730e87bb
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;
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;
60 * INSERT_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 static MSIRECORD *INSERT_merge_record( UINT fields, value_list *vl, MSIRECORD *rec )
67 MSIRECORD *merged;
68 DWORD wildcard_count = 1, i;
69 const WCHAR *str;
71 merged = MSI_CreateRecord( fields );
72 for( i=1; i <= fields; i++ )
74 if( !vl )
76 TRACE("Not enough elements in the list to insert\n");
77 goto err;
79 switch( vl->val->type )
81 case EXPR_SVAL:
82 TRACE("field %ld -> %s\n", i, debugstr_w(vl->val->u.sval));
83 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
84 break;
85 case EXPR_IVAL:
86 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
87 break;
88 case EXPR_WILDCARD:
89 if( !rec )
90 goto err;
91 if( MSI_RecordIsNull( rec, wildcard_count ) )
92 goto err;
93 str = MSI_RecordGetString( rec, wildcard_count );
94 MSI_RecordSetStringW( merged, i, str );
95 wildcard_count++;
96 break;
97 default:
98 ERR("Unknown expression type %d\n", vl->val->type);
100 vl = vl->next;
103 return merged;
104 err:
105 msiobj_release( &merged->hdr );
106 return NULL;
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;
113 MSIVIEW *sv;
114 MSIRECORD *values = NULL;
116 TRACE("%p %p\n", iv, record );
118 sv = iv->sv;
119 if( !sv )
120 return ERROR_FUNCTION_FAILED;
122 r = sv->ops->execute( sv, 0 );
123 TRACE("tv execute returned %x\n", r);
124 if( r )
125 return r;
127 r = sv->ops->get_dimensions( sv, NULL, &col_count );
128 if( r )
129 goto err;
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 );
136 if( !values )
137 goto err;
139 row = -1;
140 r = sv->ops->insert_row( sv, &row );
141 TRACE("insert_row returned %x\n", r);
142 if( r )
143 goto err;
145 for( n = 1; n <= col_count; n++ )
147 r = sv->ops->get_column_info( sv, n, NULL, &type );
148 if( r )
149 break;
151 if( type & MSITYPE_STRING )
153 const WCHAR *str = MSI_RecordGetString( values, n );
154 val = msi_addstringW( iv->db->strings, 0, str, -1, 1 );
156 else
158 val = MSI_RecordGetInteger( values, n );
159 val |= 0x8000;
161 r = sv->ops->set_int( sv, row, n, val );
162 if( r )
163 break;
166 err:
167 if( values )
168 msiobj_release( &values->hdr );
170 return ERROR_SUCCESS;
174 static UINT INSERT_close( struct tagMSIVIEW *view )
176 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
177 MSIVIEW *sv;
179 TRACE("%p\n", iv);
181 sv = iv->sv;
182 if( !sv )
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;
191 MSIVIEW *sv;
193 TRACE("%p %p %p\n", iv, rows, cols );
195 sv = iv->sv;
196 if( !sv )
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;
206 MSIVIEW *sv;
208 TRACE("%p %d %p %p\n", iv, n, name, type );
210 sv = iv->sv;
211 if( !sv )
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, MSIHANDLE hrec)
219 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
221 TRACE("%p %d %ld\n", iv, eModifyMode, hrec );
223 return ERROR_FUNCTION_FAILED;
226 static UINT INSERT_delete( struct tagMSIVIEW *view )
228 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
229 MSIVIEW *sv;
231 TRACE("%p\n", iv );
233 sv = iv->sv;
234 if( sv )
235 sv->ops->delete( sv );
236 delete_value_list( iv->vals );
237 msiobj_release( &iv->db->hdr );
238 HeapFree( GetProcessHeap(), 0, iv );
240 return ERROR_SUCCESS;
244 MSIVIEWOPS insert_ops =
246 INSERT_fetch_int,
247 NULL,
248 NULL,
249 NULL,
250 INSERT_execute,
251 INSERT_close,
252 INSERT_get_dimensions,
253 INSERT_get_column_info,
254 INSERT_modify,
255 INSERT_delete
258 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
259 string_list *columns, value_list *values, BOOL temp )
261 MSIINSERTVIEW *iv = NULL;
262 UINT r;
263 MSIVIEW *tv = NULL, *sv = NULL;
265 TRACE("%p\n", iv );
267 r = TABLE_CreateView( db, table, &tv );
268 if( r != ERROR_SUCCESS )
269 return r;
271 r = SELECT_CreateView( db, &sv, tv, columns );
272 if( r != ERROR_SUCCESS )
274 if( tv )
275 tv->ops->delete( tv );
276 return r;
279 iv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *iv );
280 if( !iv )
281 return ERROR_FUNCTION_FAILED;
283 /* fill the structure */
284 iv->view.ops = &insert_ops;
285 msiobj_addref( &db->hdr );
286 iv->db = db;
287 iv->vals = values;
288 iv->bIsTemp = temp;
289 iv->sv = sv;
290 *view = (MSIVIEW*) iv;
292 return ERROR_SUCCESS;