user32: Simplify some maximized MDI child checks.
[wine/dibdrv.git] / dlls / msi / join.c
blobb384630c2e23d07db37de464c041bb74aac5df67
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2006 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 "query.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
36 typedef struct tagMSIJOINVIEW
38 MSIVIEW view;
39 MSIDATABASE *db;
40 MSIVIEW *left, *right;
41 UINT left_count, right_count;
42 UINT left_rows, right_rows;
43 } MSIJOINVIEW;
45 static UINT JOIN_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
47 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
48 MSIVIEW *table;
50 TRACE("%p %d %d %p\n", jv, row, col, val );
52 if( !jv->left || !jv->right )
53 return ERROR_FUNCTION_FAILED;
55 if( (col==0) || (col>(jv->left_count + jv->right_count)) )
56 return ERROR_FUNCTION_FAILED;
58 if( row >= (jv->left_rows * jv->right_rows) )
59 return ERROR_FUNCTION_FAILED;
61 if( col <= jv->left_count )
63 table = jv->left;
64 row = (row/jv->right_rows);
66 else
68 table = jv->right;
69 row = (row % jv->right_rows);
70 col -= jv->left_count;
73 return table->ops->fetch_int( table, row, col, val );
76 static UINT JOIN_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
78 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
79 MSIVIEW *table;
81 TRACE("%p %d %d %p\n", jv, row, col, stm );
83 if( !jv->left || !jv->right )
84 return ERROR_FUNCTION_FAILED;
86 if( (col==0) || (col>(jv->left_count + jv->right_count)) )
87 return ERROR_FUNCTION_FAILED;
89 if( row >= jv->left_rows * jv->right_rows )
90 return ERROR_FUNCTION_FAILED;
92 if( row <= jv->left_count )
94 table = jv->left;
95 row = (row/jv->right_rows);
97 else
99 table = jv->right;
100 row = (row % jv->right_rows);
101 col -= jv->left_count;
104 return table->ops->fetch_stream( table, row, col, stm );
107 static UINT JOIN_execute( struct tagMSIVIEW *view, MSIRECORD *record )
109 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
110 UINT r, *ldata = NULL, *rdata = NULL;
112 TRACE("%p %p\n", jv, record);
114 if( !jv->left || !jv->right )
115 return ERROR_FUNCTION_FAILED;
117 r = jv->left->ops->execute( jv->left, NULL );
118 if (r != ERROR_SUCCESS)
119 return r;
121 r = jv->right->ops->execute( jv->right, NULL );
122 if (r != ERROR_SUCCESS)
123 return r;
125 /* get the number of rows in each table */
126 r = jv->left->ops->get_dimensions( jv->left, &jv->left_rows, NULL );
127 if( r != ERROR_SUCCESS )
129 ERR("can't get left table dimensions\n");
130 goto end;
133 r = jv->right->ops->get_dimensions( jv->right, &jv->right_rows, NULL );
134 if( r != ERROR_SUCCESS )
136 ERR("can't get right table dimensions\n");
137 goto end;
140 end:
141 msi_free( ldata );
142 msi_free( rdata );
144 return r;
147 static UINT JOIN_close( struct tagMSIVIEW *view )
149 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
151 TRACE("%p\n", jv );
153 if( !jv->left || !jv->right )
154 return ERROR_FUNCTION_FAILED;
156 jv->left->ops->close( jv->left );
157 jv->right->ops->close( jv->right );
159 return ERROR_SUCCESS;
162 static UINT JOIN_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
164 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
166 TRACE("%p %p %p\n", jv, rows, cols );
168 if( cols )
169 *cols = jv->left_count + jv->right_count;
171 if( rows )
173 if( !jv->left || !jv->right )
174 return ERROR_FUNCTION_FAILED;
176 *rows = jv->left_rows * jv->right_rows;
179 return ERROR_SUCCESS;
182 static UINT JOIN_get_column_info( struct tagMSIVIEW *view,
183 UINT n, LPWSTR *name, UINT *type )
185 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
187 TRACE("%p %d %p %p\n", jv, n, name, type );
189 if( !jv->left || !jv->right )
190 return ERROR_FUNCTION_FAILED;
192 if( (n==0) || (n>(jv->left_count + jv->right_count)) )
193 return ERROR_FUNCTION_FAILED;
195 if( n <= jv->left_count )
196 return jv->left->ops->get_column_info( jv->left, n, name, type );
198 n = n - jv->left_count;
200 return jv->right->ops->get_column_info( jv->right, n, name, type );
203 static UINT JOIN_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
204 MSIRECORD *rec )
206 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
208 TRACE("%p %d %p\n", jv, eModifyMode, rec );
210 return ERROR_FUNCTION_FAILED;
213 static UINT JOIN_delete( struct tagMSIVIEW *view )
215 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
217 TRACE("%p\n", jv );
219 if( jv->left )
220 jv->left->ops->delete( jv->left );
221 jv->left = NULL;
223 if( jv->right )
224 jv->right->ops->delete( jv->right );
225 jv->right = NULL;
227 msi_free( jv );
229 return ERROR_SUCCESS;
232 static UINT JOIN_find_matching_rows( struct tagMSIVIEW *view, UINT col,
233 UINT val, UINT *row, MSIITERHANDLE *handle )
235 MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
237 FIXME("%p, %d, %u, %p\n", jv, col, val, *handle);
239 return ERROR_FUNCTION_FAILED;
242 static const MSIVIEWOPS join_ops =
244 JOIN_fetch_int,
245 JOIN_fetch_stream,
246 NULL,
247 NULL,
248 JOIN_execute,
249 JOIN_close,
250 JOIN_get_dimensions,
251 JOIN_get_column_info,
252 JOIN_modify,
253 JOIN_delete,
254 JOIN_find_matching_rows
257 UINT JOIN_CreateView( MSIDATABASE *db, MSIVIEW **view,
258 LPCWSTR left, LPCWSTR right )
260 MSIJOINVIEW *jv = NULL;
261 UINT r = ERROR_SUCCESS;
263 TRACE("%p (%s,%s)\n", jv, debugstr_w(left), debugstr_w(right) );
265 jv = msi_alloc_zero( sizeof *jv );
266 if( !jv )
267 return ERROR_FUNCTION_FAILED;
269 /* fill the structure */
270 jv->view.ops = &join_ops;
271 jv->db = db;
273 /* create the tables to join */
274 r = TABLE_CreateView( db, left, &jv->left );
275 if( r != ERROR_SUCCESS )
277 ERR("can't create left table\n");
278 goto end;
281 r = TABLE_CreateView( db, right, &jv->right );
282 if( r != ERROR_SUCCESS )
284 ERR("can't create right table\n");
285 goto end;
288 /* get the number of columns in each table */
289 r = jv->left->ops->get_dimensions( jv->left, NULL, &jv->left_count );
290 if( r != ERROR_SUCCESS )
292 ERR("can't get left table dimensions\n");
293 goto end;
296 r = jv->right->ops->get_dimensions( jv->right, NULL, &jv->right_count );
297 if( r != ERROR_SUCCESS )
299 ERR("can't get right table dimensions\n");
300 goto end;
303 *view = &jv->view;
304 return ERROR_SUCCESS;
306 end:
307 jv->view.ops->delete( &jv->view );
309 return r;