wined3d: Add a comment about D3D write masks and GLSL destination swizzles.
[wine/dibdrv.git] / dlls / msi / insert.c
blobaefc8fc0c0fc115ad651a44b0d927a57b02a2bd0
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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(msidb);
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 column_info *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 * 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 )
67 MSIRECORD *merged;
68 DWORD wildcard_count = 1, i;
70 merged = MSI_CreateRecord( fields );
71 for( i=1; i <= fields; i++ )
73 if( !vl )
75 TRACE("Not enough elements in the list to insert\n");
76 goto err;
78 switch( vl->val->type )
80 case EXPR_SVAL:
81 TRACE("field %d -> %s\n", i, debugstr_w(vl->val->u.sval));
82 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
83 break;
84 case EXPR_IVAL:
85 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
86 break;
87 case EXPR_WILDCARD:
88 if( !rec )
89 goto err;
90 MSI_RecordCopyField( rec, wildcard_count, merged, i );
91 wildcard_count++;
92 break;
93 default:
94 ERR("Unknown expression type %d\n", vl->val->type);
96 vl = vl->next;
99 return merged;
100 err:
101 msiobj_release( &merged->hdr );
102 return NULL;
105 static UINT INSERT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
107 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
108 UINT r, col_count = 0;
109 MSIVIEW *sv;
110 MSIRECORD *values = NULL;
112 TRACE("%p %p\n", iv, record );
114 sv = iv->sv;
115 if( !sv )
116 return ERROR_FUNCTION_FAILED;
118 r = sv->ops->execute( sv, 0 );
119 TRACE("tv execute returned %x\n", r);
120 if( r )
121 return r;
123 r = sv->ops->get_dimensions( sv, NULL, &col_count );
124 if( r )
125 goto err;
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 );
132 if( !values )
133 goto err;
135 r = sv->ops->insert_row( sv, values );
137 err:
138 if( values )
139 msiobj_release( &values->hdr );
141 return r;
145 static UINT INSERT_close( struct tagMSIVIEW *view )
147 MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
148 MSIVIEW *sv;
150 TRACE("%p\n", iv);
152 sv = iv->sv;
153 if( !sv )
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;
162 MSIVIEW *sv;
164 TRACE("%p %p %p\n", iv, rows, cols );
166 sv = iv->sv;
167 if( !sv )
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;
177 MSIVIEW *sv;
179 TRACE("%p %d %p %p\n", iv, n, name, type );
181 sv = iv->sv;
182 if( !sv )
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;
200 MSIVIEW *sv;
202 TRACE("%p\n", iv );
204 sv = iv->sv;
205 if( sv )
206 sv->ops->delete( sv );
207 msiobj_release( &iv->db->hdr );
208 msi_free( iv );
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 =
224 INSERT_fetch_int,
225 NULL,
226 NULL,
227 NULL,
228 INSERT_execute,
229 INSERT_close,
230 INSERT_get_dimensions,
231 INSERT_get_column_info,
232 INSERT_modify,
233 INSERT_delete,
234 INSERT_find_matching_rows
237 static UINT count_column_info( column_info *ci )
239 UINT n = 0;
240 for ( ; ci; ci = ci->next )
241 n++;
242 return n;
245 UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
246 column_info *columns, column_info *values, BOOL temp )
248 MSIINSERTVIEW *iv = NULL;
249 UINT r;
250 MSIVIEW *tv = NULL, *sv = NULL;
252 TRACE("%p\n", iv );
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 )
260 return r;
262 r = SELECT_CreateView( db, &sv, tv, columns );
263 if( r != ERROR_SUCCESS )
265 if( tv )
266 tv->ops->delete( tv );
267 return r;
270 iv = msi_alloc_zero( sizeof *iv );
271 if( !iv )
272 return ERROR_FUNCTION_FAILED;
274 /* fill the structure */
275 iv->view.ops = &insert_ops;
276 msiobj_addref( &db->hdr );
277 iv->db = db;
278 iv->vals = values;
279 iv->bIsTemp = temp;
280 iv->sv = sv;
281 *view = (MSIVIEW*) iv;
283 return ERROR_SUCCESS;