riched20: Make richedit control IME aware.
[wine/wine64.git] / dlls / msi / join.c
blobab1935ee2ace2ab970ef3398b0d51bba1d83e506
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 NULL,
249 JOIN_execute,
250 JOIN_close,
251 JOIN_get_dimensions,
252 JOIN_get_column_info,
253 JOIN_modify,
254 JOIN_delete,
255 JOIN_find_matching_rows
258 UINT JOIN_CreateView( MSIDATABASE *db, MSIVIEW **view,
259 LPCWSTR left, LPCWSTR right )
261 MSIJOINVIEW *jv = NULL;
262 UINT r = ERROR_SUCCESS;
264 TRACE("%p (%s,%s)\n", jv, debugstr_w(left), debugstr_w(right) );
266 jv = msi_alloc_zero( sizeof *jv );
267 if( !jv )
268 return ERROR_FUNCTION_FAILED;
270 /* fill the structure */
271 jv->view.ops = &join_ops;
272 jv->db = db;
274 /* create the tables to join */
275 r = TABLE_CreateView( db, left, &jv->left );
276 if( r != ERROR_SUCCESS )
278 ERR("can't create left table\n");
279 goto end;
282 r = TABLE_CreateView( db, right, &jv->right );
283 if( r != ERROR_SUCCESS )
285 ERR("can't create right table\n");
286 goto end;
289 /* get the number of columns in each table */
290 r = jv->left->ops->get_dimensions( jv->left, NULL, &jv->left_count );
291 if( r != ERROR_SUCCESS )
293 ERR("can't get left table dimensions\n");
294 goto end;
297 r = jv->right->ops->get_dimensions( jv->right, NULL, &jv->right_count );
298 if( r != ERROR_SUCCESS )
300 ERR("can't get right table dimensions\n");
301 goto end;
304 *view = &jv->view;
305 return ERROR_SUCCESS;
307 end:
308 jv->view.ops->delete( &jv->view );
310 return r;