2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002 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 tagMSIWHEREVIEW
51 static UINT WHERE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
53 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
55 TRACE("%p %d %d %p\n", wv, row, col, val );
58 return ERROR_FUNCTION_FAILED;
60 if( row > wv->row_count )
61 return ERROR_NO_MORE_ITEMS;
63 row = wv->reorder[ row ];
65 return wv->table->ops->fetch_int( wv->table, row, col, val );
68 static UINT INT_evaluate( UINT lval, UINT op, UINT rval )
73 return ( lval == rval );
75 return ( lval && rval );
77 return ( lval || rval );
79 return ( lval > rval );
81 return ( lval < rval );
83 return ( lval <= rval );
85 return ( lval >= rval );
87 return ( lval != rval );
93 ERR("Unknown operator %d\n", op );
98 static UINT WHERE_evaluate( MSIVIEW *table, UINT row,
99 struct expr *cond, UINT *val )
104 return ERROR_SUCCESS;
108 case EXPR_COL_NUMBER:
109 return table->ops->fetch_int( table, row, cond->u.col_number, val );
113 return ERROR_SUCCESS; */
117 return ERROR_SUCCESS;
120 r = WHERE_evaluate( table, row, cond->u.expr.left, &lval );
121 if( r != ERROR_SUCCESS )
123 r = WHERE_evaluate( table, row, cond->u.expr.right, &rval );
124 if( r != ERROR_SUCCESS )
126 *val = INT_evaluate( lval, cond->u.expr.op, rval );
127 return ERROR_SUCCESS;
130 ERR("Invalid expression type\n");
134 return ERROR_SUCCESS;
138 static UINT WHERE_execute( struct tagMSIVIEW *view, MSIHANDLE record )
140 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
141 UINT count = 0, r, val, i;
142 MSIVIEW *table = wv->table;
144 TRACE("%p %ld\n", wv, record);
147 return ERROR_FUNCTION_FAILED;
149 r = table->ops->execute( table, record );
150 if( r != ERROR_SUCCESS )
153 r = table->ops->get_dimensions( table, &count, NULL );
154 if( r != ERROR_SUCCESS )
157 wv->reorder = HeapAlloc( GetProcessHeap(), 0, count*sizeof(UINT) );
159 return ERROR_FUNCTION_FAILED;
161 for( i=0; i<count; i++ )
164 r = WHERE_evaluate( table, i, wv->cond, &val );
165 if( r != ERROR_SUCCESS )
168 wv->reorder[ wv->row_count ++ ] = i;
171 return ERROR_SUCCESS;
174 static UINT WHERE_close( struct tagMSIVIEW *view )
176 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
181 return ERROR_FUNCTION_FAILED;
184 HeapFree( GetProcessHeap(), 0, wv->reorder );
187 return wv->table->ops->close( wv->table );
190 static UINT WHERE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
192 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
194 TRACE("%p %p %p\n", wv, rows, cols );
197 return ERROR_FUNCTION_FAILED;
202 return ERROR_FUNCTION_FAILED;
203 *rows = wv->row_count;
206 return wv->table->ops->get_dimensions( wv->table, NULL, cols );
209 static UINT WHERE_get_column_info( struct tagMSIVIEW *view,
210 UINT n, LPWSTR *name, UINT *type )
212 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
214 TRACE("%p %d %p %p\n", wv, n, name, type );
217 return ERROR_FUNCTION_FAILED;
219 return wv->table->ops->get_column_info( wv->table, n, name, type );
222 static UINT WHERE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIHANDLE hrec)
224 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
226 TRACE("%p %d %ld\n", wv, eModifyMode, hrec );
229 return ERROR_FUNCTION_FAILED;
231 return wv->table->ops->modify( wv->table, eModifyMode, hrec );
234 static UINT WHERE_delete( struct tagMSIVIEW *view )
236 MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
241 wv->table->ops->delete( wv->table );
244 HeapFree( GetProcessHeap(), 0, wv->reorder );
248 delete_expr( wv->cond );
250 HeapFree( GetProcessHeap(), 0, wv );
252 return ERROR_SUCCESS;
256 MSIVIEWOPS where_ops =
263 WHERE_get_dimensions,
264 WHERE_get_column_info,
269 UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
271 MSIWHEREVIEW *wv = NULL;
276 r = table->ops->get_dimensions( table, NULL, &count );
277 if( r != ERROR_SUCCESS )
279 ERR("can't get table dimensions\n");
283 wv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *wv );
285 return ERROR_FUNCTION_FAILED;
287 /* fill the structure */
288 wv->view.ops = &where_ops;
293 *view = (MSIVIEW*) wv;
295 return ERROR_SUCCESS;
298 static UINT WHERE_VerifyCondition( MSIVIEW *table, struct expr *cond,
306 r = VIEW_find_column( table, cond->u.column, &col );
307 if( r == ERROR_SUCCESS )
310 cond->type = EXPR_COL_NUMBER;
311 cond->u.col_number = col;
316 ERR("Couldn't find column %s\n", debugstr_w( cond->u.column ) );
320 r = WHERE_VerifyCondition( table, cond->u.expr.left, valid );
321 if( r != ERROR_SUCCESS )
324 return ERROR_SUCCESS;
325 r = WHERE_VerifyCondition( table, cond->u.expr.right, valid );
326 if( r != ERROR_SUCCESS )
331 cond->type = EXPR_UVAL;
332 cond->u.uval = cond->u.ival + (1<<15);
336 FIXME("can't deal with string values yet\n");
339 ERR("Invalid expression type\n");
344 return ERROR_SUCCESS;
347 UINT WHERE_AddCondition( MSIVIEW *view, struct expr *cond )
349 MSIWHEREVIEW *wv = (MSIWHEREVIEW *) view;
352 if( wv->view.ops != &where_ops )
353 return ERROR_FUNCTION_FAILED;
355 return ERROR_INVALID_PARAMETER;
358 return ERROR_SUCCESS;
360 TRACE("Adding condition\n");
362 r = WHERE_VerifyCondition( wv->table, cond, &valid );
363 if( r != ERROR_SUCCESS )
364 ERR("condition evaluation failed\n");
366 TRACE("condition is %s\n", valid ? "valid" : "invalid" );
370 return ERROR_FUNCTION_FAILED;
375 return ERROR_SUCCESS;