Add a couple of missing spec files.
[wine.git] / dlls / msi / select.c
blobc7b50b6387138b24c654419e7ee50f37b508e3c8
1 /*
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
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(msi);
39 /* below is the query interface to a table */
41 typedef struct tagMSISELECTVIEW
43 MSIVIEW view;
44 MSIDATABASE *db;
45 MSIVIEW *table;
46 UINT num_cols;
47 UINT max_cols;
48 UINT cols[1];
49 } MSISELECTVIEW;
51 static UINT SELECT_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
53 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
55 TRACE("%p %d %d %p\n", sv, row, col, val );
57 if( !sv->table )
58 return ERROR_FUNCTION_FAILED;
60 if( (col==0) || (col>sv->num_cols) )
61 return ERROR_FUNCTION_FAILED;
63 col = sv->cols[ col - 1 ];
65 return sv->table->ops->fetch_int( sv->table, row, col, val );
68 static UINT SELECT_execute( struct tagMSIVIEW *view, MSIHANDLE record )
70 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
72 TRACE("%p %ld\n", sv, record);
74 if( !sv->table )
75 return ERROR_FUNCTION_FAILED;
77 return sv->table->ops->execute( sv->table, record );
80 static UINT SELECT_close( struct tagMSIVIEW *view )
82 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
84 TRACE("%p\n", sv );
86 if( !sv->table )
87 return ERROR_FUNCTION_FAILED;
89 return sv->table->ops->close( sv->table );
92 static UINT SELECT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
94 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
96 TRACE("%p %p %p\n", sv, rows, cols );
98 if( !sv->table )
99 return ERROR_FUNCTION_FAILED;
101 if( cols )
102 *cols = sv->num_cols;
104 return sv->table->ops->get_dimensions( sv->table, rows, NULL );
107 static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
108 UINT n, LPWSTR *name, UINT *type )
110 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
112 TRACE("%p %d %p %p\n", sv, n, name, type );
114 if( !sv->table )
115 return ERROR_FUNCTION_FAILED;
117 if( (n==0) || (n>sv->num_cols) )
118 return ERROR_FUNCTION_FAILED;
120 n = sv->cols[ n - 1 ];
122 return sv->table->ops->get_column_info( sv->table, n, name, type );
125 static UINT SELECT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIHANDLE hrec)
127 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
129 TRACE("%p %d %ld\n", sv, eModifyMode, hrec );
131 if( !sv->table )
132 return ERROR_FUNCTION_FAILED;
134 return sv->table->ops->modify( sv->table, eModifyMode, hrec );
137 static UINT SELECT_delete( struct tagMSIVIEW *view )
139 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
141 TRACE("%p\n", sv );
143 if( sv->table )
144 sv->table->ops->delete( sv->table );
146 HeapFree( GetProcessHeap(), 0, sv );
148 return ERROR_SUCCESS;
152 MSIVIEWOPS select_ops =
154 SELECT_fetch_int,
155 SELECT_execute,
156 SELECT_close,
157 SELECT_get_dimensions,
158 SELECT_get_column_info,
159 SELECT_modify,
160 SELECT_delete
163 UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
165 MSISELECTVIEW *sv = NULL;
166 UINT count = 0, r;
168 TRACE("%p\n", sv );
170 r = table->ops->get_dimensions( table, NULL, &count );
171 if( r != ERROR_SUCCESS )
173 ERR("can't get table dimensions\n");
174 return r;
177 sv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
178 sizeof *sv + count*sizeof (UINT) );
179 if( !sv )
180 return ERROR_FUNCTION_FAILED;
182 /* fill the structure */
183 sv->view.ops = &select_ops;
184 sv->db = db;
185 sv->table = table;
186 sv->num_cols = 0;
187 sv->max_cols = count;
188 *view = (MSIVIEW*) sv;
190 return ERROR_SUCCESS;
193 UINT SELECT_AddColumn( MSIVIEW *view, LPWSTR name )
195 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
196 UINT r, n=0;
197 MSIVIEW *table;
199 TRACE("%p adding %s\n", sv, debugstr_w( name ) );
201 if( sv->view.ops != &select_ops )
202 return ERROR_FUNCTION_FAILED;
204 table = sv->table;
205 if( !table )
206 return ERROR_FUNCTION_FAILED;
207 if( !table->ops->get_dimensions )
208 return ERROR_FUNCTION_FAILED;
209 if( !table->ops->get_column_info )
210 return ERROR_FUNCTION_FAILED;
212 if( sv->num_cols >= sv->max_cols )
213 return ERROR_FUNCTION_FAILED;
215 r = VIEW_find_column( table, name, &n );
216 if( r != ERROR_SUCCESS )
217 return r;
219 sv->cols[sv->num_cols] = n;
220 TRACE("Translating column %s from %d -> %d\n",
221 debugstr_w( name ), sv->num_cols, n);
223 sv->num_cols++;
225 return ERROR_SUCCESS;