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 void WHERE_delete_expr( struct expr
*e
)
238 if( e
->type
== EXPR_COMPLEX
)
240 WHERE_delete_expr( e
->u
.expr
.left
);
241 WHERE_delete_expr( e
->u
.expr
.right
);
243 HeapFree( GetProcessHeap(), 0, e
);
246 static UINT
WHERE_delete( struct tagMSIVIEW
*view
)
248 MSIWHEREVIEW
*wv
= (MSIWHEREVIEW
*)view
;
253 wv
->table
->ops
->delete( wv
->table
);
256 HeapFree( GetProcessHeap(), 0, wv
->reorder
);
260 WHERE_delete_expr( wv
->cond
);
262 HeapFree( GetProcessHeap(), 0, wv
);
264 return ERROR_SUCCESS
;
268 MSIVIEWOPS where_ops
=
273 WHERE_get_dimensions
,
274 WHERE_get_column_info
,
279 UINT
WHERE_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, MSIVIEW
*table
)
281 MSIWHEREVIEW
*wv
= NULL
;
286 r
= table
->ops
->get_dimensions( table
, NULL
, &count
);
287 if( r
!= ERROR_SUCCESS
)
289 ERR("can't get table dimensions\n");
293 wv
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *wv
);
295 return ERROR_FUNCTION_FAILED
;
297 /* fill the structure */
298 wv
->view
.ops
= &where_ops
;
303 *view
= (MSIVIEW
*) wv
;
305 return ERROR_SUCCESS
;
308 static UINT
WHERE_VerifyCondition( MSIVIEW
*table
, struct expr
*cond
,
316 r
= VIEW_find_column( table
, cond
->u
.column
, &col
);
317 if( r
== ERROR_SUCCESS
)
320 cond
->type
= EXPR_COL_NUMBER
;
321 cond
->u
.col_number
= col
;
326 ERR("Couldn't find column %s\n", debugstr_w( cond
->u
.column
) );
330 r
= WHERE_VerifyCondition( table
, cond
->u
.expr
.left
, valid
);
331 if( r
!= ERROR_SUCCESS
)
334 return ERROR_SUCCESS
;
335 r
= WHERE_VerifyCondition( table
, cond
->u
.expr
.right
, valid
);
336 if( r
!= ERROR_SUCCESS
)
341 cond
->type
= EXPR_UVAL
;
342 cond
->u
.uval
= cond
->u
.ival
+ (1<<15);
346 FIXME("can't deal with string values yet\n");
349 ERR("Invalid expression type\n");
354 return ERROR_SUCCESS
;
357 UINT
WHERE_AddCondition( MSIVIEW
*view
, struct expr
*cond
)
359 MSIWHEREVIEW
*wv
= (MSIWHEREVIEW
*) view
;
362 if( wv
->view
.ops
!= &where_ops
)
363 return ERROR_FUNCTION_FAILED
;
365 return ERROR_INVALID_PARAMETER
;
368 return ERROR_SUCCESS
;
370 TRACE("Adding condition\n");
372 r
= WHERE_VerifyCondition( wv
->table
, cond
, &valid
);
373 if( r
!= ERROR_SUCCESS
)
374 ERR("condition evaluation failed\n");
376 TRACE("condition is %s\n", valid
? "valid" : "invalid" );
379 WHERE_delete_expr( cond
);
380 return ERROR_FUNCTION_FAILED
;
385 return ERROR_SUCCESS
;